Skip to main content
SThre
Associate II
December 1, 2019
Solved

How to erase flash before programming with STM32CubeIDE [Solved]

  • December 1, 2019
  • 5 replies
  • 33757 views

Is there someway to do this with stm32cubeide?

For my specific use case I am storing configuration data on last page of flash (currently working on figuring out how to erase it so i can rewrite it in software), but I would also like to be able to configure it by reprogramming it. I can check that the page is empty and write settings to it, but I haven't found any way to erase it with stm32cubeide, I need to open the st link utility in order to erase the flash as far as I can tell.

This topic has been closed for replies.
Best answer by Markus GIRDLAND

There are a few ways of doing it. For example, you can either call cube programmer CLI and run a mass erase as a pre-build step ${cubeide_cubeprogrammer_path}/STM32_Programmer_CLI.exe

If you use that way it's important that in the debug configuration under "Main" tab that you don't have auto build disabled because then the pre-build step will not be called.

You can also go to the startup tab in the debug configuration and add "monitor flash mass_erase" as an Initialization command.

5 replies

Markus GIRDLAND
ST Employee
December 4, 2019

There are a few ways of doing it. For example, you can either call cube programmer CLI and run a mass erase as a pre-build step ${cubeide_cubeprogrammer_path}/STM32_Programmer_CLI.exe

If you use that way it's important that in the debug configuration under "Main" tab that you don't have auto build disabled because then the pre-build step will not be called.

You can also go to the startup tab in the debug configuration and add "monitor flash mass_erase" as an Initialization command.

SThre
SThreAuthor
Associate II
December 5, 2019

Thanks, somehow I had tried to write in the initialization commands section, but I hadn't thought to include the word "monitor" in my command, so it only gave errors.

Ddeve.1
Associate
November 6, 2021

I think this works for a ST link debugger connection ; unfortunately not for a Segger Jlink?!

When adding "monitor flash mass_erase" to the debug configuration -> Initialization startup :

0693W00000GWgKQQA1.jpg 

I get the following error :

0693W00000GWgKaQAL.jpg 

Any suggestions?

diederik

Markus GIRDLAND
ST Employee
November 8, 2021

Hello Diederik,

J-Link has its own commands which you can find more about in their user manual available here.

I believe the command for J-Link should be flash erase but you can double check that with the manual.

Diego B.
Associate II
March 14, 2022

Using Segger J-Link the command is: monitor flash erase

0693W00000KcVJZQA3.png

Markus GIRDLAND
ST Employee
March 15, 2022

Thank you for the clarification! I usually use my ST-Link so I wasn't sure :grinning_face_with_sweat:

marbel
Associate III
August 28, 2022

Hi

Is there a similar way to to a partial erase?

I am switching back and forth between two different software builds in a dual banked system and I only want to erase the currently executing bank.

BR

Martin

Piranha
Principal III
August 28, 2022

By default the debugger only erases the necessary sectors/pages.

marbel
Associate III
August 29, 2022

Yes it looks that way.