Skip to main content
info239955_stm1_stmicro
Associate
January 23, 2017
Question

FLASH_WaitForLastOperation CubeMx error

  • January 23, 2017
  • 4 replies
  • 2263 views
Posted on January 23, 2017 at 10:02

The latest Version of CubeMx (4.19.0) the 'FLASH_WaitForLastOperation' function causes errors if the HAL_GetTick() function is near its rollover point. The cause seems to be 'uint32_t timeout = HAL_GetTick() + Timeout', which causes an error of the comparison 'HAL_GetTick() >= timeout'. With a 1ms resolution the error happens after 49 days, which could cause a serious problem in real systems. It would be nice, if this could be corrected.

best regards

Thomas

#cubemx
This topic has been closed for replies.

4 replies

Nesrine M_O
Associate
January 23, 2017
Posted on January 23, 2017 at 10:32

Hi

Schlenger.Thomas

,

Could you precise inwhich HAL library you have found the issue. So, we can verify it.

-Nesrine-

info239955_stm1_stmicro
Associate
January 23, 2017
Posted on January 23, 2017 at 11:30

Hi Nesrine,

it is in 'stm32l4xx_hal_flash.c' and starts in line 638. i.e. if HAL_GetTick() returns 0xffff8000 and Timeout is 50000 then timeout will be 17232, so the next compare with GetTick will initiate a timeout...

info239955_stm1_stmicro
Associate
January 23, 2017
Posted on January 23, 2017 at 11:54

I changed the repository in this way, which seems to work.

Thanks a lot for the very fine work on the very helpfull cubemx package.

HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
{
 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
 Even if the FLASH operation fails, the BUSY flag will be reset and an error�?�?�?�?
 flag will be set */
 
/*
 uint32_t timeout = HAL_GetTick() + Timeout;
 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) 
 { 
 if(Timeout != HAL_MAX_DELAY)
 {
 if(HAL_GetTick() >= timeout)
 {
 return HAL_TIMEOUT;
 }
 } 
 }
*/
 // change ths 2017
 uint32_t timeout = HAL_GetTick();
 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) 
 { 
 if(Timeout != HAL_MAX_DELAY)
 {
 if(HAL_GetTick()-timeout >= Timeout)
 {
 return HAL_TIMEOUT;
 }
 } 
 }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Nesrine M_O
Associate
January 23, 2017
Posted on January 23, 2017 at 13:46

Hi

Schlenger.Thomas

,

Thank you very much for your focus on

STM32 related solutions.

I will check the issue related to

FLASH_WaitForLastOperation function

with our development team & come back to you.Sorry for the inconvenience it may bring.

-Nesrine-

zhivko zivkovic
Associate II
October 31, 2017
Posted on October 31, 2017 at 17:12

I have similar problem. I am using STM32F303CBT6TR and I get HAL_ERROR at

https://github.com/zhivko/EclipseStm32/blob/master/Src/eeprom_flash.cpp#L156

I just copied source code from CubeMX example located at:

.\STM32Cube\Repository\STM32Cube_FW_F3_V1.7.0\Projects\STM32303C_EVAL\Examples\FLASH\FLASH_WriteProtection\Src\main.c

It seems I an getting error only in case of debugging code.

If I run it without debugger it seems it runs OK. What is the reason that I am getting HAL_ERROR

 ? Is it because of 

FLASH_WaitForLastOperation contains HAL_GetTick  that doesnt work OK while debugging ?