cancel
Showing results for 
Search instead for 
Did you mean: 

Erase a group of sectors before programming

CTabo.1
Senior

Hello,
is it possible to add a command in the startup tab of the debug configuration, to erase a group of selected sectors, before programming?

For example I want to erase sectors [16..63], but not sectors [0..15].

I have only found the "monitor flash mass_erase" command, but it erase all flash.

Thank you,
Carlo

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Pavel A.,
cmd /c "${cubeide_cubeprogrammer_path}\STM32_Programmer_CLI.exe -e [16 63]" seems to be the correct way to invoke STM32_Programmer_CLI.exe.

Now the tool is launched, but it doesn't perform the erase operation because of the following error:

cmd /c "C:\ST\STM32CubeIDE_1.11.2\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.500.202209151145\tools\bin//STM32_Programmer_CLI.exe -e [16 63]"
make[1]: *** [makefile:93: pre-build] Error -1073741819

Even if I don't know what this return code indicates (I cannot find a return code list in UM2237), I guess that one of the problems is that I need also to specify the connection port.

So I have added the -c port=SWD option in the command line and now the erase operation seems to be performed correctly, as suggested by the output dumped on the console:

make -j7 all
cmd /c "C:\ST\STM32CubeIDE_1.11.2\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.500.202209151145\tools\bin\STM32_Programmer_CLI.exe -c port=SWD -e [16 63]"
-------------------------------------------------------------------
STM32CubeProgrammer v2.12.0
-------------------------------------------------------------------

ST-LINK SN : 001D0008544B500520343637
ST-LINK FW : V3J10M3B5S1
Board : STLINK-V3SET
Voltage : 3.28V
SWD freq : 24000 KHz
Connect mode: Normal
Reset mode : Software reset
Device ID : 0x460
Revision ID : Rev B
Device name : STM32G07x/STM32G08x
Flash size : 128 KBytes
Device type : MCU
Device CPU : Cortex-M0+
BL Version : 0xB2
Debug in Low Power mode enabled

Erase sector(s) ...
Existing specified sectors are erased successfully
Protected sectors are not erased

Is it right?

Regards,
Carlo

 

View solution in original post

8 REPLIES 8
FBL
ST Employee

Hello @CTabo.1 

I am not sure if there is initialization command for sector erase but you can do that using CubeProgrammer. Otherwise I suggest you similar posts : Solved: How to erase flash before programming with STM32Cu... - STMicroelectronics Community

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.


I'm out of offce with limited access to my emails.
Happy New Year!

Typically it just erases the span of the application.

Your application could also facilitate erasure of non-application spaces via diagnostic or monitor type console.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello @FBL,
if I try to add the following pre-build step, as indicated in the post:

CTabo1_1-1695626350779.png

STM32CubeProgrammer is launched correctly, but only dumps the cli usage syntax.

make -j7 all
C:\ST\STM32CubeIDE_1.11.2\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.500.202209151145\tools\bin/STM32_Programmer_CLI.exe
-------------------------------------------------------------------

STM32CubeProgrammer v2.12.0
-------------------------------------------------------------------
Usage :

STM32_Programmer_CLI.exe [command_1] [Arguments_1][[command_2] [Arguments_2]...]
Generic commands:
-?, -h, --help : Show this help

-c, --connect : Establish connection to the device
...

However, if I append the command to erase selected sectors of flash

CTabo1_0-1695626013478.png

I have the following error:

make -j7 all
C:\ST\STM32CubeIDE_1.11.2\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.500.202209151145\tools\bin\STM32_Programmer_CLI.exe -e [16 63]
c:/st/stm32cubeide_1.11.2/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.make.win32_2.0.100.202202231230/tools/bin/sh: C:STSTM32CubeIDE_1.11.2STM32CubeIDEpluginscom.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.500.202209151145toolsbinSTM32_Programmer_CLI.exe: not found
make[1]: *** [makefile:93: pre-build] Error 127
make: *** [makefile:61: all] Error 2
"make -j7 all" terminated with exit code 2. Build might be incomplete.

What am I doing wrong?

Thank you,
Carlo

CTabo.1
Senior

Hello,
any suggestion about it?

Why if I launch STM32_Programmer_CLI.exe as a pre-build step, without command line options, it is launched correctly (but do nothing), and if I launch it with the desired command line options, like -e[16 63], I have an error saying that STM32_Programmer_CLI.exe is not found?

Thank you,
Carlo

Pavel A.
Evangelist III

From the log above, the built-in "sh" utility (busybox) does not like backslashes. Try somehow to replace all \ to \\ or to / or use cmd in the command: cmd /c "${cubeide_programmer_path}\STM32_Programmer_CLI.exe -e [16 63] "

Maybe the new CubeIDE has a bug in handling of / and \ on Windows -  it used to do the right thing.

Hello @Pavel A.,
cmd /c "${cubeide_cubeprogrammer_path}\STM32_Programmer_CLI.exe -e [16 63]" seems to be the correct way to invoke STM32_Programmer_CLI.exe.

Now the tool is launched, but it doesn't perform the erase operation because of the following error:

cmd /c "C:\ST\STM32CubeIDE_1.11.2\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.500.202209151145\tools\bin//STM32_Programmer_CLI.exe -e [16 63]"
make[1]: *** [makefile:93: pre-build] Error -1073741819

Even if I don't know what this return code indicates (I cannot find a return code list in UM2237), I guess that one of the problems is that I need also to specify the connection port.

So I have added the -c port=SWD option in the command line and now the erase operation seems to be performed correctly, as suggested by the output dumped on the console:

make -j7 all
cmd /c "C:\ST\STM32CubeIDE_1.11.2\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.0.500.202209151145\tools\bin\STM32_Programmer_CLI.exe -c port=SWD -e [16 63]"
-------------------------------------------------------------------
STM32CubeProgrammer v2.12.0
-------------------------------------------------------------------

ST-LINK SN : 001D0008544B500520343637
ST-LINK FW : V3J10M3B5S1
Board : STLINK-V3SET
Voltage : 3.28V
SWD freq : 24000 KHz
Connect mode: Normal
Reset mode : Software reset
Device ID : 0x460
Revision ID : Rev B
Device name : STM32G07x/STM32G08x
Flash size : 128 KBytes
Device type : MCU
Device CPU : Cortex-M0+
BL Version : 0xB2
Debug in Low Power mode enabled

Erase sector(s) ...
Existing specified sectors are erased successfully
Protected sectors are not erased

Is it right?

Regards,
Carlo

 

Pavel A.
Evangelist III

Looks much better. do you see the sectors actually erased with other tool such as CubeProgrammer GUI?

Hello @Pavel A.,
yes I have verified with CubeProgrammer that the sectors are actually erased.

Thank you,
Carlo