How to erase chip in STM32CubeIDE?
To erase the flash of an STM32 “chip” from STM32CubeIDE, you basically use the built-in STM32CubeProgrammer backend. Here’s the standard way, step by step.
1. Full-chip erase from STM32CubeIDE
A) Using the Run/Debug configuration (most common)
-
Connect your board
-
Open Run/Debug configurations
-
In the menu:
Run → Run Configurations…
or Run → Debug Configurations… (both dialogs are similar).
-
-
Select your project/MCU config
-
In the left tree, under STM32 Cortex-M C/C++ Application, click your project’s configuration.
-
-
Go to the “Startup” or “Debugger” tab (name slightly varies by version)
-
Look for a section like “Initialization” or “Load/Erase”.
-
-
Enable Flash erase
-
You will see options such as:
-
“Reset behaviour” (Connect under reset, etc.)
-
“Erase Flash” or “Flash Download” options
-
-
Choose “Erase entire chip” / “Full chip erase” or similar wording.
-
Apply/OK.
-
-
Run or Debug
-
When you press Run or Debug, CubeIDE will:
-
Connect to the target
-
Erase the whole flash
-
Then program your new firmware.
-
-
This is the easiest way if your goal is: erase everything, then flash my new code.
2. Erase only (without re-programming)
Sometimes you just want to wipe the chip, not load new firmware.
A) Via “External Tools” (STM32CubeProgrammer GUI)
-
Open STM32CubeProgrammer (installed together with CubeIDE or separately).
-
In CubeProgrammer:
-
Choose the correct connection (ST-LINK, J-Link, etc.).
-
Click Connect.
-
-
Under the “Erasing & Programming” section:
-
Click “Full chip erase”.
-
Confirm.
-
-
Disconnect – the MCU flash is now empty.
You can launch CubeProgrammer directly, or from CubeIDE via Help → STM32CubeProgrammer depending on version.
B) Via CubeIDE’s “External Tools” / console (advanced)
If you’re comfortable with command line, CubeIDE can call the STM32_Programmer_CLI:
-
Create a new External Tool configuration in CubeIDE that runs:
(adjust
port,sn, etc. as needed) -
Running that external tool from the toolbar will do a full erase only.
3. Quick sanity checks if erase doesn’t work
If you click erase and nothing happens (or you get errors):
-
Check connection
-
Correct ST-LINK firmware, cable, and target voltage (3.3 V / 5 V).
-
Sometimes you need “Connect under reset” if option bytes are misconfigured.
-
-
Check option bytes / readout protection
-
If RDP (Readout Protection) is at Level 1, many tools will:
-
Either refuse to read
-
Or require a full chip erase to unlock.
-
-
In CubeProgrammer, set RDP to Level 0 and apply changes (it will erase flash).
-
-
Check that you selected entire chip, not “selected sectors”
-
Some dialogs default to bank/sector erase; pick “Full chip erase” if you want everything gone.
-
4. Minimal “just tell me the button” summary
-
To erase when programming:
-
Run → Run Configurations… -
Select your STM32 project.
-
In Startup/Debugger tab, enable “Erase entire chip”.
-
Click Run.
-
-
To erase only:
-
Open STM32CubeProgrammer.
-
Connect to the MCU.
-
Click Full Chip Erase.
-

评论
发表评论