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)

  1. Connect your board

    • Plug in your STM32 board via ST-LINK (or built-in debugger on Nucleo/Discovery).

    • Make sure drivers are installed and the board shows up in CubeIDE.

  2. Open Run/Debug configurations

    • In the menu:
      Run → Run Configurations…
      or Run → Debug Configurations… (both dialogs are similar).

  3. Select your project/MCU config

    • In the left tree, under STM32 Cortex-M C/C++ Application, click your project’s configuration.

  4. Go to the “Startup” or “Debugger” tab (name slightly varies by version)

    • Look for a section like “Initialization” or “Load/Erase”.

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

  6. 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)

  1. Open STM32CubeProgrammer (installed together with CubeIDE or separately).

  2. In CubeProgrammer:

    • Choose the correct connection (ST-LINK, J-Link, etc.).

    • Click Connect.

  3. Under the “Erasing & Programming” section:

    • Click “Full chip erase”.

    • Confirm.

  4. 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:

    STM32_Programmer_CLI -c port=SWD -e all

    (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):

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

  2. 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).

  3. 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:

    1. Run → Run Configurations…

    2. Select your STM32 project.

    3. In Startup/Debugger tab, enable “Erase entire chip”.

    4. Click Run.

  • To erase only:

    1. Open STM32CubeProgrammer.

    2. Connect to the MCU.

    3. Click Full Chip Erase.

评论

此博客中的热门博文

Detailed Explanation of STM32 HAL Library Clock System

Complete MQTT Implementation Example for STM32 (STM32F407 + Ethernet)

How to remove write protection of STM32 chip?