Skip to main content
LS813
Associate
October 28, 2025
Solved

Non-polling mode Flash Erasure

  • October 28, 2025
  • 1 reply
  • 167 views

Hello, everyone. Can anyone tell me how? I want to do something while STM erases a sector, Since it is STM32F401, it takes too long to erase a sector. What can be the best solution?

Best answer by TDK

Use the nonblocking HAL call HAL_FLASHEx_Erase_IT.

Be aware that you cannot erase a sector in the same bank as you're executing and still run code.

 

As @Ozone correctly notes below, the STM32F401 only has a single bank of flash. If you want to run code and erase a sector, that code will need to be in SRAM.

1 reply

TDK
TDKBest answer
Super User
October 28, 2025

Use the nonblocking HAL call HAL_FLASHEx_Erase_IT.

Be aware that you cannot erase a sector in the same bank as you're executing and still run code.

 

As @Ozone correctly notes below, the STM32F401 only has a single bank of flash. If you want to run code and erase a sector, that code will need to be in SRAM.

"If you feel a post has answered your question, please click ""Accept as Solution""."
LS813
LS813Author
Associate
October 28, 2025

Thank you very much. One thing is unclear.

At which point do I have to unlock and lock the flash in case of using HAL_FLASHEx_Erase_IT?

HAL_FLASH_Unlock before HAL_FLASHEx_Erase_IT, and HAL_FLASH_Lock in FLASH_IRQ_Handler function?

 

TDK
Super User
October 28, 2025

> HAL_FLASH_Unlock before HAL_FLASHEx_Erase_IT, and HAL_FLASH_Lock in FLASH_IRQ_Handler function?

Yes, that works.

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