cancel
Showing results for 
Search instead for 
Did you mean: 

Error: failed to erase memory

ABouk
Associate II

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 !

20 REPLIES 20

You are probably right about not flakey connection since the funny looking value is always the same. Do you get the same value from all of your boards?

Look in the reference manual for your CPU. Find the "flash size register" and see its address. For example, for the STM32L4xx, it is at 0x1fff 75e0. I would expect it is in a different location for your F103. Run your programmer software of choice and have it read memory from that address. See what it shows. Again, for my L433 it shows 0xffff 0100. The 16 MSBs are ignored because the size register is only 16 bits wide. 0x0100 = 256K Bytes of FLASH.

ABouk
Associate II

@Bob S​ finally found the problem :

I went on Windows and attached the st link v2, started the program st-link and disabled 'read out protection' from configuration bits, once i did that, I could write freely any program on the flash using st-link command on mac OS and booting on System Memory (Boot<1:0> = 01).

Thanks all for your help !!0690X00000A9jl0QAB.png

Don't forget to mark this as "answered' :)

AHofm
Associate II

I got the same error with STM32L151

Waiting for debugger connection...

Debugger connected

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

                      STM32CubeProgrammer v2.1.0                 

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

Log output file:  C:\Users\Tonda\AppData\Local\Temp\STM32CubeProgrammer_a15552.log

ST-LINK SN : 0677FF564948897767025744

ST-LINK FW : V2J33M25

Voltage    : 3.24V

SWD freq   : 4000 KHz

Connect mode: Under Reset

Reset mode : Hardware reset

Device ID  : 0x429

Device name : STM32L100x6xxA/STM32L100x8xxA/STM32L100xBxxA/STM32L15xx6xxA/STM32L15xx8xxA/STM32L15xxBxxA

Flash size : 27.125 MBytes

Device type : MCU

Device CPU : Cortex-M3

Memory Programming ...

Opening and parsing file: ST-LINK_GDB_server_a15552.srec

 File         : ST-LINK_GDB_server_a15552.srec

 Size         : 88948 Bytes

 Address      : 0x08000000

Erasing memory corresponding to segment 0:

Error: Flash loader cannot be loaded

Error: failed to erase memory

Encountered Error when opening C:\ST\STM32CubeIDE_1.0.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_1.0.0.201904021149\tools\bin\STM32_Programmer_CLI.exe

Error in STM32CubeProgrammer

Error! Failed to read target status

Debugger connection lost.

==============================

Another interesting thing...

1) I cannot erase the chip with STM32CubeProgrammer

11:02:40 : STM32CubeProgrammer API v2.1.0

11:02:42 : ST-LINK SN : 0677FF564948897767025744

11:02:42 : ST-LINK FW : V2J33M25

11:02:42 : Voltage : 3.24V

11:02:42 : SWD freq : 4000 KHz

11:02:42 : Connect mode: Under Reset

11:02:42 : Reset mode : Software reset

11:02:42 : Device ID : 0x429

11:02:42 : UPLOADING OPTION BYTES DATA ...

11:02:42 : Bank : 0x00

11:02:42 : Address : 0x40023c1c

11:02:42 : Size : 136 Bytes

11:02:42 : Bank : 0x01

11:02:42 : Address : 0x1ff80000

11:02:42 : Size : 136 Bytes

11:02:42 : UPLOADING ...

11:02:42 : Size : 1024 Bytes

11:02:42 : Address : 0x8000000

11:02:42 : Read progress:

11:02:42 : Data read successfully

11:02:42 : Time elapsed during the read operation is: 00:00:00.007

11:02:49 : MASS ERASE ... 

11:02:49 : Error: Mass erase operation failed.Please verify flash protection

2) but, I can erase it by STM32ST-LinkUtility

???

ABouk
Associate II

"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
Associate II

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

Thx Ant

ABouk
Associate II

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

jmf1
Senior

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

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

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.