Searching for this topic on google comes up with a number of threads, however none of them was conclusive or I was unable to understand what the final recommendation was!
Current situation :
I have a number of working sketches that use the onboard eeprom on 32U4 or 1284p MPUs to store settings for my sketches. Having decided to move to an ARM MPU I now need to "port" these sketches to work on an arduino zero clone type of board but I need to find a replacement for the functionality of the onboad EEPROM that does not exist on ARM MPUs.
As for hardware, I seem to have two options:
My custom PCB also has a place for an external I2C connected EEPROM
EEPROM emulation of the MPU's flash memory
Does the fact that the contains of this "EEPROM" must be maintained even when the program is re-flashed crosses out option 2 above?
If now option 1 is implemented, whats the easiest way to use my existing sketches and somehow "re-direct" access to external I2C eeprom when the sketch is loaded to an arduino zero board but also maintain compatibility with the AVR boards?
Attention : Before you can use SPIFFS you need to erase and format the flash memory chip using SPIFFSFormat.ino
ESP32 offers directly some embedded options mimicking EEPROM (in Flash too)
External I2C EEPROM is an option, it's an additional piece on your I2C bus and cost to your BOM. The plus side is that you can exchange the External I2C EEPROM chip if it wears out (if you write very often) whereas you'll have to change the full SAMD board if your flash memory wears out.
Thanks for your input!
It looks like with FlashStorage memory contains are lost when a new sketch is uploaded.
Also the SPIFFS option requires to erase all page memory data in order to change a single bit from zero to 1.
This makes both above options unsuitable for my application.
So i suppose i am left with an external I2C EEPROM option.
I wonder how I could easily redirect access to the external EEEPOM whenever the sketch is compiled for an ARM based arduino...
you could design a Class mimicking that API that would just basically be the EEPROM class on AVR through conditional compilation and implement an I2C EEPROM access layer on other architectures.
design another library similar to eeprom.h which will pose as EEPROM on AVR and mimic the internal EEPROM (using external EEPROM) on other platform. This way you write only one code and depending on your architecture the compilers figures out what needs to be done.
Yes there are libraries out there that you could use (this one does not offer update() or exactly the same API but that's the idea) and you can abstract the thing into your own class if you don't want to have the #ifdef stuff in your sketch
update() is just a read() followed by a comparison and a write() if the values are different, so easy to implement with read() and write() if you have your own class
and quite fun to look at how it's done through the abstraction layer with the EERef struct
EERef &update( uint8_t in ) { return in != *this ? *this = in : *this; }
Unlike the internal eeprom, the external eeproms have page boundaries which need to be taken into consideration. Porting the code to an external device depends on the size of what is stored.
Good spot @cattledog . Shame on Sparkfun for not fixing that in a way that any odd-sized data works ok with page boundaries, or at least clarifying the claim I quoted above. Sounds like @Watcher will not have any problems saving his (or her) byte and int data.