2014-05-12 10:23 PM
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: 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
2014-05-12 10:31 PM
[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=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
2014-05-12 10:40 PM
OK! Thank You. I seek this issue but could not find.