Emulated EEPROM

C_D
Mon Aug 03, 2015 8:12 pm
Has anyone here worked with emulated eeprom on the stm32?

I am working on an application where I need to do a one off calibration and save a few bytes of data. They will be written very rarely (probably only once) and read often.

I saw in the RTC thread there were a few bytes of storage available in memory which is kept alive by the RTC battery, however I would prefer to have this calibration data kept even if the RTC battery is replaced.

It seems ST have provided an app note detailing their ’emulated eeprom’ strategy: AN2594
And there is an implementation of it for Maple available: maple-eeprom-emulation-library

I’m going to investigate this further today and see if I can get it running.


martinayotte
Mon Aug 03, 2015 8:24 pm
You can also use a small I2C EEPROM, they are cheap and you can get quite big ones such as AT24C512.

RogerClark
Mon Aug 03, 2015 9:23 pm
@C_D

As far as I was aware the EEPROM library was working.

https://github.com/rogerclarkmelbourne/ … ies/EEPROM

Page size on the Maple mini etc is 1k, and on the bigger (high density devices) its 2k.


C_D
Mon Aug 03, 2015 11:06 pm
:shock:

STM32duino never ceases to amaze me 8-)

Should have checked here first…


pablomuro
Thu Jul 13, 2017 2:15 am
[RogerClark – Mon Aug 03, 2015 9:23 pm] –
@C_D

As far as I was aware the EEPROM library was working.

https://github.com/rogerclarkmelbourne/ … ies/EEPROM

Page size on the Maple mini etc is 1k, and on the bigger (high density devices) its 2k.

G’day,
I noticed in the library “EEPROM” the lack of function “EEPROM.update” so I added in EEPROM.cpp the function:

Uint16 EEPROMClass :: update (uint16 Address, uint16 Data)
{
  If (EEPROM.read (Address)! = Data)
   {
     EEPROM.write (Address, Data);
   }
   Uint16 status = EE_VerifyPageFullWriteVariable (Address, Data);
Return status;
}

And also added in the file “EEPROM.h” in the section EEPROMClass class:

Uint16 update (uint16 address, uint16 data);

Is this correct? Will it work?

Thanks for the wonderfull work “Arduino for the stm32”


victor_pv
Thu Jul 13, 2017 2:30 am
[pablomuro – Thu Jul 13, 2017 2:15 am] –

G’day,
I noticed in the library “EEPROM” the lack of function “EEPROM.update” so I added in EEPROM.cpp the function:

Uint16 EEPROMClass :: update (uint16 Address, uint16 Data)
{
  If (EEPROM.read (Address)! = Data)
   {
     EEPROM.write (Address, Data);
   }
   Uint16 status = EE_VerifyPageFullWriteVariable (Address, Data);
Return status;
}

And also added in the file “EEPROM.h” in the section EEPROMClass class:

Uint16 update (uint16 address, uint16 data);

Is this correct? Will it work?

Thanks for the wonderfull work “Arduino for the stm32”

The write function already includes this verification:
EE_VerifyPageFullWriteVariable (Address, Data);

So you don’t need that part, and could just return the value returned by write(). Such as:
return EEPROM.write (Address, Data);


pablomuro
Thu Jul 13, 2017 3:13 am
Thanks, I will download the lastest version, sure will be better.

MakcYan
Sun Nov 12, 2017 1:48 pm

English variant:
Help me! The feeds given after disconnecting dc power are not saved. After connecting the power while reading eeprom data = 0. That did I do not so?
I use Arduino IDE with the kernel stm32duino
code:
#include <EEPROM.h>
uint16 temp_set1_niz; uint16 temp_set1_verx;
void setup() {
EEPROM.init();
EEPROM.PageBase0 = 0x801F000;
EEPROM.PageBase1 = 0x801F800;
EEPROM.PageSize = 0x400;
}
void loop(){
temp_set1_niz = EEPROM.read(0x30, &temp_set1_niz); temp_set1_verx = EEPROM.read(0x40, &temp_set1_verx);
... There are data changes and then saving data ...
EEPROM.write(0x30, temp_set1_niz); EEPROM.write(0x40, temp_set1_verx);
}


Pito
Sun Nov 12, 2017 2:21 pm
You mix
&temp_set1_niz
temp_set1_niz

MakcYan
Sun Nov 12, 2017 3:15 pm
[Pito – Sun Nov 12, 2017 2:21 pm] –
You mix
&temp_set1_niz
temp_set1_niz

kbahey
Sat Apr 21, 2018 12:06 am
I am running this example for EEPROM emulation on an STM32F103C8T6 Black Pill.

When I select 3, read/write test, I sometimes get an 81 error (out of storage), and sometimes AB (no valid page).
Trying 2k worked once (status returned 0), but returned AB or subsequent attempts.

Is EEPROM emulation supported on Black Pill and Blue Pill boards?
If not, then what is the way to do it? There is always AT24Cxx I2C EEPROMs, but that means extra complexity and less pins.


electrobling
Sat Apr 21, 2018 3:02 am
I’ve been using the EEPROM emulation with Blue Pill and Maple mini clone for several weeks now. I haven’t had any problems.

RogerClark
Sat Apr 21, 2018 3:55 am
Works fine for me as well.

Important.

Its just an emulation. If you treat it like a real EEPROM and issue thousands of erase / write cycles you will wear the flash memory out, very quickly as it only has 10,000 rewrite cycles – hence its not very usable for data logging.

However its fine for storing settings that don’t change very often


kbahey
Sat Apr 21, 2018 4:41 pm
This is not for data collection. It is for saving settings. When certain settings change from the default, they will be written. Only a handful per week at most.

One thing of note is that the application (a telescope controller), uses the Arduino API, which uses 8 bit arguments, and then strings 2 or 4 of these for 16 and 32 bit values.

The wrapper code is here: https://github.com/hjd1964/OnStep/blob/Alpha/NV.h

This works for Arduino Mega 2560, and Teensy 3.x.

Then it would store things like this:

nv.write(offset1, false);
nv.writeLong(offset3, 15956313L);


RogerClark
Sat Apr 21, 2018 8:56 pm
The basic functions to store the data in flash ( near the top of usable space) work ok

I find the EEPROM library very limited.

What we should probably do is make a new libarary with some better functions, as really the process is..

READ PAGE TO RAM
UPDATE RAM WITH NEW DATA IN SOME PLACES
CHECK IF DATA HAS ACTUALLY CHANGED
IF DATA HAS CHANGED….

UNLOCK PAGE IN FLASH
ERASE PAGE IN FLASH
WRITE RAM TO FLASH
LOCK FLASH


Leave a Reply

Your email address will not be published. Required fields are marked *