Skip to main content
Graduate II
October 1, 2025
Question

HAL API - --HAL_GetTick() always returned 0 in HAL_RCC_OscConfig() during SystemClock_Config?

  • October 1, 2025
  • 2 replies
  • 332 views

Hi all, 

STM32 start executes the following during startup in main.c:

  1. HAL_Init();

  2. SystemClock_Config();

  3. Initialize all configured peripherals (e.g., MX_GPIO_Init())

  4. 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.

 

 

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    October 1, 2025

    Hello @chai2145 

    I have tested the scenario you described, and it worked well from my side.

    chai2145Author
    Graduate II
    October 2, 2025

    Hi @Saket_Om , are you able to get the tickstart value? For my side is always 0 as shown in image below.

     

    chai2145_1-1759375572740.png

     

    ST Employee
    October 2, 2025

    Hello @chai2145,

    If you are using the NUCLEO-L053R8, please ensure the following hardware modifications:

    • Turn OFF solder bridges SB54 and SB55
    • Remove resistor R35
    • Turn ON solder bridges SB16 and SB50

    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

    chai2145Author
    Graduate II
    October 3, 2025

    Im using STM32L071RZH6 MCU