Skip to main content
Associate III
December 31, 2025
Question

Error: failed to erase memory on STM32F407

  • December 31, 2025
  • 2 replies
  • 990 views

 

Hi.

I'm having an issue with the error: failed to erase memory on STM32F407.
I'm using the board https://github.com/mcauser/BLACK_F407VE
and the debugger https://github.com/WeActStudio/WeActStudio.MiniDebugger.
and the original STM32F407VET6 chip.

Yesterday there was no issue, but today when I tried to continue my project, the problem appeared. I have set the SWD frequency from Auto to 100 kHz. At some point, it worked with BT0 = 0 and BT1 = 0 after several attempts of pressing the reset button before starting the debug. I have replaced the debugger twice and tried it on the same chip type on a different board, and it worked. However, it did not work on the chip on my project board. I tried it with the STM32Programmer, and the same problem occurred—it could not erase during download. Strangely, full chip erasure could be done, and the connection was normal with no issues.

STMicroelectronics ST-LINK GDB server. Version 7.12.0
Copyright (c) 2025, STMicroelectronics. All rights reserved.

Starting server with the following options:
 Persistent Mode : Disabled
 Logging Level : 1
 Listen Port Number : 61234
 Status Refresh Delay : 15s
 Verbose Mode : Disabled
 SWD Debug : Enabled
 InitWhile : Enabled

Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
 -------------------------------------------------------------------
 STM32CubeProgrammer v2.21.0 
 -------------------------------------------------------------------



Log output file: C:\Users\User\AppData\Local\Temp\STM32CubeProgrammer_a34096.log
ST-LINK SN : 066BFF494849877187143951
ST-LINK FW : V2J46M33
Board : --
Voltage : 3.24V
SWD freq : 4000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x413
Revision ID : Rev 2.0
Device name : STM32F405xx/F407xx/F415xx/F417xx
Flash size : 512 KBytes
Device type : MCU
Device CPU : Cortex-M4
BL Version : 0x31



Opening and parsing file: ST-LINK_GDB_server_a34096.srec


Memory Programming ...
 File : ST-LINK_GDB_server_a34096.srec
 Size : 52.37 KB 
 Address : 0x08000000


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 3]
Error: failed to erase memory


Error: failed to erase memory
Encountered Error when opening C:\ST\STM32CubeIDE_1.17.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.2.300.202508131133\tools\bin\STM32_Programmer_CLI.exe
Error in STM32CubeProgrammer
Shutting down...
Exit.

If I change the frequency to 100 kHz, this problem occurs.

STMicroelectronics ST-LINK GDB server. Version 7.12.0
Copyright (c) 2025, STMicroelectronics. All rights reserved.

Starting server with the following options:
 Persistent Mode : Disabled
 Logging Level : 1
 Listen Port Number : 61234
 Status Refresh Delay : 15s
 Verbose Mode : Disabled
 SWD Debug : Enabled
 InitWhile : Enabled

Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Failed to read all registers from target
Failed to read registers from target
Shutting down...
Exit.

I experienced the same error on the same chip a month ago, and I tried closing the application and reopening it, which worked. However, this time it was different; it didn't work. I tried upgrading from STM32CubeIDE 1.19.0 to 2.0.0, but the problem remained the same.

Is my chip damaged? 

Thank you :)

2 replies

mƎALLEm
Technical Moderator
December 31, 2025

Hello,

1- What you suspect you did yesterday on the board to make that happens? What kind of programs you uploaded to the MCU? Flash write/erase?

2- If you are able to do a full ship erase, are you  seeing 0xFFFFFF content in the Flash with the STM32CubeProgrammer at the sector 0? could you do a MCU program after? 

3- What kind of hardware tool you are using to connect to the board? STLINK? Could you please take a picture of your probe and share it with us?

STM32F407VET6.jpg

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
No_NameAuthor
Associate III
December 31, 2025

1). I don't feel like I'm doing that; I program it as usual on the main application.

2). If after a full erase at start offset 0x00000000, everything is FF.
Sometimes there is an error warning like “protection”; I don't read it anymore. I repeat it again and the full erase is successful, but the download still fails when erasing the download.

3) Yes, STLink is probably modified with the original ST chip.

If the problem is with the cable, I don't think it's a problem because when I tried it with the same debugger and cable with the same chip but on a different board, it worked.

 

 

No_Name_0-1767182723658.png

https://github.com/WeActStudio/WeActStudio.MiniDebugger

 

 

 

 

When I bought the project board, the chip was a Chinese clone, so I replaced it with the original one so that it could be used on STM32CubeIDE.

 

No_NameAuthor
Associate III
December 31, 2025

I have tried replacing the chip with a new one, but the same problem persists. My conclusion is that there is a problem with the board, but I don't know exactly where the problem lies.

MGogr.1
Senior
December 31, 2025

One solution could be changing the wires which are used to connect Debugger and Board.

Or you can try by re-soldering the Controller. Or try by changing the USB cable. Restarting the Cube IDE can also work.