Skip to main content
Visitor II
October 8, 2021
Solved

HAL_Delay(X) function delays by X/2 (@STM32L0)

  • October 8, 2021
  • 4 replies
  • 2521 views

Hello everyone,

I write HAL_Delay(1000) or HAL_Delay(5000) on my code but it delays it by half. I checked SystickTimer it works fine. But HAL_Delay function gives me half delay time.

I created another project with same board, same Cubemx features , it works fine.

Where should i check at my code to find what's wrong with it (at debug mode)?

    This topic has been closed for replies.
    Best answer by Bahadir(Canceled)

    Why i did that i don't know but I had written twice HAL_IncTick(); function in the SysTick_Handler.

    My stupidity I'm sorry.

    It's solved.

    Thank you all.

    4 replies

    Graduate II
    October 8, 2021

    What are you using for a clock source, and on what board?

    For external clocks watch the define for HSE_VALUE, and use of HSE BYPASS for TCXO/XO type clock sources vs crystals

    Internal clocks can typically be exported via MCO/PA8 pin so you can scope them.

    Visitor II
    October 8, 2021

    I am using HSI16, at PLL x4 and /2 32MHz all of the peripherals. Also I have a HSE osc. But situation is same. HAL_Delay gives me delay by half.

    MCO is used as a input right now but i'll try tomorrow.

    Super User
    October 8, 2021

    HAL_Delay uses SysTick to increment the counter. Can't see how one would be correct and the other would be wrong. The logic is very simple.

    Most likely the clock is twice as fast as you think it is.

    Bahadir(Canceled)AuthorAnswer
    Visitor II
    October 9, 2021

    Why i did that i don't know but I had written twice HAL_IncTick(); function in the SysTick_Handler.

    My stupidity I'm sorry.

    It's solved.

    Thank you all.

    Graduate II
    October 13, 2021

    Thanks for the update on that. That would certainly do it..