2024-12-24 11:44 AM
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:
/* 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
2024-12-24 11:54 AM
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
2024-12-25 08:51 AM
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/
You can output the clock via one of the pins so as not to load the crystal circuit, map out via MCO
2024-12-25 11:02 AM
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.