2026-03-28 7:36 AM
hello,
I encountered a problem while developing for stm32u585. When the stm32 wakes up from standby mode, the HAL_RCC_OscConfig() function occasionally fails, "Wait till LSI is disabled" timeout in HAL_RCC_OscConfig() (this project uses IWDG)
The specific process is as follows:
1. start boot
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ICACHE_Init();
MX_UART4_Init();
boot to other address(app)
2. app init
HAL_Init();
SystemClock_Config();
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_LSI
|RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSEState = RCC_LSE_ON_RTC_ONLY;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.LSIDiv = RCC_LSI_DIV128;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 40;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
3. timeout in HAL_RCC_OscConfig()
/* Turn off LSI before changing RCC_BDCR_LSIPREDIV */
if ((bdcr_temp & RCC_BDCR_LSION) == RCC_BDCR_LSION)
{
__HAL_RCC_LSI_DISABLE();
tickstart = HAL_GetTick();
/* Wait till LSI is disabled */
while (READ_BIT(RCC->BDCR, RCC_BDCR_LSIRDY) != 0U)
{
if ((HAL_GetTick() - tickstart) > LSI_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
}
}How to solve this problem
Solved! Go to Solution.
2026-03-30 2:03 AM
Hello @lll
The LSI should only be initialized once at power-on reset (POR). Re-initializing or reconfiguring the LSI after each wake-up from standby can cause issues, as the oscillator may already be in use by IWDG, and the LSIRDY flag may not behave as expected.
2026-03-30 2:03 AM
Hello @lll
The LSI should only be initialized once at power-on reset (POR). Re-initializing or reconfiguring the LSI after each wake-up from standby can cause issues, as the oscillator may already be in use by IWDG, and the LSIRDY flag may not behave as expected.
2026-03-30 7:34 AM
Does this mean I have to modify HAL_RCC_OscConfig() ?
I have added this condition in HAL_RCC_OscConfig():
__HAL_PWR_GET_FLAG(PWR_FLAG_SBF)
Can it ensure that this startup is from standby wake-up
/*------------------------------ LSI Configuration -------------------------*/
if ((((pRCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI)
&& __HAL_PWR_GET_FLAG(PWR_FLAG_SBF))
2026-03-30 9:16 PM
or modify SystemClock_Config()
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SBF))
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48
|RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
else
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_LSI
|RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
2026-03-31 1:36 AM
Hello @lll
In your own SystemClock_Config(), do not request LSI/LSIDiv changes when IWDG might already be running.
That way, HAL_RCC_OscConfig() never enters the “disable LSI” branch, so no timeout.