cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in HAL_Delay() all Cube SDK

ryabinin
Associate
Posted on May 13, 2014 at 07:23

Hi!

I'm sure there is a bug inHAL_Delay() when current time returned by HAL_GetTickis close to overflow (0xFFFFFFFF). Check out this code:

http://ideone.com/MAdwBN

Second version ofHAL_Delay() is my suggestion, it's pass the test.

//-----------------------------------------------------------------------------
#include <stdio.h>
#include <inttypes.h>
//-----------------------------------------------------------------------------
#define __IO
static
uint32_t Ticks;
/// Debug version of HAL_GetTick()
static
uint32_t HAL_GetTick()
{
return
Ticks++;
}
//-----------------------------------------------------------------------------
#if 1
/// Original HAL_Delay() from CubeMX
void
HAL_Delay(__IO uint32_t Delay)
{
uint32_t timingdelay;
timingdelay = HAL_GetTick() + Delay;
while
(HAL_GetTick() < timingdelay)
{
}
}
#else
/// Proposed HAL_Delay()
void
HAL_Delay(__IO uint32_t Delay)
{
uint32_t tt = HAL_GetTick();
while
((uint32_t)(HAL_GetTick() - tt) < Delay)
{
}
}
#endif
//-----------------------------------------------------------------------------
int
main(
int
argv, 
char
* argc[])
{
uint32_t temp;
Ticks = 0xFFFFFFE0;
temp = Ticks;
HAL_Delay(10);
printf
(
''%''
PRIu32 
''\n''
, (uint32_t)(Ticks - temp));
temp = Ticks;
HAL_Delay(10);
printf
(
''%''
PRIu32 
''\n''
, (uint32_t)(Ticks - temp));
temp = Ticks;
HAL_Delay(10);
printf
(
''%''
PRIu32 
''\n''
, (uint32_t)(Ticks - temp));
temp = Ticks;
HAL_Delay(10);
printf
(
''%''
PRIu32 
''\n''
, (uint32_t)(Ticks - temp));
temp = Ticks;
HAL_Delay(10);
printf
(
''%''
PRIu32 
''\n''
, (uint32_t)(Ticks - temp));
temp = Ticks;
HAL_Delay(10);
printf
(
''%''
PRIu32 
''\n''
, (uint32_t)(Ticks - temp));
temp = Ticks;
HAL_Delay(10);
printf
(
''%''
PRIu32 
''\n''
, (uint32_t)(Ticks - temp));
temp = Ticks;
HAL_Delay(10);
printf
(
''%''
PRIu32 
''\n''
, (uint32_t)(Ticks - temp));
temp = Ticks;
HAL_Delay(10);
printf
(
''%''
PRIu32 
''\n''
, (uint32_t)(Ticks - temp));
return
0;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

#st32cubemx #hal
2 REPLIES 2
Posted on May 13, 2014 at 07:31

[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=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2F[bug%20report]%20Bug%20in%20HAL%20%28SPL%29%20delay%20function&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=180

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ryabinin
Associate
Posted on May 13, 2014 at 07:40

OK! Thank You. I seek this issue but could not find.