cancel
Showing results for 
Search instead for 
Did you mean: 

How to erase flash before programming with STM32CubeIDE [Solved]

SThre
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Markus GIRDLAND
ST Employee

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.

View solution in original post

11 REPLIES 11
Markus GIRDLAND
ST Employee

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
Associate II

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 II

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

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

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

0693W00000KcVJZQA3.png

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

marbel
Associate II

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

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

> dual banked system

This is interesting question. How the programmer knows which mode to use: one bank or dual bank, and which bank is the 'current'? Does it check the option bytes?