2021-05-24 04:42 AM
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.
Solved! Go to Solution.
2021-05-24 11:49 PM
Solved. I recalculated the clock configuration with Cube and it seems to work well now. Thank you.
2021-05-24 04:48 AM
What STM32?
What did period did you actually measure?
Using SysTick?
Frequency of external clock vs HSE_VALUE define?
2021-05-24 05:10 AM
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.
2021-05-24 06:10 AM
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.
2021-05-24 06:18 AM
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
2021-05-24 06:45 AM
2021-05-24 11:06 PM
I use Cube code. What do you mean for output MCO?
2021-05-24 11:08 PM
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.
2021-05-24 11:46 PM
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
2021-05-24 11:49 PM
Solved. I recalculated the clock configuration with Cube and it seems to work well now. Thank you.