cancel
Showing results for 
Search instead for 
Did you mean: 

Keeping several parameters in a flash sector constant while changing one of them?

WBäck.1
Associate

I am not too familiar with embedded systems and just started learning about them. I have some parameters that lives in their own flash sector (16KB). They are stored as one long string ("PARAM1=X\r\nPARAM2=Y\r\n...." and so on). One of the parameters, let's say "PARAM4" can have values "1" or "0". I have code that is able to change the "1" to a "0" but since "0" has an integer value lower than "1" I cannot do the opposite since flashing only can change a 1-bit to a 0-bit.

So from my understanding is that I have to erase the entire sector to be able to change the "0" to a "1", the problem is that I want all of the other parameters to stay the same. Is the only real approach to solve this problem to copy the entire flash sector and re-flashing the flash sector after the erase, changing only the value of "PARAM4" while doing so?

4 REPLIES 4
MM..1
Chief III

Try read somethink about EEPROM emulation on flash, or simply your techniq waste life and space.

Most simple for store is use for example 32 bit flash space split to 16 16 where 16 is addr or id for param

for example FFFE for param 1 and second 16bit is value. Code work search from end sector first addr id and read value or write on ffff place .... when sector is full you read all params to ram erase and write back. Too you can use more as one sector...

Which STM32?

As MM..1 said above, usually a page (or whatever the erase-block is called) of FLASH is consecutively filled with parameter_marker-value pairs, and upon reset you seek for the newest value for each parameter. If the reserved FLASH block is reached In your case, you could perhaps add more and more PARAMx=X\r\n.

Note, that FLASH programming takes time and erasing takes even more time, and during that time you cannot execute code from the FLASH (unless you have some of the large-FLASH dual-bank STM32 models)

There are STM32 ('L0 and the freshly NRND'd 'L1) with a piece of FLASH which works more like EEPROM, i.e. it is erased in small pieces (4 bytes IIRC) automatically when reprogramming. It still takes time.

If this does not fit your purpose, contemplate using e.g. battery-backuped RAM (in some families e.g. 'F4/'F7), or a small cheap external I2C EEPROM.

JW

KnarfB
Principal III

There is an application note AN4894 "EEPROM emulation techniques and software for

STM32 microcontrollers" and associated source code that might help here.

hth

KnarfB

...or FRAM.