Nucleo series Clock Structure and Xtal oscillation "problem"

<June 9th, 2015>
I recognized that Nucleo board have three hardware version, MB1136 C-01, C-02 and C-03.
Followings are LSE difference those 3 versions.

VersionLSE XtalC31 & C32 valueComments
C-01No XtalnoneYou need to equipe Xtal(32.769kHz) and Capacitors
C-0232.768kHz Xtal10pF 10pF is not good for starting oscillation
C-0332.768kHz Xtal4.3pFCaps looks okay (I don't have this version.)

Please check DocID025833 Rev.7 (UM1724 User Manual) 5.7.3 OSC 32kHz clock supply.
If you have C-03 version board, I hope you don't have a LSE oscillation problem.

<May 17th, 2015>
Time-out setting value are changed officially as of today mbed-src (Rev.541) and mbed(Rev.99).

No.Board nametime-out[msec]
1)ST Nucleo L152RE 500 ->5000
2)ST Nucleo F401RE 500 ->5000
3)ST Nucleo F411RE 600 ->5000

Unfortunately this countermeasure is not enough for permanent solution!
During power-on sequence, sometimes the program cannot select LSE and shows "NO CLOCK" condition even LSE 32.768KHz Xtal is equipped correctly.

For LSE(External Xtal) issue, please also refer following link. (added on Feb. 20th, 2015)
/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/

1) Summary

Here I would like to explain two issues for ST Nucleo Board, (a) LSE Problem, (b)HSE without additional Xtal(X3).

====================
(a)LSE Problem
<Problem>
"Problem" is as of October 25th, 2014.
Below is the page which you can see the problem and answer.
http://developer.mbed.org/questions/4531/RTC-External-Crystal-Nucleo/
This problem is not only for ST Nucleo L152 Problem but also so at least F401 & F411 and I expected all of kinds of ST Nucleo boards.
Everybody want to use actual 32.768kHz clock of RTC but you can use if you have a lucky condition!
<Route Cause>
Hardware design(load capacitors) and software design(time-out) problem which Mr.Drescher pointed out in the above Q&A session.
if you have an interest for the detail route cause explanation, please see following session.
<Solution>
Two solutions are available.
1) Change X2 load capacitors -> Change hardware -> C31 and C32 value -> I don't know best value
2) Change software-> Please refer this page https://developer.mbed.org/users/kenjiArai/code/Nucleo_RTC_Clock_setting/

====================
(b)HSE without additional Xtal(X3)
New board doesn't have a X3 Xtal but it can run with best speed without X3!!
Why? Use X1 Xtal for main CPU Clock. Please refer follows.

2) HSE without additional Xtal(X3)

New board has a connection SB16 and SB50.
X1 is for ST/Link control CPU but they can deliver the clock to main CPU via MCO line because X1 = 8MHz Xtal and CPU needs 8MHz clock. Latest version of software can detect this connection and auto configure it.
Old board is only internal HSI clock but you can modify the board to connect SB16 & SB50 also.

3) LSE control problem

I have following Necleo boards.

No.Board nameVersionX2 & X3CLOCK (expected)actual
1)ST Nucleo L152REoldX2,X3 -> Not equipedLSI , HSILSI, HSI
2)ST Nucleo L152REnewX2->32.768kHz XtalLSE,HSELSI,HSE
3)ST Nucleo F401REoldX2,X3 -> Not equipedLSI,HSILSI,HSI
4)ST Nucleo F401REnewX2->32.768kHz XtalLSE,HSELSI,HSE
5)ST Nucleo F411REnewX2->32.768kHz XtalLSE,HSELSI,HSE

New board has external Xtal, 32.768kHz as X2 RTC, LSE clock source (Old version doesn't have it (You can check C-01(old) or C-02(new one as of today(Oct. 25th,2014) on your board bottom side)).
You can check your board new or old as follows(example Nucleo F401RE board).
/media/uploads/kenjiArai/nucleo12.jpg
/media/uploads/kenjiArai/nucleo23.jpg
As I mentioned above, the route cause is un-proper capacitors for X2.
Xtal and capacitor combination is very fundamental and very important hardware design issue.
You can see AN2867 application note provided by STM.
https://docs.google.com/viewer?url=http%3A%2F%2Fwww.st.com%2Fweb%2Fen%2Fresource%2Ftechnical%2Fdocument%2Fapplication_note%2FCD00221665.pdf%23search%3D%27AN2867%27
ST Nucleo board has 10pF capacitor as C31 and C32.
Capacitors value is not good for the board!! and software time-out setting is also bad!!(May 17th, 2015)
Board engineers didn't consider proper value for the capacitors and no collaboration with software engineers.
A software function which can select LSI(internal clock) and LSE(X2 Xtal) is also cannot work properly.
In the Q&A session which mentioned above, you can see function call "rtc_init()" but this routine cannot help for your problem.
In the AN2867 page 14, you can see following sentence.
4.5. Start-up time
Current mbed-src and mbed library has changed to 5s but still has a problem.(May 17th, 2015)
Start-up time of 32kHz crystal is within the 1s to 5s range.

followings are related program list.

file:rtc_api.c

void rtc_init(void){
    // ------deleted here--------
    // Enable LSE Oscillator
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
    RCC_OscInitStruct.PLL.PLLState   = RCC_PLL_NONE; /* Mandatory, otherwise the PLL is reconfigured! */
    RCC_OscInitStruct.LSEState       = RCC_LSE_ON; /* External 32.768 kHz clock on OSC_IN/OSC_OUT */
    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) {
        // Connect LSE to RTC
        __HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSE);
        __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
        rtc_freq = LSE_VALUE;
    } else {
        // Enable LSI clock
        // ------deleted here--------
        rtc_freq = LSI_VALUE;
    }
    // ------deleted here--------
}


file: stm32f4xx_hal_rcc.c

HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef  *RCC_OscInitStruct){
  // ------deleted here--------
  /*------------------------------ LSE Configuration -------------------------*/
  if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) {
    // ------deleted here--------
    __PWR_CLK_ENABLE();
    PWR->CR |= PWR_CR_DBP;
    /* Wait for Backup domain Write protection disable */
    tickstart = HAL_GetTick();
    while((PWR->CR & PWR_CR_DBP) == RESET)  {
      // ------deleted here--------
    }
    /* Reset LSEON and LSEBYP bits before configuring the LSE ----------------*/
    __HAL_RCC_LSE_CONFIG(RCC_LSE_OFF);
    tickstart = HAL_GetTick();
    while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET) {
      if((HAL_GetTick() - tickstart ) > LSE_TIMEOUT_VALUE) {
        return HAL_TIMEOUT;
      }
    }
    /* Set the new LSE configuration -----------------------------------------*/
    __HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
    /* Check the LSE State */
    if((RCC_OscInitStruct->LSEState) == RCC_LSE_ON)  {
      tickstart = HAL_GetTick();
      /* Wait till LSE is ready */
      while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)      {
        if((HAL_GetTick() - tickstart ) > LSE_TIMEOUT_VALUE)        {
          return HAL_TIMEOUT;
        }
      }
    } else {
      tickstart = HAL_GetTick();
      while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET)      {
        if((HAL_GetTick() - tickstart ) > LSE_TIMEOUT_VALUE)        {
          return HAL_TIMEOUT;
        }
      }
    }
  }
  // ------deleted here--------
  return HAL_OK;
}


files: stm32f3xx_hal_rcc.h, stm32f4xx_hal_rcc.h, stm32l0xx_hal_rcc.h, stm32l1xx_hal_rcc.h

updated to 5000
followings are old information
 (May 17th, 2015)

//  /TARGET_NUCLEO_F302R8/stm32f3xx_hal_rcc.h
/* LSE state change timeout */
#define LSE_TIMEOUT_VALUE        ((uint32_t)5000) /* 5 s    */
//  /TARGET_NUCLEO_F401RE/stm32f4xx_hal_rcc.h
/* LSE state change timeout */
#define LSE_TIMEOUT_VALUE        ((uint32_t)500)
//  /TARGET_NUCLEO_F411RE/stm32f4xx_hal_rcc.h
/* LSE state change timeout */
#define LSE_TIMEOUT_VALUE        ((uint32_t)600)
//  /TARGET_NUCLEO_L152RE/stm32l1xx_hal_rcc.h
#if !defined  (LSE_STARTUP_TIMEOUT)
  #define LSE_STARTUP_TIMEOUT   ((uint32_t)500)   /*!< Time out for LSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/* LSE state change timeout */
#define LSE_TIMEOUT_VALUE         LSE_STARTUP_TIMEOUT


Time-out for each CPU are here.
Here is old (please refer top of this page) (May 17th, 2015)

No.Board nametime-out[msec]
1)ST Nucleo L152RE500
2)ST Nucleo F401RE500
3)ST Nucleo F411RE600

Please check your board using this program.

Import programNucleo_RTC_Clock_setting

Check RTC LSE(External Xtal, 32.768kHz) mode

NOW you can use this program not only for F401 and F411 but also L152.
Here is my board results -> time-out sets original (0.5 or 0.6Sec).
/media/uploads/kenjiArai/401.png /media/uploads/kenjiArai/411.png

Most of the case, it reaches a time-out condition.
Some times, it can set LSE but not always.
Here is 2nd check.
Results -> Time-out sets 5sec
/media/uploads/kenjiArai/aftr401.png /media/uploads/kenjiArai/aftr411.png
Startup time for X3, LSE oscillator is diverse form 0.4 sec to over 1.2sec!!

4) Request to STMicroelectronics and the mbed team

Easy Solution Please modify definition as follows.

Thanks!  Followings are done. (May 17th, 2015)

//  /TARGET_NUCLEO_F401RE/stm32f4xx_hal_rcc.h
/* LSE state change timeout */
#define LSE_TIMEOUT_VALUE         ((uint32_t)5000) /* 5 s    */
//  /TARGET_NUCLEO_F411RE/stm32f4xx_hal_rcc.h
/* LSE state change timeout */
#define LSE_TIMEOUT_VALUE        ((uint32_t)5000) /* 5 s    */
//  /TARGET_NUCLEO_L152RE/stm32l1xx_hal_rcc.h
#if !defined  (LSE_STARTUP_TIMEOUT)
  #define LSE_STARTUP_TIMEOUT   ((uint32_t)5000) /* 5 s    */ 
#endif /* HSE_STARTUP_TIMEOUT */
/* LSE state change timeout */
#define LSE_TIMEOUT_VALUE         LSE_STARTUP_TIMEOUT

Better Solution
Change "Time-out period " as function argument.
Best Solution
AN2867 application note is not only for user but also STMicroelectronics engineers.
Route case is very clear that combination of hardware load capacitor value and time-out setting.
I believe they will change the best value both capacitors and time-out ASAP.
Added on May 17th, 2015
In the power-on sequence, I think LSE setting program is called when CPU VDD is still unstable period.
My recommendation is that LSE setting program is calling just before go to main().


10 comments on Nucleo series Clock Structure and Xtal oscillation "problem":

25 Oct 2014

I received a F401RE from Mouser yesterday. It apparently has the MB as originally populated - MB1136 C-01. It doesn't have any crystals on the main part of the board. When I run your program I get:

Select RTC clock source
Use standard function by STM
The time taken was 0.500378 sec. (Time-out setting:0.500000 sec.)
Use LSI
Use LSI again
Repeat again? [y/n]
 If yes, please pusch [RESET] buttom.
 If no, please hit any key.

So I guess everything is fine with my board?

25 Oct 2014

Hi Dan, you have a trouble for RTC part but you can use the board most of applications!.
If you want to use RTC, you may need to set LSE mode.
At the time you have a trouble because "standard function" run with "Time-out" condition.
500mSec is time-out + 378uSec is excuting time.
After that "USE LSI" means still internal clock.
Please check with following modification.

//#define STANDARD_FUNCTION // Use standard library prepared by STMicroelectronics
#define SPECIAL_FUNCTION  // Use special function. Time out is much longer than standard function
25 Oct 2014

Select RTC clock source
Use special function (extend time-out)
The time taken was 4.999112 sec. (Time-out setting:5.000000 sec.)
No clock
Use LSI again
Repeat again? [y/n]
 If yes, please pusch [RESET] buttom.
 If no, please hit any key.

So is the only ramification of this that I would have issues using a RTC? Could this be the reason I cannot even get a simple DebounceIn example to work? http://developer.mbed.org/forum/mbed/topic/5234/

25 Oct 2014

Hi Dan, I'm sorry that I didn't read your comments carefully.
Your F401RE board is C-01 which can NOT work with LSE mode because you don't have external Xtal current condition.
After 5 seconds, you have seen above result. This is right result!
Your question for "DebounceIn", I posted my answer in the link.
Please see it.
Again->You don't need any concern X2 Xtal issue for your most of application.

29 Nov 2014

Hi Kenji.

I have been having other RTC problems with the ST boards.

I have the crystals and back up cell fitted and are working, the time functions are correct, however if I reset or power cycle my board the time is reset to zero. Other platforms do not reset the RTC in these cases.

Any ideas, do you have the same problem?

04 Dec 2014

Paul
YES, you area right!!
This is next problem to use internal RTC!
This is only my guess, an initializing process for mbed system start up, they initialize RTC power or others.
If the initialize program doen't care RTC part, they can keep the data even we push reset switch.
I don't have any idea how to solve the problem at this moment.
My GPS data logger project has a stndby function and well wake up using RTC.
http://www.page.sannet.ne.jp/kenjia/STM32L_w_GPS_logger.html
At least, L152 can use this way but current mbed cannot do it.

10 Dec 2014

Thanks! very helpful! we have same problem as Paul Staron now...

12 Dec 2014

Hi, there! In my quest to *fix* my nucleo 401RE I found that a very convenient solution is to add a DS3231 module (breakout boards are cheaper than the crystals you would buy :D). I added a DS3231 with a 32kbit eeprom on board, thus solving the 2 most troublesome issues with the Nucleo, no accurate RTC and no eeprom.

I've enabled the LSE by connecting the 32kHz output from DS3231 to PC_14 of the nucleo, all is working well with time_t commands.

BUT... now I want to get accurate miliseconds ... and timer/ticker/wait all seem to use the HSI, any bright ideeas for my issue that doesn't involve soldering/desoldering components from the board? :D

I can also output a 8MHz from the DS or use the crystal from st-link boards, but both require de/soldering components.

Reading more in the user manual...

Quote:

• Oscillator from external PF0/PD0/PH0: from an external oscillator through pin 29 of the CN7 connector. The following configuration is needed: – SB55 ON – SB50 OFF – R35 and R37 removed

• HSE not used: PF0/PD0/PH1 and PF1/PD1/PH1 are used as GPIO instead of Clock The following configuration is needed: – SB54 and SB55 ON – SB50 (MCO) OFF – R35 and R37 removed

There are two possible default configurations of the HSE pins depending on the version of NUCLEO board hardware. The board version MB1136 C-01 or MB1136 C-02 is mentioned on sticker placed on bottom side of the PCB. The board marking MB1136 C-01 corresponds to a board, configured for HSE not used.

So if my boards MB1136 C-01 ships with the default configuration of SB54>ON will that impact the settings required to use an external osc on pin 29 of CN7 ? (where SB54 is not mentioned).

07 Feb 2015

Hi all,
I have made a RTC control function for F401RE & F411RE mbed.
If you set HW back up circuit, it can keep the time even power off condition.
Please evaluate it and give me feedback.
Thanks,
/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/

31 Mar 2015

On firmware 2.23.10:

Please hit any key to start measure
Select RTC clock source
Use special function (extend time-out)
Start-up time was 0.599676 sec. (Time-out setting:0.600000 sec.)
Use LSI

Repeat again? [y/n]
 If yes, please pusch [RESET] buttom.
   recomend to remove USB connecter then re-plug it.
 If no, please hit any key.
next

after reset button

Please hit any key to start measure
Select RTC clock source
Use special function (extend time-out)
Start-up time was 0.125218 sec. (Time-out setting:0.600000 sec.)
Use LSE

Repeat again? [y/n]
 If yes, please pusch [RESET] buttom.
   recomend to remove USB connecter then re-plug it.
 If no, please hit any key.
next

Close, but not close enough :D

Please log in to post comments.