Electrical – Problems with programming STM32L mcu with stm32cubeIDE (failed to erase memory)

stm32stm32cubeide

I am trying to program a STM32L152R8 MCU with stm32cubeIDE v1.4. The MCU is not brand-new and is soldered on a board. I want to change its firmware.

While debugging with ST-Link Debugger I encounter the following error:

Memory Programming ...

Opening and parsing file: ST-LINK_GDB_server_a07132.srec

 File         : ST-LINK_GDB_server_a07132.srec

 Size         : 9052 Bytes

 Address      : 0x08000000
   
Erasing memory corresponding to segment 0:

Error: Flash loader cannot be loaded
    
Error: failed to erase memory

Encountered Error when opening E:\ST\STM32CubeIDE_1.3.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_1.3.0.202002181050\tools\bin\STM32_Programmer_CLI.exe

Error in STM32CubeProgrammer

Debugger connection lost.

Shutting down...

Notes:

  1. The reset pin is connected,
  2. I've tried to mass erase the chip using st-link utility,
  3. OpenOCD works but the live expression is disabled,
  4. Keil uVision and ST-Link Utility work fine without any problems

Any ideas?

Best Answer

If your chip is respoinsive and you can access it using ST-Link utility or uVision the problem is that flash memory protection is enabled and attemp to erase, write (ans maybe also read) flash by debugger fails as expected. Probably in utility you also do not see code (instruction bytes) but you see only memory full of zeros or full of ones.

In ST-Link utility select in menu Target > Option bytes and select Read out Protection to Level 0 and in the bottom pane select Unselect all to disable read and write protection of all sectors of flash. Then confirm by Apply button.

Read/Write protection in ST-Link utility