cancel
Showing results for 
Search instead for 
Did you mean: 

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

chai2145
Senior

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.

 

 

0 REPLIES 0