cancel
Showing results for 
Search instead for 
Did you mean: 

Error: failed to erase memory on STM32F407

No_Name
Associate III

 

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 2
mƎALLEm
ST Employee

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.
MGogr.1
Associate III

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.