2023-03-12 07:27 AM
Hi all,
How loop back handled in hal layer if uwTick reach to the max limit HAL_MAX_DELAY=0xffffffff
2023-03-12 07:42 AM
Don't delay for 50 day intervals.
If you need to do that, perhaps consider a different approach?
For shorter delays it should handle correctly unless they break the code again..
2023-03-12 07:57 AM
I'm taking about short delay,
Let uwTick current value is 0xFFFFFFF0 and then use HAL_Delay(1000)
As per HAL_Delay function
uint32_t tickstart = HAL_GetTick();
uint32_t wait = Delay;
/* Add a freq to guarantee minimum wait */
if (wait < HAL_MAX_DELAY)
{
wait += (uint32_t)(uwTickFreq);
}
while((HAL_GetTick() - tickstart) < wait)
after 256 tick HAL_GetTick returns 0 because of integer value roll over and this while become false and never get 1000 ms delay and All HAL library will failed because HAL_GetTick() function used in complete HAL library.
2023-03-12 08:07 AM
Why 256?
Just play with it, use a blinking led or smth. It works.
2023-03-12 08:39 AM
because current value is uwTick = 0xFFFFFFF0 and its increasing on every 1ms
after 255 ms the value will be 0xFFFFFFFF, on 256th ms its value will be 0.
2023-03-12 08:45 AM
If you do the uint32_t math properly the fact that the counter itself rolls over is irrelevant.
This is why you subtract out the starting point before doing the comparison.
If you add the delay to the starting point and compare that you will fail, but that's the amateur approach. Occasionally an intern from ST breaks it, and we all complain again about the stupidity.
They add a little to the wait as if you call the delay just before the count occurs it will take zero time to complete, and they want HAL_Delay(1) to be at least 1 ms.
2023-03-12 11:23 AM
Nick Gammon demonstrate how to handle millis (aka GetTick) to avoid overflow problems: