Erase failed
The flash controller rejected an erase, before anything new was written. What was on the chip is still there.
FLASH_ERASE_FAILED
Symptoms
- Flashing stops in the erase phase, before any progress on programming.
- The chip still runs its previous firmware afterwards — the failure happened before anything was overwritten.
- Erase fails on some sectors and succeeds on others.
Likely causes
- Write protection (WRP) covers the sectors being erased. Protection blocks erase and programming alike.
- The core was running and its firmware touched the flash controller at the same time.
- Read-out protection is active at a level where the debugger may not erase flash directly.
- Dual-bank parts erasing against the wrong bank, or a part number whose flash geometry does not match the chip on the board.
How to fix it
-
Retry once
MCUHex halts the core before flashing. A failure caused by firmware racing the flash controller usually does not repeat on the second attempt.
-
Check write protection in the option bytes
Open STM32CubeProgrammer → Option Bytes and look at WRP. Sectors listed there cannot be erased until it is cleared.
-
Confirm the part number matches the chip
An erase aimed at sectors this chip does not have fails on the first one that is not there. Check the target selection against the marking on the package.
-
Try a mass erase from an external tool
A full chip erase clears stale protection state that a sector erase cannot. This wipes the chip — the firmware on it is gone.
pyocd erase --mass