Teensy LC EEPROM Bug Demonstration Program

I wrote a simple program that demonstrates inconsistent functionality of Emulated EEPROM on the Teensy LC

PROBLEM:
The EEPROM writes data correctly ~70% of the time. The correct data can be read back during runtime, but upon reboot the data is corrupted with two different writes or just garbage data.
As a second problem, the EEPROM will refuse to be written after one of these corruption occurs, but after ~200 write attempt's it starts to works again.

This is not a worn out memory issue, this is apparent with Teensy LC's fresh out of the package
This is not a power loss issue, this happens even when gracefully shut down.

Here are previous threads I have found that may have been experiencing the same issue:
https://forum.pjrc.com/threads/60298-Teensy-LC-Diagnose-EEPROM-Issue
https://forum.pjrc.com/threads/35302-Teensy-LC-internal-EEPROM-issue
https://forum.pjrc.com/threads/64233-TeensyLC-EEPROM-emulation
https://forum.pjrc.com/threads/55336-Teensy-LC-EEPROM-Write-Speed

I am a big fan of Teensy and Paul and have used Teensys for years in my personal projects and contract work. I have the Teensy LC in a custom circuit board that will benefit directly from a fix to this bug.
I would have added an external EEPROM but on short notice I just implemented CRC checks to my firmware. Right now the user has to power cycle the board to confirm their configuration numbers are actually working.


Thanks for reading my post, let me know if I can provide any more information.






Code:
#include <EEPROM.h>

#define p  Serial.print
#define pl Serial.println


// This program demonstrates the common malfunctions that occur with the Teensy LC emulated EEPROM

// INSTRUCTIONS:
// 1. Starts by reading back what is stored in EEPROM, comparing it to the bytes to see which bank number they could have come from. Ideally it should be a 100% match with one of the 10 banks.
// 2. Write a one of the banks, which bank is chosen is determined with a random seed.
// 3. Immediately read back the EEPROM, and compare each byte to find which bank it belongs to.
// 4. The user is then expected to turn off the teensy in between tests, taking note of what was the last bank number written.
// 5. Turn on the teensy again and see if it's the same bank, or if it's corrupted.
// 6. If it is corrupted... wait and watch as the written bytes don't stick, but after a while they start to again.

// RESULTS:
// after turning the teensy back on, the result of the test is:
// 1. the correct data is shown
// 2. half one bank, haf the other
// 3. garbage data with bytes that do not match.

// NOTES:
// This glitch is not a result of turning the teensy off in the middle of a write. It exprences the same behavior with a graceful shutdown in my other project.
// This glitch is not a result of worn out program memory. It happens with brand new Teensy LC right out of the bag.


//try out different number of bytes:
#define numbytes 57  // 1 to 128


uint8_t readback[128];
uint8_t bank = 0;
bool foundMatch = 0;
int32_t firstBankVal = 0;
bool res = 0;

uint8_t sudorandom[10][128] = {
{0x42,0xFB,0x9F,0xE0,0x59,0x81,0x5A,0x81,0x66,0xA1,0x0E,0x5C,0x4E,0xB4,0xDA,0xEC,0x2F,0xF5,0x60,0x7E,0x8A,0xEA,0x3B,0xCA,0x2B,0xD5,0x82,0x69,0x1D,0xC3,0x84,0x13,0x0E,0xA6,0x6A,0x10,0xB3,0x3C,0xB4,0x4E,0x9A,0x80,0x4F,0x61,0x06,0x82,0x17,0xF4,0xCA,0x76,0xBA,0x84,0xE2,0xDC,0xC9,0x66,0x4F,0xA5,0x07,0x8C,0x8E,0x36,0xD1,0x97,0xDC,0x70,0x1B,0x0F,0x38,0x8A,0xFB,0x91,0xB0,0x20,0xB7,0x9F,0x90,0x62,0x6C,0x81,0x19,0x11,0xC4,0x32,0x47,0x04,0xEF,0xFB,0x7D,0x8F,0xF2,0xC3,0xCE,0xCB,0xF9,0xE2,0xE0,0xE3,0x2D,0xB7,0x4E,0xE0,0x5F,0x8C,0x6D,0x68,0xD3,0x40,0x1F,0xD5,0xF4,0x31,0x99,0xB2,0x74,0x82,0x86,0xBF,0xB3,0xB5,0x07,0x3E,0xC2,0x52,0x8B,0x7E,0x70,0xA6},
{0x02,0x47,0x45,0xA0,0x23,0x37,0x17,0x7E,0x09,0x26,0x1F,0x3E,0xC7,0xBB,0xED,0xF9,0xC5,0xE5,0x9B,0x2D,0x02,0x81,0x0F,0x76,0x3F,0x2B,0x35,0x90,0x7F,0x5A,0x2F,0x14,0x3C,0x3B,0x1B,0x55,0x34,0x8A,0xC5,0x5B,0x50,0x45,0x8F,0x9E,0x4C,0x3D,0x8A,0x9F,0x96,0x85,0x15,0x80,0x93,0xFE,0xE6,0xC1,0x49,0x2E,0x95,0x8B,0xF6,0x00,0x24,0x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0x3B,0xFD,0x9B,0x51,0x87,0x66,0x50,0xD6,0x68,0x8F,0xBD,0xA7,0x30,0x58,0xC2,0x80,0xED,0x81,0xCD,0x99,0x57,0xD8,0x6B,0xA0,0x0E,0x57,0x33,0x3B,0x0A,0xB0,0x34,0x84,0x28,0x85,0x91,0xBB,0xE8,0x96,0xB9,0xA7,0xAD,0x9A,0x0F,0x21,0x2A,0x9A,0x90,0xA3,0x6E,0x90,0xAE,0xB8,0x9A,0x46,0x12,0xBC,0x54,0x92,0x39,0x62,0x8F,0x1B,0xA4,0x48,0x35,0x3B,0x43,0x17,0x7F,0x12,0xF3,0x7A,0xEA,0x8C,0x80,0xD0},
{0x3F,0x93,0xD9,0xD4,0x2A,0x64,0x00,0x73,0x2B,0x9A,0x38,0x29,0x70,0x01,0xBF,0xBE,0xCE,0xF7,0x02,0x51,0x74,0x6E,0x01,0x61,0x1F,0x54,0xB0,0x61,0xB7,0x14,0x09,0x52,0x57,0x97,0xFE,0x41,0x63,0xBB,0x47,0x6E,0x11,0x0E,0x24,0x13,0x93,0x6C,0x96,0x0D,0x2D,0xEF,0x4F,0x49,0xFC,0xE9,0x2F,0x84,0xC6,0x3B,0x12,0x78,0x4E,0x04,0xAB,0x04,0xA5,0x9D,0xBE,0xB5,0x9D,0x01,0xEA,0x57,0x71,0xC4,0x7C,0xA7,0xB7,0xA2,0xCA,0x6E,0x75,0xE9,0xE9,0xB2,0x2E,0xB5,0x42,0x2D,0x8E,0xFF,0xB2,0x16,0xD3,0xD4,0x3A,0x6C,0x51,0xF8,0x1A,0x04,0x87,0x66,0xBF,0x42,0xFD,0x5B,0x02,0x4B,0x7A,0x78,0xC5,0xD4,0x92,0xBD,0x64,0x37,0xF1,0x35,0x9D,0xA5,0xD2,0x66,0xF7,0xF0,0x97,0x76,0xDF,0x5C}
};
// 0    1    2    3    4    5    6    7    8    9    10   1    2    3    4    5    6    7    8    9    20   1    2    3    4    5    6    7    8    9    30   1    2    3    4    5    6    7    8    9    40   1    2    3    4    5    6    7    8    9    50   1    2    3    4    5    6    7    8    9    60   1    2    3    4    5    6    7    8    9    70   1    2    3    4    5    6    7    8    9    80   1    2    3    4    5    6    7    8    9    90   1    2    3    4    5    6    7    8    9   100   1    2    3    4    5    6    7    8    9   110   1    2    3    4    5    6    7    8    9   120   1    2    3    4    5    6    7  




void setup() {
  Serial.begin(115200);
  delay(1000);
  
  pl("Random number banks");
  for(int k = 0; k < 10; k++){
    p("       Bank #"); p(k); p(": ");
    for(int i = 0; i < numbytes; i++){
      pHEX(sudorandom[k][i]);p(" ");
    }
    pl();
  }
  pl();

  p("Reading EEPROM: ");
  for(uint8_t i = 0; i < numbytes; i++){
    readback[i] = EEPROM.read(i);
    pHEX(readback[i]); p(" ");
  }
  pl();

  analyzeReadback();

  randomSeed(analogRead(A0));
}

void loop() {
  bank = random(10);
  
   p("Writing bank ");p(bank); p(": ");
  for(uint8_t i = 0; i < numbytes; i++){
    EEPROM.write(i , sudorandom[bank][i]);
    pHEX(sudorandom[bank][i]); p(" ");
  }
  pl();


  p("Reading EEPROM: ");
  for(uint8_t i = 0; i < numbytes; i++){
    readback[i] = EEPROM.read(i);
    pHEX(readback[i]); p(" ");
  }
  pl();

  analyzeReadback();

  delay(1500);

}

bool analyzeReadback(){
  foundMatch = 0;
  res = 1;
  firstBankVal = -1;
  p("    Bank Match: ");
  for(int i = 0; i < numbytes; i++){
    foundMatch = 0;
    for(int k = 0; k < 10; k++){
      if(sudorandom[k][i] == readback[i]){
        p(k);
        foundMatch = 1;
        if(firstBankVal == -1){firstBankVal = k;}
        if(firstBankVal != k){res = 0;}
        break;
      }
    }
    if(!foundMatch){
      res = 0;
      p("-");
    }
    p("  ");
  }
  pl();
  if(res){
    pl("       match :)        ");
    return 1;
  }else{
    pl("[[[ ERROR DETECTED! ]]]");
    return 0;
  }
}


void pHEX(uint8_t val){
  if(val < 16){
    p('0');
  }
   p(val,HEX);
}
 
Here is an 2 outputs from the program.
First the teensy is powered on, but after at restart, the first readback shows an amalgamation of the #2 bank data, and #3 bank.
I think this is because the EEPROM stopped actually truly writing at a point during the writing the #2 bank, and left the previous #3 bank bytes there untouched.


Code:
////////////////Here is an example output//////////////////////////////


Reading EEPROM: CE ED 2B 74 17 2E 7C 29 A5 5C 94 F9 D9 43 06 47 70 87 81 33 33 94 15 33 9D 4D 45 1D F5 E4 F7 83 38 E9 55 AA A6 70 93 42 3B 7E A3 78 FF 31 E0 B0 9C 03 9C 4C 84 45 55 9F 5B 
    Bank Match: 7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  
       match :)        
Writing bank 8: 2F F7 3F C6 7D 5A 9A B9 34 9C 0D 60 A0 38 38 C9 FF 06 1D 7F C7 EC D6 E2 D2 28 90 5A 1B 46 2D 2B 75 A9 22 CD B4 B4 B0 A9 79 44 29 AD 67 0C 90 D9 FD F5 1A 69 3B FD 9B 51 87 
Reading EEPROM: 2F F7 3F C6 7D 5A 9A B9 34 9C 0D 60 A0 38 38 C9 FF 06 1D 7F C7 EC D6 E2 D2 28 90 5A 1B 46 2D 2B 75 A9 22 CD B4 B4 B0 A9 79 44 29 AD 67 0C 90 D9 FD F5 1A 69 3B FD 9B 51 87 
    Bank Match: 8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  
       match :)        
Writing bank 9: 3F 93 D9 D4 2A 64 00 73 2B 9A 38 29 70 01 BF BE CE F7 02 51 74 6E 01 61 1F 54 B0 61 B7 14 09 52 57 97 FE 41 63 BB 47 6E 11 0E 24 13 93 6C 96 0D 2D EF 4F 49 FC E9 2F 84 C6 
Reading EEPROM: 3F 93 D9 D4 2A 64 00 73 2B 9A 38 29 70 01 BF BE CE F7 02 51 74 6E 01 61 1F 54 B0 61 B7 14 09 52 57 97 FE 41 63 BB 47 6E 11 0E 24 13 93 6C 96 0D 2D EF 4F 49 FC E9 2F 84 C6 
    Bank Match: 9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  
       match :)        
Writing bank 3: 19 60 06 2C FE CC 74 3A EF B0 93 C9 BF 2C FF 45 FA 5B B6 28 E7 0F E0 9B 86 96 03 1B B5 81 C8 D4 74 7A E4 18 AE 96 FF FE 7B 23 23 30 FB 74 7C C6 05 63 96 38 FE 33 C6 D6 12 
Reading EEPROM: 19 60 06 2C FE CC 74 3A EF B0 93 C9 BF 2C FF 45 FA 5B B6 28 E7 0F E0 9B 86 96 03 1B B5 81 C8 D4 74 7A E4 18 AE 96 FF FE 7B 23 23 30 FB 74 7C C6 05 63 96 38 FE 33 C6 D6 12 
    Bank Match: 3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  
       match :)        
Writing bank 2: D9 7E D2 DE 7E 70 1B C3 EC C8 8B 3D F0 E8 DE E7 6B A2 68 26 AE 7C 9C 2A 20 7B 1B AD 7B 65 E5 56 41 E8 BE 83 97 06 DB 86 4F 81 F3 66 57 CA 0F A1 BD F7 51 C9 E1 A5 12 3E 56 
Reading EEPROM: D9 7E D2 DE 7E 70 1B C3 EC C8 8B 3D F0 E8 DE E7 6B A2 68 26 AE 7C 9C 2A 20 7B 1B AD 7B 65 E5 56 41 E8 BE 83 97 06 DB 86 4F 81 F3 66 57 CA 0F A1 BD F7 51 C9 E1 A5 12 3E 56 
    Bank Match: 2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  
       match :)                                                                                                                            
Writing bank 7: CE ED 2B 74 17 2E 7C 29 A5 5C 94 F9 D9 43 06 47 70 87 81 33 33 94 15 33 9D 4D 45 1D F5 E4 F7 83 38 E9 55 AA A6 70 93 42 3B 7E A3 78 FF 31 E0 B0 9C 03 9C 4C 84 45 55 9F 5B 
Reading EEPROM: CE ED 2B 74 17 2E 7C 29 A5 5C 94 F9 D9 43 06 47 70 87 81 33 33 94 15 33 9D 4D 45 1D F5 E4 F7 83 38 E9 55 AA A6 70 93 42 3B 7E A3 78 FF 31 E0 B0 9C 03 9C 4C 84 45 55 9F 5B 
    Bank Match: 7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  7  
       match :)        
Writing bank 6: EC 91 10 F7 7A 7E 26 42 81 F5 50 8D 3F 1E 51 16 17 11 8F 25 FB A2 0D 01 F1 B9 0A F4 A4 16 FC D2 4D 7F D1 9A DE 56 60 EF EB 6C BC C1 E6 F1 07 A5 71 41 6A 43 98 17 DA 34 65 
Reading EEPROM: EC 91 10 F7 7A 7E 26 42 81 F5 50 8D 3F 1E 51 16 17 11 8F 25 FB A2 0D 01 F1 B9 0A F4 A4 16 FC D2 4D 7F D1 9A DE 56 60 EF EB 6C BC C1 E6 F1 07 A5 71 41 6A 43 98 17 DA 34 65 
    Bank Match: 6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  
       match :)        



/////////////////After being powered off and back on//////////////////////


Reading EEPROM: D9 7E D2 DE 7E 70 1B C3 EC C8 8B 3D F0 E8 DE E7 6B A2 68 26 AE 7C 9C 2A 20 7B 1B AD 7B 65 E5 56 41 E8 BE 83 97 06 DB 86 4F 81 23 30 FB 74 7C C6 05 63 96 38 FE 33 C6 D6 12 
    Bank Match: 2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  
[[[ ERROR DETECTED! ]]]
Writing bank 0: 42 FB 9F E0 59 81 5A 81 66 A1 0E 5C 4E B4 DA EC 2F F5 60 7E 8A EA 3B CA 2B D5 82 69 1D C3 84 13 0E A6 6A 10 B3 3C B4 4E 9A 80 4F 61 06 82 17 F4 CA 76 BA 84 E2 DC C9 66 4F 
Reading EEPROM: 00 86 00 10 33 14 14 02 98 00 45 01 04 80 17 80 6B A2 68 26 AE 7C 9C 2A 20 7B 1B AD 7B 65 E5 56 08 60 10 80 A2 50 81 42 0B 81 23 30 FB 74 7C C6 05 63 96 38 FE 33 C6 D6 12 
    Bank Match: -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  -  -  -  -  -  -  -  7  -  2  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  
[[[ ERROR DETECTED! ]]]
Writing bank 1: 02 47 45 A0 23 37 17 7E 09 26 1F 3E C7 BB ED F9 C5 E5 9B 2D 02 81 0F 76 3F 2B 35 90 7F 5A 2F 14 3C 3B 1B 55 34 8A C5 5B 50 45 8F 9E 4C 3D 8A 9F 96 85 15 80 93 FE E6 C1 49 
Reading EEPROM: 14 11 0B 05 30 82 05 01 50 01 0A 94 04 14 88 92 6B A2 68 26 AE 7C 9C 2A 20 7B 1B AD 7B 65 E5 56 04 05 11 80 92 56 60 C1 49 81 23 30 FB 74 7C C6 05 63 96 38 FE 33 C6 D6 12 
    Bank Match: -  -  5  -  -  -  -  -  -  -  -  -  -  -  -  -  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  -  -  -  -  -  6  6  -  -  2  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  
[[[ ERROR DETECTED! ]]]
Writing bank 6: EC 91 10 F7 7A 7E 26 42 81 F5 50 8D 3F 1E 51 16 17 11 8F 25 FB A2 0D 01 F1 B9 0A F4 A4 16 FC D2 4D 7F D1 9A DE 56 60 EF EB 6C BC C1 E6 F1 07 A5 71 41 6A 43 98 17 DA 34 65 
Reading EEPROM: 88 11 40 05 1A 82 10 01 04 01 0A 94 04 14 88 92 17 11 8F 25 FB A2 0D 01 F1 B9 0A F4 A4 16 FC D2 4D 7F D1 9A DE 56 60 EF EB 6C BC C1 E6 F1 07 A5 71 41 6A 43 98 17 DA 34 65 
    Bank Match: -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  
[[[ ERROR DETECTED! ]]]
Writing bank 5: BA EF 0B 18 49 6A 80 FA 31 1D 18 C6 49 CC 79 9F E7 43 8E 23 7E 03 A1 65 05 16 D6 11 41 47 67 87 40 70 D2 F6 1A 95 7C E2 97 FF 97 3A A9 9C 5E AC A3 FC 86 21 97 F1 F0 48 A0 
Reading EEPROM: BA EF 0B 18 49 6A 80 FA 31 1D 18 C6 49 CC 79 9F E7 43 8E 23 7E 03 A1 65 05 16 D6 11 41 47 67 87 40 70 D2 F6 1A 95 7C E2 97 FF 97 3A A9 9C 5E AC A3 FC 86 21 97 F1 F0 48 A0 
    Bank Match: 5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  
       match :)        
Writing bank 3: 19 60 06 2C FE CC 74 3A EF B0 93 C9 BF 2C FF 45 FA 5B B6 28 E7 0F E0 9B 86 96 03 1B B5 81 C8 D4 74 7A E4 18 AE 96 FF FE 7B 23 23 30 FB 74 7C C6 05 63 96 38 FE 33 C6 D6 12 
Reading EEPROM: 19 60 06 2C FE CC 74 3A EF B0 93 C9 BF 2C FF 45 FA 5B B6 28 E7 0F E0 9B 86 96 03 1B B5 81 C8 D4 74 7A E4 18 AE 96 FF FE 7B 23 23 30 FB 74 7C C6 05 63 96 38 FE 33 C6 D6 12 
    Bank Match: 3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  
       match :)        
Writing bank 4: 27 01 7F 90 09 DA 0C 1A 8E FC 89 FC 4F 1F 8A 0D F2 12 D0 17 FC EF E3 56 F0 32 C8 BB 58 7B C5 10 DD 9D 9F 44 12 80 F4 6B 9F E4 9F F7 98 2D 02 8B 7F 17 8D 63 AD 97 9A C0 99 
Reading EEPROM: 27 01 7F 90 09 DA 0C 1A 8E FC 89 FC 4F 1F 8A 0D F2 12 D0 17 FC EF E3 56 F0 32 C8 BB 58 7B C5 10 DD 9D 9F 44 12 80 F4 6B 9F E4 9F F7 98 2D 02 8B 7F 17 8D 63 AD 97 9A C0 99 
    Bank Match: 4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  
       match :)
 
I also get odd behaviour from a Teensy LC.
I tried the code on a T3.2 and a T4.1 and they both work all the time.

Pete
 
I can confirm this. It happens without the EEPROM library, too.
I used eeprom_write_block(), eeprom_read_block().
Interesting is, that something happens after a few block writes and it starts "working" (I doubt) - even more interesting is, that after power on, it reads wrong values which look like there wasn't a real flash write?
 
The other models have their own eeprom-emulation code, so it's unlikely they are affected.

Code:
Reading EEPROM: EC 91 10 F7 7A 7E 26 42 81 F5 50 8D 3F 1E 51 16 17 11 8F 25 FB A2 0D 01 F1 B9 0A F4 A4 16 FC D2 4D 7F D1 9A DE 56 60 EF EB 6C BC C1 E6 F1 07 A5 71 41 6A 43 98 17 DA 34 65 7A 15 D2 E5 51 7D F6 87 4E 92 48 35 BE 7C 4E 7B D0 25 0F 02 C5 79 8B 61 EA F1 AC F4 3C A8 01 F3 20 1D 9C 8B 5E DD 22 A1 78 44 41 33 3E 5C A8 57 94 AD 3A 06 F8 81 18 C5 2A 5A C8 21 DB 88 AC 
    Bank Match: 6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  
       match :)        
Writing bank 4: 27 01 7F 90 09 DA 0C 1A 8E FC 89 FC 4F 1F 8A 0D F2 12 D0 17 FC EF E3 56 F0 32 C8 BB 58 7B C5 10 DD 9D 9F 44 12 80 F4 6B 9F E4 9F F7 98 2D 02 8B 7F 17 8D 63 AD 97 9A C0 99 EF EF 52 54 4F D3 C2 28 D2 C4 49 AE F0 94 9B 6F CB 5C 21 D3 1D 37 0A 52 7D 45 5A 08 78 E7 93 1B 4E 9C 03 68 C6 59 08 C4 73 0A 89 9F 4B 9C B7 D4 82 7F 49 EE FE 59 00 F6 79 70 C9 34 92 CC B1 
Reading EEPROM: 27 01 7F 90 09 DA 0C 1A 8E FC 89 FC 4F 1F 8A 0D F2 12 D0 17 FC EF E3 56 F0 32 C8 BB 58 7B C5 10 DD 9D 9F 44 12 80 F4 6B 9F E4 9F F7 98 2D 02 8B 7F 17 8D 63 AD 97 9A C0 99 EF 15 D2 E5 51 7D F6 87 4E 92 48 35 BE 7C 4E 7B D0 25 0F 02 C5 79 8B 61 EA F1 AC F4 3C A8 01 F3 20 1D 9C 8B 5E DD 22 A1 78 44 41 33 3E 5C A8 57 94 AD 3A 06 F8 81 18 C5 2A 5A C8 21 DB 88 AC 
    Bank Match: 4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  6  
[[[ ERROR DETECTED! ]]]
Writing bank 4: 27 01 7F 90 09 DA 0C 1A 8E FC 89 FC 4F 1F 8A 0D F2 12 D0 17 FC EF E3 56 F0 32 C8 BB 58 7B C5 10 DD 9D 9F 44 12 80 F4 6B 9F E4 9F F7 98 2D 02 8B 7F 17 8D 63 AD 97 9A C0 99 EF EF 52 54 4F D3 C2 28 D2 C4 49 AE F0 94 9B 6F CB 5C 21 D3 1D 37 0A 52 7D 45 5A 08 78 E7 93 1B 4E 9C 03 68 C6 59 08 C4 73 0A 89 9F 4B 9C B7 D4 82 7F 49 EE FE 59 00 F6 79 70 C9 34 92 CC B1 
Reading EEPROM: 40 01 03 90 00 DA 00 1A 0D FC 89 FC 4F 1F 8A 0D 08 12 48 17 63 EF 81 56 10 32 C8 BB 58 7B C5 10 62 9D 09 44 11 80 00 6B 80 E4 9F F7 98 2D 02 8B 10 17 C9 63 4C 97 91 C0 99 EF 15 D2 E5 51 7D C2 28 D2 C4 49 AE F0 94 9B 6F CB 5C 21 D3 1D 37 0A 52 7D 45 5A 08 78 E7 93 1B 4E 9C 03 68 C6 59 08 C4 73 0A 89 9F 4B 9C B7 D4 82 7F 49 EE FE 59 00 F6 79 70 C9 34 92 CC B1 
    Bank Match: -  4  -  4  -  4  9  4  -  4  4  4  4  4  4  4  -  4  -  4  -  4  -  4  -  4  4  4  4  4  4  4  -  4  -  4  -  4  -  4  -  4  4  4  4  4  4  4  -  4  -  4  -  4  -  4  4  4  6  6  6  6  6  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  4  
[[[ ERROR DETECTED! ]]]
Here, it wasn't a power cycle.
You see that it wrote the block 4 data - but even after writing block 4 again it returns wrong values.
From this, it looks like a problem with the wear algorithm.

It even prints values that are not part of any of the blocks.
 
Last edited:
I'm developing a Software Defined Transceiver (SDT) for amateur radio:
BreadBoardSTDT41.jpg
and we need to store critical frequency and filter values in EEPROM lest we run amuck of FCC regulations. Has anyone figured out a work-around? Failing that, what's been the experience using the T4.1 SD card?
 
I'm developing a Software Defined Transceiver (SDT) for amateur radio:
...
and we need to store critical frequency and filter values in EEPROM lest we run amuck of FCC regulations. Has anyone figured out a work-around? Failing that, what's been the experience using the T4.1 SD card?

Only indication of problem is T_LC. The T_4.x shows no such problems or issues (not does any T_3.x). No issues reported with SD card either - though new faster library code replacing the function of the prior SD.h code ... a copy of Grieman SDFat included in TD 1.54 b7 and beyond.
 
Thanks, defragster. I must be doing something wrong with the EEPROM, then. Pretty simple stuff. I just have a large structure and using put() and get() to EEPROM. Hopefully it will be a flat forehead mistake and I won't have to mess with the SD card. Thanks again...
 
Still having problems with EEPROM. It appears that all of the discrete variables are stored correctly and at the correct relative addresses. However, aggregate data types always come back as 0 even when they are "put()" with values. Those values are either int, long, or float. A char array at the front seems to do fine. It makes no sense to me that the discrete variables are fine, but the arrays are messed up.
 
That's the problem. I write a small test program like this:

Code:
#include <EEPROM.h>
#define ARRAY_SIZE  5

struct {
  char aString[10];
  int val;
  long bigVal;
  float dataPoints[ARRAY_SIZE];
} myStructure;

void setup() 
{
  int i;
  
  Serial.begin(9600);

  while (!Serial) ;

  strcpy(myStructure.aString, "V101");
  myStructure.val = 15;
  myStructure.bigVal = 7030000L;
  for (i = 0; i < ARRAY_SIZE; i++) {
    myStructure.dataPoints[i] = (float) i;
  }
  EEPROM.put(0, myStructure);
  memset(&myStructure, 0, sizeof(myStructure));    // Clear the data
  EEPROM.get(0, myStructure);
  Serial.println(myStructure.aString);
  Serial.println(myStructure.val);
  Serial.println(myStructure.bigVal);
  for (i = 0; i < ARRAY_SIZE; i++) {
    Serial.println(myStructure.dataPoints[i]);
  }
}

void loop() {

}

and it works perfectly. The only real difference is that the structure is 464 bytes long. Like I said, this is going to be one of those flat-forehead mistakes, but so far, the bug has eluded me.
 
SOLVED:

It was a flat forehead mistake. I was out of sync with the put() and get() because I had buried one of the calls inside another EEPROM call. I broke my own rule of making each function only perform a single task and it came back to bite me in the butt.

Thanks to all who scratched their head on my behalf.
 
Here's a <link to the thread> where EEPROM writes were previously not working for T4. You might try the test program from that thread on your LC to see if it helps to reproduce the problem easily, just in case the underlying cause is something similar.

Mark J Culross
KD5RXT
 
After some more testing, i'm quite sure it only happens when there is/was a powerloss during a write.
In that case the internal wear leveling does not work anymore - of course, because it is in an inconsitent state, then.
So, I think the only way to "fix" that, is to make sure that this condition can not happen.
 
Interesting Frank!

For T_4.? somebody wrote an EPROM decoder/verifier sketch.

Wondering if such a thing might restore FUTURE function - if not be capable of seeing/saving 'good data?
 

Attachments

  • eeprom.c
    15.6 KB · Views: 76
Paul: Are you saying that the file should only be placed in the Teensy3 directory; that the T4's are okay?
 
Paul: Are you saying that the file should only be placed in the Teensy3 directory; that the T4's are okay?

Indeed that file is Teensy3 folder specific as indicated, and will break usage if place in Teensy4 folder. And the indicated change is even under Teensy_LC #ifdef of "KINETISL" so fix applies only to error reported above for T_LC.

No errors have been reported with Teensy 4 usage.
 
I've been running a number of other tests here, trying to make sure all cases are truly covered by this fix. So far it's looking pretty good.

Please let me know how it works for you?


Paul: Are you saying that the file should only be placed in the Teensy3 directory; that the T4's are okay?

Yes, confirmed, this is only about Teensy LC.

But if you're feeling concerned about any other boards, please do run the test code or any other tests you can imagine. If you can reproduce a problem on any other board, please start a new thread.
 
Back
Top