Skip to main content
ABouk
Associate II
August 15, 2019
Question

Error: failed to erase memory

  • August 15, 2019
  • 17 replies
  • 20799 views

Good afternoon, I was trying to debug a program on my new stm32f103C8T6 chip using the st-link v2 programmer, but i always get the same error : Error: failed to erase memory

I have tried the procedure with multiple boards so i guess that the problem is software, here is the full console output :

STMicroelectronics ST-LINK GDB server. Version 5.2.3

Copyright (c) 2019, 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

Waiting for debugger connection...

Debugger connected

   -------------------------------------------------------------------

            STM32CubeProgrammer v2.1.0          

   -------------------------------------------------------------------

Log output file:  /tmp/STM32CubeProgrammer_k3pQvR.log

ST-LINK SN : 33FF6D064E59343942520343

ST-LINK FW : V2J33S7

Voltage   : 3.20V

SWD freq  : 4000 KHz

Connect mode: Under Reset

Reset mode : Hardware reset

Device ID  : 0x410

Device name : STM32F101/F102/F103 Medium-density

Flash size : 63.999 MBytes

Device type : MCU

Device CPU : Cortex-M3

Memory Programming ...

Opening and parsing file: ST-LINK_GDB_server_JSWBJu.srec

 File     : ST-LINK_GDB_server_JSWBJu.srec

 Size     : 9716 Bytes

 Address    : 0x08000000 

Erasing memory corresponding to segment 0:

Erasing internal memory sectors [0 9]

Error: failed to erase memory

Error: failed to erase memory

Encountered Error when opening /Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.macos64_1.0.0.201904021149/tools/bin/STM32_Programmer_CLI

Error in STM32CubeProgrammer

Error! Failed to read target status 

Debugger connection lost.

Shutting down...

Thanks !

This topic has been closed for replies.

17 replies

ABouk
ABoukAuthor
Associate II
August 23, 2019

"Error! Failed to read target status"

I think that you must disable 'read out protection' in st-link utility, had the exact same problem

AHofm
Visitor II
August 23, 2019

ooooooh, thanks, can you little bit direct me where to set it.

Thx Ant

ABouk
ABoukAuthor
Associate II
August 23, 2019

try 'configuration bits', it's there, after having disabled it erase the flash memory and retry debugging using stm32cube if you want

jmf1
Associate III
February 5, 2020

I had something that looked quite similar using CubeMX IDE and a "Blue Pill":

  • device with MBytes instead of KBytes
  • Error during Erasing

I dowloaded Stm32Cube Programmer and discovered that RDP - Read Out Protection was set. So Flash Memory was read-protected. Unchecking this protection solved my issue (both with Stm32Cube Programmer and CubeMX IDE).

Go !

JMF

LKamm.2
Associate II
September 28, 2020

We are facing a similar problem on a L1-controller:

  1. We use the STM32L151CBT6-A on a custom PCB. The hardware is properly installed. All supply pins are connected with their respective signals. The programming connections are fine.
  2. The software STM32CubeProgrammer is capable of reading the Flash and Option Bytes, but programming or erasing the flash results in the error message: "Error: Flash loader cannot be loaded". The same error occurs using the internal Debugger / Programmer in STM32CubeIDE.
  3. In contrast, flash programming is possible using the STM32 ST-LINK Utility by loading the .bin file. The programm is executed correctly.

I have no idea, what the source of this error might be. Since flashing and executing the program are both working fine after using the older ST-LINK Utility, the issue should be located inside the Toolchain / STM32CubeProgrammer. The Read Out Protection is disabled (checked with ST-LINK Utility and STM32CubeProgrammer / CubeIDE can both read the flash and option bytes).

Please respond to this entry if you are facing the same problem or have any ideas to solve the issue.

LKamm.2
Associate II
October 2, 2020

If anybody else is experiencing the same issue as mentioned in my previous post:

For me it works not to use the STM32 Cube Programmer (GUI / CLI or integrated in Cube IDE).

I have switched to openocd (Windows x64 binaries), either by opening a Debugging server manually or integrating the server start in Cube IDE. This works perfectly fine. My platform:

Windows 10 64 bit

Cube MX / IDE / Programmer

STLINKV2/1

The problem occured with STM32L151CB-A and STM32L152CB-A.

MSmit.15
Visitor II
August 25, 2022

I was having similar problems after I updated STM32CubeIDE from 1.9.0 to 1.10.1 but I had also seen it after I installed v1.9.0 too and forgot how I fixed it.

Basically, the IDE tries to run STLink at 24000 kHz which my target did not seem to like. I reduced it to 21000 kHz and things worked properly.

To set it, in the IDE with the project loaded, right click on the project name in the Project Explorer window. Properties->Run/Debug Settings. Select the project name and then 'Edit'. Under the 'Debugger' tab you can find the interface frequency.

My suspicion is that when I updated the IDE to 1.10.1 it reset the STLink frequency back to the default clock speed.