EEPROM emulation how to increase size?

Working libraries, libraries being ported and related hardware
Post Reply
sp5iou
Posts: 5
Joined: Sat Oct 24, 2020 9:46 pm

EEPROM emulation how to increase size?

Post by sp5iou »

Hi.
I am usinh EEPROM libryary (eeprom.h) in my application on Bluepill board.
It works, however it is able to store 255 bytes only.
I need approx 1kB like it is in real eeprom in avr processors.
I was trying to play with eeprom configuratios, increasing pagesize , changing pages base addresses, but it works properlu only with npage size 0x400 which gives real 256 bytes only:
EEPROM.PageBase0 = 0x801F000;
EEPROM.PageBase1 = 0x801F800;
EEPROM.PageSize = 0x400;

I could modify Pagesazes addresses, but incresing Pagesize cause EEPROM.init and EEPROM.format to result with status 131 (errr) and EEPROM.read gets always 0xFFFF resolt regardless on EEPROM.write to the adress.
How could I increase capacity to real 1024 bytes working properly?
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: EEPROM emulation how to increase size?

Post by mrburnette »

If using STM's official core:
https://github.com/stm32duino/wiki/wiki ... -Emulation

If using libmaple (Roger's) then search the old forum or consult the Example:
https://www.google.com/search?&q=eeprom ... oforum.com

... and you can search this forum in the upper-right Search box.
sp5iou
Posts: 5
Joined: Sat Oct 24, 2020 9:46 pm

Re: EEPROM emulation how to increase size?

Post by sp5iou »

Thank You for advise.
I doidn't find answer for my qustins on links provided.
Before I opened this topics I searched forum for eeprom related posts and didn't found answer for my problem, also other web resources.
I spent for searching 2 hours.
There is a lot of interesting information about eeprom emulation, how does it work etc, but it is quite complex at least for me to built on that solution for problem I displayed.
So if You do not mind, please help me to find a way how to store more using eeprom.h library.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: EEPROM emulation how to increase size?

Post by fpiSTM »

Hi @sp5iou
For BP (STM32F103C8), all flash page size is 0x400. You can use the whole FLASH_PAGE_SIZE so 1kb.
I've tested and can have access to the whole page.
Note that I don't advice to use the EEPROM mainly if your write a lot. Flash has a limited number of write iterations.
Moreover each time you write 1 byte all the page is written. To avoid this you can use the buffered API. Example are provided here:
https://github.com/stm32duino/STM32Exam ... EEPROM.ino


So, I don't see how you conclude you can only write 255 bytes? If your bytes are stored in a uint32_t then it will consume 4 bytes.
Could you share your sketch ? Did you try the default examples (eeprom_put and eeprom_get) ?
sp5iou
Posts: 5
Joined: Sat Oct 24, 2020 9:46 pm

Re: EEPROM emulation how to increase size?

Post by sp5iou »

Hi.
Thank You for information.
Sketch it is quit long application initially written on AVR arduino.
It is automatic Telegraphy keyer with many options.
Configuration and texts for automatic transmission is stored in eeprom.
Since STM based board are supported by Arduino application could be compiled for STM.
Generally it works, but due to no eeprom in those STM processors, emulation is used.
Problem is that capacity for texts decreased dramatically.
I suppose that some capacity is wasted, because most of data including textx characters are 1 byte size, but emultion use 16bits.
It is difficult to rebuild application, since STM is just a marginal option.
I thing that just multiplying capacity of emulated eeprom is the simplest solution.
In flash is plenty of room, and values in non volatile memory do not change often.

For testing i use sketch below, but it can store and read no more than 247 values.

Code: Select all

//Test eeprom
#include <EEPROM.h>
uint16 AddressWrite = 0x10;
uint16 Status;
int ledPin =  13;    // LED connected to digital pin 13

void setup() {
  // put your setup code here, to run once:
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);
        Serial.begin(115200);
        delay(5000);
  Serial.print("Begin eeprom initialisation");
//      EEPROM.PageBase0 = 0x801F000;
//      EEPROM.PageBase1 = 0x801F800;
//     EEPROM.PageSize  = 0x400;
      EEPROM.PageBase0 = 0x801D000;
      EEPROM.PageBase1 = 0x801E800;
      EEPROM.PageSize  = 0x400;
      Status = EEPROM.init();
      Serial.print("EEPROM.init status ");
      Serial.println(Status);
      Status = EEPROM.format();
      Serial.print("EEPROM.format status ");
      Serial.println(Status);

}

void loop() {
  delay(5000);
  Serial.print("Begin eeprom test");
  delay(5000);
  // put your main code here, to run repeatedly:
  uint16 Data;
  uint8 DataS;
for(uint16 i=AddressWrite; i<AddressWrite+1023;i++)
{
  DataS = i;
  EEPROM.write(i,DataS);
  Serial.print(DataS);
  Serial.print(" ");
  EEPROM.read(i,&Data);
  Serial.println(Data);
  }
  delay(60000);
}
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: EEPROM emulation how to increase size?

Post by fpiSTM »

It seems you use the Libmaple core based on your code example.
So I move this topic to the correct core section.
FerroFerido
Posts: 12
Joined: Tue Nov 17, 2020 11:10 pm

Re: EEPROM emulation how to increase size?

Post by FerroFerido »

Man, we have the same problem.
Did you manage to solve the problem? If yes, plis, tell me how, please.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: EEPROM emulation how to increase size?

Post by mrburnette »

sp5iou wrote: Sun Nov 01, 2020 10:52 pm ...
Problem is that capacity for texts decreased dramatically.
I suppose that some capacity is wasted, because most of data including textx characters are 1 byte size, but emultion use 16bits.
IMO best solution: Have you considered using a real external EEPROM? Cheap and flexible: SPI or I2C chips.

Maybe a better solution would be to consider SPIFFS for constant text. I am familiar with SPIFFS as implemented for the Espressif ESP8266: example here.

There seems to be some activity around STM32F103 and SPIFFS.

I have not personally implemented SPIFFS & EEPROM libraries together on ESP microcontrollers. But this EEPROM library sounds promising: https://github.com/jwrw/ESP_EEPROM

One could also split the storage: move configuration to atmega (3.3V @ 12MHz) for EEPROM and use the STM32 flash for const data. Just request the config from the atmega at power reset and read/update over a serial/I2C/SPI interface. You can move all the config as a single structure:
Struct_Send & Struct_Receive: https://github.com/LowPowerLab/RFM69/tr ... r/Examples
The supported micro-controllers on the various Arduino and Genuino boards have different amounts of EEPROM:
1024 bytes on the ATmega328P,
512 bytes on the ATmega168 and ATmega8,
4 KB (4096 bytes) on the ATmega1280 and ATmega2560.
Ray
sp5iou
Posts: 5
Joined: Sat Oct 24, 2020 9:46 pm

Re: EEPROM emulation how to increase size?

Post by sp5iou »

Any hint how to increase size of eeprom emulation?
Since project run as it should on arduino mega 2560, To have it running on Mapple Mini or bluepill I need to increase size to 4kB.
I am not able to use external eeprom - no room on PCB and much space in STM flash.
Post Reply

Return to “Libraries & Hardware”