cancel
Showing results for 
Search instead for 
Did you mean: 

Intermittent failures on boot during SystemClock_Config

jmcoreymv
Associate III

I'm using an STM32L4A6 on a custom-designed board.  I'm using STM32CubeIDE 1.16.0 and CubeMX to generate my project.  I'm running into an issue where intermittently (let's say every few days, but it seems random), my board will not bootup for a number of attempts (~5 but random, could be 1 could be 20).  When using the debugger, I can see that it got stuck in the Error_Handler() within the SystemClock_Config function which was generated by CubeMX.  Most of the time this works fine, but intermittently it gets caught in this error handler and I'm not sure how to narrow down further to the root cause of the problem.

More specifically:

  1. It's getting caught during the HAL_RCC_OscConfig() call which is returning a HAL_TIMEOUT
  2. Stepping through HAL_RCC_OscConfig, I see it's stuck in this loop until it times out:
    /* Check the LSE State */
    if(RCC_OscInitStruct->LSEState != RCC_LSE_OFF)
    {
      /* Get Start Tick*/
      tickstart = HAL_GetTick();

      /* Wait till LSE is ready */
      while(READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == 0U)
      {
        if((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
        {
          return HAL_TIMEOUT;
        }
      }
    }

Unfortunately, it's hard to troubleshoot because it's an ephemeral issue that will sometimes resolve itself after a few restarts.  Any suggestions on what could be causing this?

Thanks

 

3 REPLIES 3
TDK
Guru

You could increase RCC_LSE_TIMEOUT_VALUE, or instrument code to determine what the normal startup time is. Compare that against the expected times in the datasheet.

Could also look at your LSE circuit and ensure it meets recommendations, particularly with respect to acceptable drive strength. Note that drive strength can be changed with the LSEDRV field in RCC->BDCR.

Guidelines for oscillator design on STM8AF/AL/S and STM32 MCUs/MPUs - Application note

If you feel a post has answered your question, please click "Accept as Solution".

Drive level or load capacitors are marginal with your oscillator choice.

Or you'll need to determine a workable start-up time.

 

https://ecsxtal.com/news-resources/stm32-crystal-selection-tools/

https://www.st.com/resource/en/application_note/an2867-guidelines-for-oscillator-design-on-stm8afals-and-stm32-mcusmpus-stmicroelectronics.pdf

You can output the clock via one of the pins so as not to load the crystal circuit, map out via MCO

https://www.st.com/resource/en/reference_manual/rm0351-stm32l47xxx-stm32l48xxx-stm32l49xxx-and-stm32l4axxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf#page=208

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you! This seems like a promising route to explore.  Unfortunately since I can't seem to consistently reproduce the issue, it may be difficult for me to know if my fix actually fixed it.  I'm going to increase the drive strength from low to medium-low based on some of the documentation I read.