cancel
Showing results for 
Search instead for 
Did you mean: 

HAL delay doesn't match the value

VCapu
Associate III

I am using an STM32 MCU. When I use the HAL_Delay function with a parameter of 1000 for example, I see that the delay is shorter than it should be. I have checked that HAL_IncTick(), but it works correctly and it is placed inside the SysTick_Handler. What do I need to check in my code? Or it could be a problem with some configuration made with Cube ? Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
VCapu
Associate III

Solved. I recalculated the clock configuration with Cube and it seems to work well now. Thank you.

View solution in original post

9 REPLIES 9

What STM32?

What did period did you actually measure?

Using SysTick?

Frequency of external clock vs HSE_VALUE define?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
VCapu
Associate III

It's a STM32F405ZGT6. Now I have set in the Keil IDE the value Xtal(Mhz) at 25Mhz, and HSE_VALUE is the same. It seems that real delay is about a fifth of the parameter of the function. I am not measuring exactly the delay because the problem is very evident.

TDK
Guru

Are you using CubeMX generated clock initialization or your own code? Show it. Output MCO to verify your clock is what you think it is.

If you feel a post has answered your question, please click "Accept as Solution".

Toggle a GPIO in the SysTick_Handler

No valid reason for delays to be 1/5th of expected. Would suggest you walk all the code, and math

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
> No valid reason for delays to be 1/5th of expected.
Sure, but as they weren't actually measured, they could also be 1/3 or 8/25.
If you feel a post has answered your question, please click "Accept as Solution".
VCapu
Associate III

I use Cube code. What do you mean for output MCO?

If I increase a counter inside SysTick_Handler and when it has the value of 1000 I toggle an output, it all works and 1000 match to 1 second.

25/168 is very roughly 1/5...

MCO is direct output from RCC, as AF on PA8 or PC9, see pinout chapter in datasheet and read the RCC chapter in RM0090.

Cube is open soure, you can/should debug it as your own code. If you are sure systick works as expected and Cube's delay framework still doesn't, simply single-step from the systick ISR, or place the same pin toggle into Cube's function which is supposed to increment the tick variable.

Or just don't use Cube.

JW

VCapu
Associate III

Solved. I recalculated the clock configuration with Cube and it seems to work well now. Thank you.