cancel
Showing results for 
Search instead for 
Did you mean: 

Flash erase vs Program Running vs Design Decisions

mrx23
Associate III

Hello,

On STM32F401 is the HAL flash erase a blocking function? (one flash bank, no RAM functions) FLASH_Erase_Sector(idx, FLASH_VOLTAGE_RANGE_3);

 

It's not explicitly stated anywhere. Datasheet says reading the flash while erasing causes stalling, which is also confusing. I guess it means stalls until flash erase finishes then it continues accessing the flash.

 

If it's blocking then why doesn't it have return value of outcome, instead having to use another function like FLASH_WaitForLastOperation.

 

And what's the point of systick timeout in FLASH_WaitForLastOperation if we never enter it while erasing, also systick is not served while flash is busy.

 

And what's the point of having it as interrupt based, since program doesn't run anyway:

HAL_FLASHEx_Erase_IT

 

And why does the address space start with the smallest 16KB sectors, which are most likely will be used for user config? Why not put them at the end.

 

Not to mention smaller standard 2KB sectors would have been nicer for user configs. 2x16KB (with mirroring) is a lot of wasted space to store config.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

If your code is running from flash, then it is effectively a blocking function. If you're running code from RAM, then your code can continue while erasing happens in the background.

 

FLASH_Erase_Sector isn't meant to be called directly. The function intended to be called by the user is HAL_FLASHEx_Erase (or HAL_FLASHEx_Erase_IT).

 

Smaller flash sectors at the beginning allow for a bootloader, which is probably a more common use scenario than storing user data in flash.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

1 REPLY 1
TDK
Guru

If your code is running from flash, then it is effectively a blocking function. If you're running code from RAM, then your code can continue while erasing happens in the background.

 

FLASH_Erase_Sector isn't meant to be called directly. The function intended to be called by the user is HAL_FLASHEx_Erase (or HAL_FLASHEx_Erase_IT).

 

Smaller flash sectors at the beginning allow for a bootloader, which is probably a more common use scenario than storing user data in flash.

If you feel a post has answered your question, please click "Accept as Solution".