cancel
Showing results for 
Search instead for 
Did you mean: 

How to erase external flash using STM32_Programmer_CLI.exe and flash loader?

FU
Associate

When I use STM32Programmer IDE I can erase external flash sector by sector.

When I use STM32_Programmer_CLI.exe I cannot erase the external flash.

Board info:

FU_0-1707307587040.png

I get following error from STM32_Programmer_CLI.exe:

STM32_Programmer_CLI.exe -c port=swd -e all -el C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\ExternalLoader\N25Q128A_STM32L476G-DISCO.stldr
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.15.0
      -------------------------------------------------------------------

ST-LINK SN  : 0671FF565588494867121539
ST-LINK FW  : V2J43M28
Board       : 32F746GDISCOVERY
Voltage     : 3.22V
SWD freq    : 4000 KHz
Connect mode: Normal
Reset mode  : Software reset
Device ID   : 0x449
Revision ID : Rev Z
Device name : STM32F74x/STM32F75x
Flash size  : 1 MBytes
Device type : MCU
Device CPU  : Cortex-M7
BL Version  : 0x90
Debug in Low Power mode enabled


Mass erase ...

Error: Mass erase operation failed.
Please verify flash protection

Since the erase fails I cannot program the device either.

STM32_Programmer_CLI.exe -c port=swd -el C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\ExternalLoader\N25Q128A_STM32L476G-DISCO.stldr -d C:\work\STM32F746DiscoveryCmakeTemplate\build\STM32F746DiscoveryCmakeTemplate.hex
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.15.0
      -------------------------------------------------------------------

ST-LINK SN  : 0671FF565588494867121539
ST-LINK FW  : V2J43M28
Board       : 32F746GDISCOVERY
Voltage     : 3.22V
SWD freq    : 4000 KHz
Connect mode: Normal
Reset mode  : Software reset
Device ID   : 0x449
Revision ID : Rev Z
Device name : STM32F74x/STM32F75x
Flash size  : 1 MBytes
Device type : MCU
Device CPU  : Cortex-M7
BL Version  : 0x90
Debug in Low Power mode enabled



Memory Programming ...
Opening and parsing file: STM32F746DiscoveryCmakeTemplate.hex
  File          : STM32F746DiscoveryCmakeTemplate.hex
  Size          : 590.28 KB
  Address       : 0x08000000


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


Error: failed to erase memory

I need STM32Programmer_CLI.exe to work since I want to be able to program the board with scripts. IDE does not work for me.

Here is a log from failing flash/erase step:

Erasing external memory sectors [0 3]
Init flashloader...
halt ap 0
w ap 0 reg 0 R0   0x00000001
w ap 0 reg 1 R1   0x00000000
w ap 0 reg 2 R2   0x00000000
w ap 0 reg 3 R3   0x00000000
w ap 0 reg 4 R4   0x00000000
w ap 0 reg 5 R5   0x00000000
w ap 0 reg 6 R6   0x00000000
w ap 0 reg 7 R7   0x00000000
w ap 0 reg 8 R8   0x00000000
w ap 0 reg 9 R9   0x00000000
w ap 0 reg 10 R10  0x00000000
w ap 0 reg 11 R11  0x00000000
w ap 0 reg 12 R12  0x00000000
w ap 0 reg 13 SP   0x00000000
w ap 0 reg 14 LR   0x20000001
w ap 0 reg 15 PC   0x200006D3
w ap 0 reg 16 xPSR 0x01000000
w ap 0 reg 17 MSP  0x20001D98
w ap 0 reg 18 PSP  0x00000000
run ap 0
halt ap 0
r ap 0 reg 0 R0   0x48001000
Init function fail
r ap 0 reg 16 xPSR 0x01000003
Loader sector erase...
Error: failed to erase memory

How can I do that please?

I looked forums and communities and I have to say the info is rather hopeless.

How come same flash loader works in the IDE but does not work in the CLI?

2 REPLIES 2
Maryem
ST Employee

Hello @FU and welcome to the ST Community,

Sorry for my late replay.

The file "N25Q128A_STM32L476G-DISCO.stldr" you are using is an external loader file for the STM32L476G-DISCO board. Could you please try with this file instead "N25Q128A_STM32F746G-DISCO.stldr"

 

Maryem.


In order 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.

Hi,

Thank you for your reply. I am sorry but I could not really understand your suggestion.


@Maryem wrote:

The file "N25Q128A_STM32L476G-DISCO.stldr" you are using is an external loader file for the STM32L476G-DISCO board.


Spot on. Sharp eye you have.


@Maryem wrote:

Could you please try with this file instead "N25Q128A_STM32F746G-DISCO.stldr"

Well... Are you sure N25Q128A_STM32F746G-DISCO.stldr will work? Shouldn't I use N25Q128A_STM32F746G-DISCO.stldr instead? Or maybe I shall try N25Q128A_STM32F746G-DISCO.stldr?

I am sorry, I could not resist the joke.

The problem I think is not in the external flash loader since when that is called by GUI programmer it seems to be doing the job.

I think the problem is in Programmer CLI which somehow does not call external flash loader correctly.

But since I do not have the source code of the CLI nor the GUI of the Programmer it is quite hard to me to narrow down the problem.