cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L073 store data after power off

waiyang93
Associate II
Posted on July 12, 2016 at 11:19

Hi,

I am working with an external flash and I wanted to store the lastest memory address after the power cut off and fetch back the stored memory address when power on. So, how should I do it ?  Is it done by write into the EEPROM of the chip or is there any ways to do it?

Is there any EEPROM example code provided by ST? Because I am using STM32CubeL0 to learn, but I did not find any example code related to EEPROM.
12 REPLIES 12
waiyang93
Associate II
Posted on July 14, 2016 at 04:22

Thanks for the reply Clive! So is kind of putting the chip in a sleep mode instead of totally cut off the power?

matic
Associate III
Posted on July 14, 2016 at 06:38

If storing to flash, you have to erase the whole page (not only one data) when the page is full. If you are storing half-words, then you can store data 1024 times (if page is 2kB) and then you need to erase it -> if you want to start storing again from the first element up.

But it is a bit tricky, if power goes off at that time when page is being erased. Then you lose your last valid data. So, you have to implement 2 pages, where you always have one valid data.

For this approach, refer to this document:

http://www.st.com/content/ccc/resource/technical/document/application_note/ec/dd/8e/a8/39/49/4f/e5/DM00036065.pdf/files/DM00036065.pdf/jcr:content/translations/en.DM00036065.pdf

It is for the F4 series, but the idea is the same.

waiyang93
Associate II
Posted on July 14, 2016 at 07:11

My flash is refered to a external NVM flash not the flash in the chip itself. Sorry I did not make that point clear. So the idea is :

1)store current data into NVM flash memory ( probably store a new data every 5 min)

2)before power off store the last written NVM address memory in to EEPROM

3)after restart use for-loop find back the last written NVM address memory from EEPROM 

As continue writting data all the memory address will be full.So, my problem now is when is the good time to erase the old data?