Skip to content

FlashAsEEROM weird issues #44

@tuxedo0801

Description

@tuxedo0801

We have some issues with the EEPROM lib ...

The effects we see in a more complex program:

We write >1,5k of data and finally do a commit(). This gives no error, but it seems that after next device startup not all the data is there.

I tried to narrow down the issue to a small testable example:

#define EEPROM_EMULATION_SIZE 2048
#include <FlashAsEEPROM.h>

void setup() {
  SerialUSB.begin(115200);

  while (!SerialUSB) {
  }

  byte firstByte = EEPROM.read(0x0000);

  // if EEPROM is "empty" ...
  if (firstByte == 0xFF) {

    
    // write repeatedly 0x00...0xFF to "EEPROM"
    SerialUSB.println("write to EEPROM ...");

    byte v = 0x00;


    for (int i = 0; i < EEPROM_EMULATION_SIZE; i++) {
      
      SerialUSB.print("Writing: #");
      SerialUSB.print(i);
      SerialUSB.print(" -> ");
      SerialUSB.println(v);
      EEPROM.write(i, v);
      
      v++;
      
    }
    
    SerialUSB.println("  Doing commit ...");
    EEPROM.commit();
    SerialUSB.println("  Doing commit ...*DONE*");
    
    SerialUSB.println("Writing *DONE*");
    SerialUSB.println("Do manual reboot now ...");
    
  }
  else
  {

    // Verify that EEPROM contains repeatedly 0x00...0xFF 
    SerialUSB.println("Read from EEPROM ...");
    byte v = 0x00;
    for (int i = 0; i < EEPROM_EMULATION_SIZE; i++) {

      
      
      byte b = EEPROM.read(i);
      SerialUSB.print("Read: #");
      SerialUSB.print(i);
      SerialUSB.print(" -> ");
      SerialUSB.print(b);
      SerialUSB.print(" vs. ");
      SerialUSB.println(v);
      
      
      if (b!=v) {
        SerialUSB.println("WRONG!!!!");  
        while(true);
      }

      v++;
            
    }
    SerialUSB.println("All fine!!!");  

  }
}

void loop() {
  // nothing to do here
}

The idea: On the first startup, fill the entire EEPROM with sequences of 0x00...0xFF
Then you need to restart the device. Now it will compare the EEPROM content with the required 0x00..0xFF sequences.

Interestignly, I get a different, but also weird behavior:

If I set the EEROM emulation size to 1024, it works quite well.Writing and reading works as expected. All the data can be written und reading out return the same data.

On 2048 the "commit" after writing all the data is hanging forever.

And on 4096 or 8192 it struggles with writing to EEPROM (the for-loop is not finished): Somewhere around EEPROM index ~2200 it just stops writing.

Any ideas on what's wrong?
I'm using a custom SAMD21 board...

best regards,
Alex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions