2025-09-30 11:40 PM
Hi all,
STM32 start executes the following during startup in main.c:
HAL_Init();
SystemClock_Config();
Initialize all configured peripherals (e.g., MX_GPIO_Init())
Enter the main while loop
However, I've observed a cold-start issue:
If the power supply is disconnected for 3–5 seconds or more, the system hangs and never reaches the main while loop after reboot.
If the supply is disconnected for a short interval or a manual reset is applied, the system boots normally.
While debugging, I suspected that the LSE/LSI/HSI oscillators might need more time to stabilize.
Looking into HAL_RCC_OscConfig(), it waits for the HSI to be ready by checking RCC_FLAG_HSIRDY with a timeout mechanism:
/* Get Start Tick */
tickstart = HAL_GetTick();
/* Wait till HSI is ready */
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == 0U)
{
if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
}
When I set a breakpoint here, I noticed:
tickstart is always 0
HAL_GetTick() always returns 0
It seems the HAL tick is not advancing at this point, causing the function to hang indefinitely.
Has anyone encountered a similar issue, or can explain why HAL_GetTick() would not increment during system clock configuration at cold start? Any suggestions on how to fix this would be greatly appreciated.
2025-10-01 3:46 AM
Hello @chai2145
I have tested the scenario you described, and it worked well from my side.
2025-10-01 8:26 PM
Hi @Saket_Om , are you able to get the tickstart value? For my side is always 0 as shown in image below.
2025-10-02 7:11 AM
Hello @chai2145,
If you are using the NUCLEO-L053R8, please ensure the following hardware modifications:
After making these changes, test your setup using the RCC_ClockConfig example to verify proper operation.
I hope my answer has helped you. When your question is answered, please select this topic as the solution that answered you, as it will help others find that answer faster.
Thanks for your contribution.
Dor_RH
2025-10-02 7:31 PM
Im using STM32L071RZH6 MCU