Emulated EEPROM

Post here first, or if you can't find a relevant section!
Post Reply
C_D
Posts: 62
Joined: Mon May 11, 2015 3:27 am
Location: New Zealand

Emulated EEPROM

Post by 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.

User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: Emulated EEPROM

Post by 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.

User avatar
RogerClark
Posts: 7475
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Emulated EEPROM

Post by 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
Posts: 62
Joined: Mon May 11, 2015 3:27 am
Location: New Zealand

Re: Emulated EEPROM

Post by C_D » Mon Aug 03, 2015 11:06 pm

:shock:

STM32duino never ceases to amaze me 8-)

Should have checked here first...

User avatar
pablomuro
Posts: 4
Joined: Tue May 09, 2017 2:12 am

Re: Emulated EEPROM

Post by pablomuro » Thu Jul 13, 2017 2:15 am

RogerClark wrote:
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
Posts: 1745
Joined: Mon Apr 27, 2015 12:12 pm

Re: Emulated EEPROM

Post by victor_pv » Thu Jul 13, 2017 2:30 am

pablomuro wrote:
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:

Code: Select all

return EEPROM.write (Address, Data);
But anyway since a PR on February 7th there is an update() function, so if you download the latest version of the repo, it should be included.
If you don't want to update the repo, then modify your function so EE_VerifyPageFullWriteVariable() is not called twice.

User avatar
pablomuro
Posts: 4
Joined: Tue May 09, 2017 2:12 am

Re: Emulated EEPROM

Post by pablomuro » Thu Jul 13, 2017 3:13 am

Thanks, I will download the lastest version, sure will be better.

MakcYan
Posts: 15
Joined: Tue Oct 24, 2017 6:27 pm

Re: Emulated EEPROM

Post by 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:

Code: Select all

#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); 
}
Russian variant:
Помогите мне!
Не сохраняются данные после отключения питания. После подключения питания при чтении eeprom данные = 0. Что я не так сделал?

User avatar
Pito
Posts: 1627
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Emulated EEPROM

Post by Pito » Sun Nov 12, 2017 2:21 pm

You mix

Code: Select all

&temp_set1_niz
temp_set1_niz
Is that ok?
Pukao Hats Cleaning Services Ltd.

MakcYan
Posts: 15
Joined: Tue Oct 24, 2017 6:27 pm

Re: Emulated EEPROM

Post by MakcYan » Sun Nov 12, 2017 3:15 pm

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

Code: Select all

&temp_set1_niz
temp_set1_niz
Is that ok?
& - from the example.
chip stm32f103c8t6

If you remove & it does not work

Code: Select all

C:\Users\MAKC-admin\Desktop\arduino-1.8.4\hardware\Arduino_STM32-master\STM32F1\libraries\EEPROM/EEPROM.h:69:9: error:   initializing argument 2 of 'uint16 EEPROMClass::read(uint16, uint16*)' [-fpermissive]

  uint16 read (uint16 address, uint16 *data);

         ^

exit status 1
invalid conversion from 'uint16 {aka short unsigned int}' to 'uint16* {aka short unsigned int*}' [-fpermissive]

Post Reply