2024-01-06 03:02 PM - edited 2024-01-06 03:05 PM
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.
Solved! Go to Solution.
2024-01-06 03:14 PM - edited 2024-01-06 03:16 PM
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.
2024-01-06 03:14 PM - edited 2024-01-06 03:16 PM
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.