Intermittent failures on boot during SystemClock_Config
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:
- It's getting caught during the HAL_RCC_OscConfig() call which is returning a HAL_TIMEOUT
- 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
