cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 — Flash erase fails after STM32CubeIDE programming error

GHanj
Associate II

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

4 REPLIES 4
Andrew Neil
Super User

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.

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

TDK
Super User

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

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.