cancel
Showing results for 
Search instead for 
Did you mean: 

Non-polling mode Flash Erasure

LS813
Associate

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?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

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".

View solution in original post

4 REPLIES 4
TDK
Super User

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".

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?

 

> 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".
Ozone
Principal II

While I can't find any clue in the datasheet, I strongly suspect the F401, being at the cheaper end, is a single-bank design.
I find it very unfortunate the ST obscures this important criterium on most sites and documents.