RM0444 Rev 5 75/1390
RM0444 Embedded Flash memory (FLASH)
118
To erase a page (2 Kbytes), follow the procedure below:
1. Check that no Flash memory operation is ongoing by checking the BSY1 bit of the
FLASH status register (FLASH_SR).
2. Check and clear all error programming flags due to a previous programming. If not,
PGSERR is set.
3. Set the PER bit and select the page to erase (PNB) in the FLASH control register
(FLASH_CR).
4. Set the STRT bit of the FLASH control register (FLASH_CR).
5. Wait until the BSY1 bit of the FLASH status register (FLASH_SR) is cleared.
Note: The internal oscillator HSI16 (16 MHz) is enabled automatically when STRT bit is set, and
disabled automatically when STRT bit is cleared, except if the HSI16 is previously enabled
with HSION in RCC_CR register.
Flash memory bank or mass erase
When PCROP or WRP is enabled, the Flash memory mass erase is aborted, no erase
starts, and the WRPERR bit is set.
To perform a mass erase, follow the procedure below:
1. Check that no Flash memory operation is ongoing by checking the BSY1 bit of the
FLASH status register (FLASH_SR).
2. Check and clear all error programming flags due to a previous programming. If not,
PGSERR is set.
3. Set the MER1 (for Bank 1 or single-bank device) and/or MER2 (for Bank 2) bit of the
FLASH control register (FLASH_CR).
4. Set the STRT bit of the FLASH control register (FLASH_CR).
5. Wait until the BSY1 bit ofthe FLASH status register (FLASH_SR) is cleared.
Table 13. Page erase overview
SEC_PROT PCROP WRP PCROP_RDP Comment WRPERR CPU bus error
0
No No
x
Page is erased No
No
No Yes
Page erase aborted
(no page erase started)
YesYes No
Yes Yes
1 x Protected pages only No Yes
Table 14. Mass erase overview
SEC_PROT PCROP WRP PCROP_RDP Comment WRPERR CPU bus error
0
No No
x
Memory is erased No
No
No Yes
Erase aborted (no erase started) YesYes No
Yes Yes
1 x Erase aborted (no erase started) No Yes