cancel
Showing results for 
Search instead for 
Did you mean: 

what happen "if uwTick reach to max limit HAL_MAX_DELAY"

vchau.2
Associate III

Hi all,

How loop back handled in hal layer if uwTick reach to the max limit HAL_MAX_DELAY=0xffffffff

6 REPLIES 6

Don't​ delay for 50 day intervals.

If you need to do that, perhaps consider a different approach?​

F​or shorter delays it should handle correctly unless they break the code again..

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

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.

Why 256?

Just play with it, use a blinking led or smth. It works.

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.

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.

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

Nick Gammon demonstrate how to handle millis (aka GetTick) to avoid overflow problems:

https://www.gammon.com.au/millis