Adjusting the Emulated EEPROM size on 4.0?

NuttyMonk

Well-known member
Hi all,

just a quick check to see if it is possible to adjust the size of the emulated EEPROM on the Teensy 4.0.

I'd made my project on the 3.2 and was able to get 6 save spaces for settings out of it, but since the 3.2 is out of stock i have moved to a 4.0 and now can only get 3 save spaces. I'm using 314 bytes for each save space.

I realise there is a lot of code that goes into the background of the Teensy dev boards but if it is a case of simply adjusting a value somewhere i would like to give it a try.

Cheers

NM
 
Yes, just edit E2END in the core library. Look for it in avr/eeprom.h (as E2END is an AVR convention). Max possible emulated EEPROM size for Teensy 4.0 is 3825 bytes. If you try to configure more than the hardware allows, you'll get a compiler error.

Recommend you don't change anything in the file with this comment near the top.

Code:
// To configure the EEPROM size, edit E2END in avr/eeprom.h.
//
// Generally you should avoid editing this code, unless you really
// know what you're doing.

The underlying flash endurance (100K erase/write cycles per sector) does not change. If most of your extra usage will be infrequent writes, then not an issue. But if you will use it for something like data logging where you overwrite it all on a regular basis, you'll get less wear leveling by emulating a larger size.
 
Thanks for the replies. I'll give that a go.

There's absolutely no issue with me using up enough space on the flash memory that i can't run at the max emulated EEPROM. That will give me 12 save spaces on the Teensy 4.0. Nice!

Cheers

NM
 
Hi all,

so i found the eeprom.h file in this location

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4\avr

and changed this
Code:
#define E2END 0x437

to this
Code:
#define E2END 0xEF1

Paul said that 3825 bytes was the maximum and as far as i can tell

Code:
0xEF1 = 3825

yet i am getting a compiler error saying that

Code:
"E2END is set larger than the maximum possible EEPROM size"

Does anyone have any ideas why this is happening?

Cheers

NM
 
Looking at eeprom.c this is the line that generates that error message.
https://github.com/PaulStoffregen/cores/blob/3c442f9c67ee785ddad921ff5d0a3ebe5a9682ca/teensy4/eeprom.c#L53
Looks like you want to set it to 3824. 3824 would be the max address, 0 is the starting address, the size of the eeprom would be 3825. The variable is setting the end address.

Code:
#if defined(ARDUINO_TEENSY40)
#define FLASH_BASEADDR 0x601F0000
#define FLASH_SECTORS  15
#elif defined(ARDUINO_TEENSY41)
#define FLASH_BASEADDR 0x607C0000
#define FLASH_SECTORS  63
#elif defined(ARDUINO_TEENSY_MICROMOD)
#define FLASH_BASEADDR 0x60FC0000
#define FLASH_SECTORS  63
#endif


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

The default value was 0x437 or 1079, which is 1 less than 1080 since address 0 is included.
 
Last edited:
Back
Top