Expand/Emulate Larger EEPROM on Teensy 4.1?

Thundercat

Well-known member
Hey all,

I've got a large program with a bunch of user presets that is eating up most of my 4284 bytes of EEPROM on a Teensy 4.1.

I've been researching up a storm but I admit this topic is a little overwhelming.

I understand that I can add an additional flash chip to the Teensy 4.1 (I've actually added PSRAM and Flash to a unit I have via soldering to the underpads).

However, what I'm not clear on is, can I use any of that additional flash memory to store configuration data as I would with EEPROM?

I know I can use the LittleFuse library but it doesn't seem suited to just holding random bytes of data here and there like you can with the onboard emulated EEPROM, although I suppose I could make some kind of text config file and write values and read them back using a CSV format. But this seems very awkward and amateurish - and very much not how this should be done.

So what would you do if you wanted to store, say, double or more the amount of data into the Teensy 4.1 EEPROM?

I also read some threads where it's possible to increase the existing onboard EEPROM emulation via code, but that this breaks the wear leveling feature which sounds risky. I'm not clear on how much it reduces wear leveling etc.

I realize this is a very simplistic question that probably has a lot of nuance and complexity to it; apologies; I've been reading for hours trying to understand it all and I'm not getting very far.

Thanks for any ideas and insights.

Mike
 
You can edit the core library eeprom code for a small increase. But you should not attempt to use more of the flash for eeprom.

For a large increase and using more flash, best to go with LittleFS_Program and store your settings in small files.
 
@joepasquariello I saw your message but now it's gone. I appreciate your time and response.

Well using text files ups the complexity greatly - simply having an EEPROM address is very clean and simple to save config data from the user.

With a text file I'd need to keep track of headings and values, figure out how to find a particular value and edit it, as well as dealing with a larger file size using more flash ram...I'm sure it's all doable but it sounds like a nightmare. Maybe I just don't know, but I've had great success with using EEPROM library in past with what I'm trying to do...

Also the user would never open or see this config file; it would be stored only in Teensy Littlefuse library...

Could be it's a fine way to do things; if so please give me some pointers on how to do it efficiently.

Thanks much,

Mike
 
There is no reason why you can't save a struct (in binary-which is your configuration) on an SD card. Not much more complex than saving/restoring from EEPROM.
 
Hopefully the file below will help your understanding:
Code:
#include <Arduino.h>
#include <timelib.h>
#include <SD.h>

File configFile;

struct configType {
    uint32_t lastStartTime;
    uint32_t softwareVsNo;
    float    temperature;
    float    humidity;
};

configType config;
#define configFn "Config.fil"

void setup() {
    Serial.begin(9600);
    while (!Serial && millis() < 5000){}
    Serial.print("\nInitializing SD card...");

    if (!SD.begin(BUILTIN_SDCARD)) {
        Serial.println("initialization failed. Things to check:");
        Serial.println("* is a card inserted?");
        Serial.println("* did you change the chipSelect pin to match your shield or module?");
        return;
    }
    else {
        Serial.println("A card is present and recognised.");
        if (SD.exists(configFn)) {
            Serial.println("Config.fil exists....reading Config Data");
            configFile = SD.open(configFn, FILE_READ);
            configFile.read((uint8_t*)&config, sizeof(config));
            configFile.close();
        }
        else {
            Serial.println("example.txt doesn't exist....creating default file");
            config.humidity = 58.1;
            config.lastStartTime = now();
            config.softwareVsNo = 102;
            config.temperature = 202;
            configFile = SD.open(configFn, FILE_WRITE);
            configFile.write((uint8_t*)&config, sizeof(config));
            configFile.close();
        }
    }
}

void loop() {
}
 
Wow thank you so much @BriComp !

I really, really appreciate it.

Mike
By the way you can obviously use structs with EEPROM saving a lot of space over using text.
Use get and put to read and write your struct values.
Were you reading/writing text values or binary? If text, you will save a lot of space by using get and put with a struct.
 
With a text file I'd need to keep track of headings and values, figure out how to find a particular value and edit it, as well as dealing with a larger file size using more flash ram...

Also the user would never open or see this config file; it would be stored only in Teensy

If you’re familiar with INI files, they hide all the details and let you treat them as key-value stores. Search GitHub for Arduino INI Library.
 
By the way you can obviously use structs with EEPROM saving a lot of space over using text.
Use get and put to read and write your struct values.
Were you reading/writing text values or binary? If text, you will save a lot of space by using get and put with a struct.
I just use straight numbers for all eeprom values - bytes to be exact.

I’ll look deeper into structs and thank you so much for the helpful example.
 
If you’re familiar with INI files, they hide all the details and let you treat them as key-value stores. Search GitHub for Arduino INI Library.
Great to know!

I will check this out.

I’m not a programmer but I seem to spend a lot of time writing code, so your and Bri’s guidance is terrific!

Thank you Joe.
 
Back
Top