Should HAL_FLASH_Program and HAL_FLASHEx_Erase be placed in RAMFUNC?
Hi all,
I'm working on a project based on the STM32H7 and STM32G4 series, and I'm performing flash write and erase operations using the STM32 HAL functions:
HAL_FLASH_Program()
HAL_FLASHEx_Erase()
My question is:
Should these functions be placed into the .ramfunc section to avoid instruction fetch stalls or faults when writing/erasing flash on the same bank where code is executing?
Is there any direct feeback from ST about this topic?
On this topic I've the following observations:
I know that flash memory becomes unavailable during erase/programming, and the reference manual warns that executing from the same bank can cause CPU stalls or faults.
(from H7 RM: The embedded flash memory supports read-while-write operations provided the read and write operations target different banks)However, in my testing:
I'm calling these HAL functions from flash, without placing them in RAM.
I'm writing to or erasing a sector in the same bank where my code resides (e.g. bootloader on sector 1 succesfully erase - and then re-program - all the other sectors of bank 1 with the application without ever encountering any problem so far on company history).
I haven’t encountered any faults or crashes so far.
- Moreover ST HAL flash operations are not marked as RAMFUNC, so I would guess that they are not usually placed in that section
What do you think about that?
- Do you place these functions in RAMCODE inside your baselines?
- In case of positive answers, how did you updated the HAL library to do that?
- Have you already tried to write the same sector (not bank!) where your code reside (e.g code in the first 64KB of the sector, while programming the next 64KB)? Does this provoke faults in your experience?
