cancel
Showing results for 
Search instead for 
Did you mean: 

False HAL_Delay computation when uwTick overflows ?

florent
Associate II
Posted on April 11, 2015 at 09:18

Hi,

uwTick is an uint32_t incremented each Systick interrupt 1ms.

uwTick is used to execute HAL_Delay function.

So i calculated, uwTick will overflow each 49 days almost. I know its a really rare event but if a system is never powered-off it shall occur.

If HAL_Delay is called when uwTick is close to 2^32-1, the HAL_Delay function may return earlier than delay in ms asked in parameter because of the while condition (HAL_GetTick() - tickstart) < Delay) comparison and the uwTick that can overflows to 0.

Am i true ?

#stm32cube #stm32f4 #you-failed-the-interview
6 REPLIES 6
Posted on April 11, 2015 at 13:06

Am i true ?

No

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
florent
Associate II
Posted on April 11, 2015 at 17:33

Why ? If HAL_Delay is called when uwTick = 2^32-10

and parameter Delay = 20.

At first loop round:

HAL_GetTick() - tickstart) < Delay <=> 2^32-9 - 2^32-10 < 20

                                                                  1 < 20 : ok it continue while loop

But when uwTick overflows to 0, i.e. only 10ms after,

HAL_GetTick() - tickstart) < Delay <=> 0 - 2^32-10 < 20

                                                                  10 - 2^32 < 20: false, it break the while loop

So at only 10ms and not 20ms, the HAL_Delay functions give back hand to the program.

florent
Associate II
Posted on April 11, 2015 at 17:40

Ok below argumentation is based on SysTick_Handler defined as:

HAL_IncTick();

Posted on April 12, 2015 at 02:24

0x00000002 - 0xFFFFFFFE = 0x00000004

Or perhaps you would prefer the original implementation?

[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=180]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/[bug%20report]%20Bug%20in%20HAL%20%28SPL%29%20delay%20function&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=180

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 12, 2015 at 02:41

0xFFFFFFFF - 0xFFFFFFF6 = 0x00000009
0x00000000 - 0xFFFFFFF6 = 0x0000000A
0x00000001 - 0xFFFFFFF6 = 0x0000000B
..
0x0000000A - 0xFFFFFFF6 = 0x00000014

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
florent
Associate II
Posted on April 13, 2015 at 14:16

Ok, some forgotted binary boolean arithmetic for subtraction made me think in a wrong way...

Thanks.