Skip to main content
vchau.2
Associate III
March 12, 2023
Question

what happen "if uwTick reach to max limit HAL_MAX_DELAY"

  • March 12, 2023
  • 2 replies
  • 3463 views

Hi all,

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

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    March 12, 2023

    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    vchau.2
    vchau.2Author
    Associate III
    March 12, 2023

    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.

    Pavel A.
    March 12, 2023

    Why 256?

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

    Michal Dudka
    Lead
    March 12, 2023

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

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