cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid erasing the entire program in the Flash

MA4
Associate III

Hello,
I'm working on stm32h7 with the STM32CubeIDE IDE and I'd like to know how to make sure that when the debug starts it doesn't delete the whole program. Let me explain:

in my flash memory I have data in a specific location and specific size that I've written via the program and that I want to keep.
The problem is that when I launch the debug, it deletes the entire flash memory to write the new program.
Is it possible not to erase a specific memory location?
(I've tried with KEEP and NOLOAD in the linker script but it doesn't work).

 

thank you

3 REPLIES 3
Andrew Neil
Super User

@MA4 wrote:

The problem is that when I launch the debug, it deletes the entire flash memory


It should only erase the amount of Flash necessary for the size of the program:

https://community.st.com/t5/stm32cubeide-mcus/partial-or-full-chip-erase-before-programming/m-p/734869/highlight/true#M31829

You could try not including it in the linker script at all - which is what the EEPROM Emulation does.

 

PS:

The smallest unit of erasing is a single page; so you do have to ensure that your data is in a page of its own - separate from any part of the application.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
MA4
Associate III

I will test it. Thank you for your answer


@Andrew Neil wrote:

PS:

The smallest unit of erasing is a single page; so you do have to ensure that your data is in a page of its own - separate from any part of the application.


Exactly. The STM32H7 has 128k sectors. So the size of the reserved part of memory has to be a multiple of a whole sector and aligned with a whole sector. I often use the last sector of the flash for data. Or the first sector after a bootloader and before the application.

 


@Andrew Neil wrote:
You could try not including it in the linker script at all - which is what the EEPROM Emulation does.

I've had an application with external flash and I had to remove it from the elf file to prevent it from being flashed. Changing the linker file did not work in my case. It always wanted to write it. And when disabling writing it gave an error that certain data from the elf file was not written. So the simplest is not to include it in the elf file, but simply have that sector not defined in the linker file.

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.