2016-10-27 01:24 PM
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.2016-10-28 09:21 AM
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 .-Hannibal-2016-10-28 02:17 PM
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 bituint8_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: 20t1 = t1+20; // 20ms later t1 wraps aroundtd = t1 - t0; printf(''t0: %d t1:%d td: %d\r\n'', t0, t1, td); // output: t0: 240 t1:14 td: 402016-10-28 03:42 PM
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¤tviews=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 [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/False%20HAL_Delay%20computation%20when%20uwTick%20overflows&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21¤tviews=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=752016-10-28 11:43 PM