Skip to main content
Associate II
November 4, 2025
Solved

STM32F407 — Flash erase fails after STM32CubeIDE programming error

  • November 4, 2025
  • 4 replies
  • 462 views

Hi everyone,

I’m facing a serious issue with my STM32F407 MCU on a custom PCB.
I was flashing firmware from STM32CubeIDE using the onboard ST-Link from a Discovery board over SWD, and everything was working fine until one upload failed during the erase step.

Since that moment, I can’t erase or reprogram the chip anymore, even from STM32CubeProgrammer or ST-Link Utility.
le programming via STM32CubeIDE, I suddenly got this error in the ST-LINK GDB server console:
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 2]
Error: failed to erase memory
Encountered Error when opening ...\STM32_Programmer_CLI.exe
Error in STM32CubeProgrammer
Shutting down...
Exit.
After this, every subsequent attempt (from CubeIDE, CubeProgrammer, or ST-Link Utility) failed the same way.
I have tried : 

Connect under Reset mode, SWD frequencies (from 4 MHz → 950 kHz → 100 kHz), RDP = Level 0 (0xAA), no write protection in Option Bytes, Tried Full Chip Erase several times -> worked few times but can no longer erase
Sometimes says “Flash erased” but still cannot program 
My first concern is the MCU still OK and not permanently corrupted 
What could be the cause of this problem, all I did was just connecting the SWD wires like before

Best answer by GHanj

The issue is solved! It turned out to be a power problem, my previous power source was unstable, causing flash erase/program failures. After changing it everything worked perfectly. Thanks to everyone for the help and suggestions!

4 replies

Andrew Neil
Super User
November 4, 2025

Have you tried using the System (ROM) Bootloader ?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
GHanjAuthor
Associate II
November 4, 2025

Not yet
Do you think using the system bootloader could solve it ? 

Andrew Neil
Super User
November 4, 2025

If your problem is with the SWD interface, the Bootloader avoids that ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Super User
November 4, 2025

If SWD is connected correctly, it's likely that the chip has been damaged or there is some other issue with the design. Perhaps VDDA is not connected or some other power issue. Can you share the schematic?

If this is not a hardware issue, but is instead caused by the currently loaded firmware, holding BOOT0 during reset will allow you to recover.

"If you feel a post has answered your question, please click ""Accept as Solution""."
STOne-32
Technical Moderator
November 4, 2025

Dear @GHanj ,

Is that possible to share a picture of the device marking on top of your F4 discovery board ? It may happen the device or board is damaged - try to program in 8-bit and do a Mass Erase . If not helping - try to erase the upper sectors of the flash having 64k and 128kbytes if working that means the small sectors 0 , 1 etc reached maximum cumulative Erase cycle which is up to 10kcyles .

hope it is helping you.

STOne-32

GHanjAuthorBest answer
Associate II
November 5, 2025

The issue is solved! It turned out to be a power problem, my previous power source was unstable, causing flash erase/program failures. After changing it everything worked perfectly. Thanks to everyone for the help and suggestions!

STOne-32
Technical Moderator
November 5, 2025

Dear @GHanj ,

Thank you for feedback and Happy to see your board is working perfectly now .

Have a great day,

STOne-32