Question on Flash-to-Flash IAP on STM32F303CC
Hello everyone,
I'm working on an In-Application Programming (IAP) solution for an STM32F303CC. I've divided the flash memory into two application areas (let's call them App1 and App2), and I want to rewrite the program in App2 from code running in App1.
I have already implemented this, and it seems to be working correctly. However, I have some doubts and would appreciate it if anyone with knowledge on this topic could provide some clarification.
Here is my implementation detail:
The code that erases the App2 area is located in the App1 area.
It executes the standard HAL sequence: HAL_FLASH_Unlock(), HAL_FLASHEx_Erase(), and HAL_FLASH_Lock().
Global interrupts are not disabled during this process.
Several interrupts are active, but I have confirmed that all of their ISRs are also located within the App1 memory area.
My understanding was that the CPU should stall if an interrupt occurs during a flash erase operation, as it would try to fetch the ISR from a busy flash. However, this stall does not seem to be happening in my tests. A colleague suggested that it might be working without conflict because the program area and the target area are in clearly separated sectors.
My questions are:
Is this control method (erasing one flash sector while executing from another on a single-bank device) valid and safe according to the official specifications?
If it is valid, could you please provide evidence from a reference manual or application note that confirms this behavior?
If this method is problematic, would creating a critical section by disabling interrupts (__disable_irq() / __enable_irq()) be a sufficient and correct solution?
Any insights or guidance you could offer would be greatly appreciated. Thank you for your time and consideration.
