Skip to main content
vaidasmikalajunas
Associate II
October 27, 2016
Question

STM32CUBEMX and Systick problem

  • October 27, 2016
  • 4 replies
  • 1061 views
Posted on October 27, 2016 at 22:24

Hello, 

does anybody faced some problems with STM32CubeMX generated code when systick overflows? Normally ir overflows every 50 days (uint32) if set to 1ms... As all Cube drivers have the same style with delays (if (getSystick() < ...) ) some strange things can happen on overflow... I did not experienced any problems for now, but would like to hear what do you do to prevent such situations, maybe change Systick type to uint64 or something else?

Thank You.
    This topic has been closed for replies.

    4 replies

    Walid FTITI_O
    Visitor II
    October 28, 2016
    Posted on October 28, 2016 at 18:21

    Hi mikalajunas.vaidas, 

    It seems a time base issue.

    I recommend to take allok to '' 4.11.6 Setting HAL timebase source'' inside the STM32CubeMX User manual

    http://www.st.com/content/ccc/resource/technical/document/user_manual/10/c5/1a/43/3a/70/43/7d/DM00104712.pdf/files/DM00104712.pdf/jcr:content/translations/en.DM00104712.pdf

    .

    -Hannibal-

    thomfischer
    Senior
    October 28, 2016
    Posted on October 28, 2016 at 23:17

    the unsigned arithmetic guarantees that the time difference calculation is correct even if

    the tick value wraps around.

    e.g. if time value would be only 8 bit

    uint8_t t0,t1;

    uint8_t td ;

    t0 = 230;

    t1 = 250;

    td = t1 - t0;

    printf(''t0: %d t1:%d td: %d\r\n'', t0, t1, td);      // output: t0: 230 t1:250 td: 20

    t1 = t1+20;         // 20ms later t1 wraps around

    td = t1 - t0;        

    printf(''t0: %d t1:%d td: %d\r\n'', t0, t1, td);      // output: t0: 240 t1:14 td: 40

    Tesla DeLorean
    Guru
    October 28, 2016
    Posted on October 29, 2016 at 00:42

    Thought this was addressed a long while ago, I hope stuff hasn't crept back in.

    Show the actual failing code snippet, not an edited one.

    [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/%5bbug%20report%5d%20Bug%20in%20HAL%20%28SPL%29%20delay%20function&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=3127]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex%5Fmx%5Fstm32%2F%5Bbug%20report%5D%20Bug%20in%20HAL%20%28SPL%29%20delay%20function&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=3127

    https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Bug%20in%20HAL_Delay%28%29%20all%20Cube%20SDK&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=790

    [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/False%20HAL_Delay%20computation%20when%20uwTick%20overflows&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=75]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Java%2FFalse%20HAL_Delay%20computation%20when%20uwTick%20overflows&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21¤tviews=75

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    vaidasmikalajunas
    Associate II
    October 29, 2016
    Posted on October 29, 2016 at 08:43

    Thank You all for the help, now I see. that there is no problem with systick overflow, my bad...