Teensy 4.1 E2END value for maximum emulated EEPROM

johnsondavies

New member
The file teensy4/avr/eeprom.h defines E2END which specifies how much emulated EEPROM is available:

Code:
#if defined(ARDUINO_TEENSY40)
#define E2END 0x437
#elif defined(ARDUINO_TEENSY41)
#define E2END 0x10BB
#endif

In this earlier post @Branan said that on Teensy 4.0 the value of E2END can be increased up to a maximum of 0xEC6, giving 3783 bytes of EEPROM with reduced wear levelling:

https://forum.pjrc.com/threads/57377?p=214566&viewfull=1#post214566

I couldn't quite understand how he arrives at this figure; there's a test in avr/cores/teensy4/eeprom.c:

Code:
#if E2END > (255*FLASH_SECTORS-1)
#error "E2END is set larger than the maximum possible EEPROM size"
#endif

but that calculation gives a maximum of 255 x 15 - 1 or 3824 bytes, which is 41 more.

My question is: what is the largest value I can set E2END to on the Teensy 4.1 to get the maximum contiguous EEPROM?
 
Teensy 4.1 has 63 sectors reserved for EEPROM emulation. So if you're willing to go with minimal wear leveling, you can set it to 0x3EC0, giving 16065 bytes of storage.
 
Teensy 4.1 has 63 sectors reserved for EEPROM emulation. So if you're willing to go with minimal wear leveling, you can set it to 0x3EC0, giving 16065 bytes of storage.

Thanks - I see that's 255 x 63 - 1.

So on Teensy 4.0, why isn't the maximum 255 x 15 - 1 or 0xEF0 rather than the value 0xEC6 recommended by @Branan?

Thanks, David
 
Hello. I am trying to increae the Teensy 4.1 emulated EEPROM as described above by changing the #define E2END 0x10BB line in C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4\avr\eeprom.h to #define E2END 0x3EC0 but when I upload a sketch with say EEPROM.write(6000,100); it doesn't write the value 100 as EEPROM.read(6000) gives 255. By the way for me the path of eeprom.h is not teensy4/avr/eeprom.h but is ...\teensy\avr\cores\teensy4\avr\eeprom.h. there is no eeprom.h in teensy4/avr/. Whats wrong with my attempt ?
 
Whats wrong with my attempt ?

Difficult to say what's wrong, as I can't see your screen.

But as a first troubleshooting step, I'd recommend temporarily adding a syntax error to the file you're editing. Click Verify. It Arduino IDE gives an error for that line number in that file, then you've at least confirmed you're editing the correct file.

Especially if you've installed both the old and new IDE, it's very easy to end up with multiple copies of these files and then end up editing a different file than the compiler is actually reading.
 
Thank you ! Indeed even after disinstalling the new IDE and just using the old one (1-8-13) it did not read the file in C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4\avr\ but the one in
C:\Users\....\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\cores\teensy4\avr.
Now it works !
 
Last edited:
Back
Top