Skip to main content
CTabo.1
Senior
September 22, 2023
Solved

Erase a group of sectors before programming

  • September 22, 2023
  • 8 replies
  • 3414 views

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

    This topic has been closed for replies.
    Best answer by CTabo.1

    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

     

    8 replies

    ST Technical Moderator
    September 22, 2023

    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 "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
    CTabo.1
    CTabo.1Author
    Senior
    September 25, 2023

    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

    Tesla DeLorean
    Guru
    September 22, 2023

    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    CTabo.1
    CTabo.1Author
    Senior
    October 6, 2023

    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.
    October 6, 2023

    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.

    CTabo.1
    CTabo.1AuthorBest answer
    Senior
    October 9, 2023

    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.
    October 9, 2023

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

    CTabo.1
    CTabo.1Author
    Senior
    October 11, 2023

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

    Thank you,
    Carlo