29.4.3.3 Erase Commands
Erase commands are allowed only on unlocked regions of the Flash main area. Several commands can be used to erase the Flash:
- Erase Pages (EPA): 8, 16, 32 or 64 pages are erased in the Flash sector selected. The first page to be erased is specified in the EEFC_FCR.FARG[15:3] field. The first page number must be a multiple of 8, 16, 32 or 64, depending on the number of pages to erase at the same time.
- Erase Sector (ES): a full 128-Kbyte memory sector is erased. EEFC_FCR.FARG must be set with a page number that is in the sector to be erased.
If the processor is fetching code from the Flash memory while the EPA or ES command is being executed, the processor accesses are stalled until the EPA command is completed. To avoid stalling the processor, the code can be run out of the internal SRAM.
If the Flash has to be read while an EPA or ES command is performed, the Erase command can be suspended by writing the Suspend (SUSP) command in EEFC_FCR.
Consequently, EEFC_FSR.FDRY rises together with EEFC_FSR.FLSUSP, indicating the Erase command has been suspended.
Only Read accesses from the Flash are allowed during a suspended Erase command.
The suspended Erase command can be later resumed by writing a Resume command (RES) in EEFC_FCR.
If the SUSP command is issued late in the programming, the Erase command may simply finish but not be suspended as indicated by EEFC_FSR.FDRY rising but EEFC_FSR.FLSUSP staying low.
If the same Erase command is suspended then resumed multiple times, it is recommended that after RES command, the next SUSP command should be given not earlier than 1 ms.
The erase sequence is the following:
- Erase starts as soon as one of the Erase commands and the FARG field are written in EEFC_FCR.
For the EPA command, the two lowest bits of the FARG field define the number of pages to be erased (FARG[1:0]):
Table 29-3. EEFC_FCR.FARG Field for EPA Command FARG[2:0] Number of pages to be erased with EPA command 1 8 pages 2 16 pages 3 32 pages 4 64 pages - When erasing is completed, the bit EEFC_FSR.FRDY rises. If an interrupt was enabled by setting the bit EEFC_FMR.FRDY, the interrupt line of the interrupt controller is activated.
Three errors can be detected in EEFC_FSR after an erasing sequence:
- Command error: a wrong keyword was written in EEFC_FCR.
- Lock error: at least one page to be erased belongs to a locked region. The Erase command has been refused, no page has been erased. A command must be run previously to unlock the corresponding region.
- Flash error: at the end of the erase period, the EraseVerify test of the Flash memory fails.
