Skip to main content
Visitor II
December 24, 2024
Question

Intermittent failures on boot during SystemClock_Config

  • December 24, 2024
  • 2 replies
  • 679 views

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

 

    This topic has been closed for replies.

    2 replies

    Super User
    December 24, 2024

    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

    Graduate II
    December 25, 2024
    jmcoreymvAuthor
    Visitor II
    December 25, 2024

    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.