2020-07-01 08:29 AM
Hello,
I have never done this so please be patient haha - I need to store around 10 float numbers into the flash memory - I will do this in the last memory sector. The problem that I have is that I can write & read to the flash but if i want to overwrite a memory location I have to delete the whole sector which causes the rest of the data to be lost. To counter this I could copy all the existing data in the sector to another sector then write the memory location i initially wanted to then copy the rest of the values from the other sector - however this is soooooo inneficient and I have read that the mem cycle is only 10k - does anyone have any suggestions on this? it would be much appreciated. Is it really impossible to overwrite data at a specific memory locaiton without clearing the whole sector?
2020-07-01 02:38 PM
Yes, flash works that way. If it were possible to overwrite arbitrary bytes, then it would be called eeprom instead, and it would cost five times more.
A flash sector can hold a lot more than 10 float values, so if they must be updated, just write 10 more values into the same sector until it is filled to capacity. When the program starts, scan the whole flash area for the last valid number. An unprogrammed word in flash contains 0xFFFFFFFF which is interpreted as NAN so you know when to stop.
> the mem cycle is only 10k - does anyone have any suggestions on this?
If you have to update the values so often that it would still exhaust the 10k erase cycles, then either connect an external FRAM memory or some battery or supercap to power the internal backup ram if there is one.
2020-07-01 02:41 PM
>>A flash sector can hold a lot more than 10 float values, so if they must be updated, just write 10 more values into the same sector until it is filled to capacity. When the program starts, scan the whole flash area for the last valid number. An unprogrammed word in flash contains 0xFFFFFFFF which is interpreted as NAN so you know when to stop.
Yes, journal the structure across the sector, finding the last one when you need to read, write to the next available slot when you want to write.
https://community.st.com/s/question/0D53W00000BKkRnSAL/virtual-eeprom-for-f0
2020-07-02 01:37 AM
I assume I need to use a second sector to copy the last known values when the first sector gets filled then move the values back at the beginning of the first sector when it gets cleared, after the values were moved at the beginning of the first sector - I delete the second sector. This is gonna be a bit of work, trying to decide if I even need to save on memory cycles as I only use this as a settings storage area - don't think people will change the settings more than 10000 times throughout its lifetime
2020-07-02 01:40 AM
Sure, if they are just manual configuration settings then there is no reason to bother with the flash wearing out.