Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Adjusting the Emulated EEPROM size on 4.0?

  1. #1

    Adjusting the Emulated EEPROM size on 4.0?

    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

  2. #2
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    814
    Could you use the T4.1?
    It has 2X T3.2 EEPROM and 4X T4.0 EEPROM.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,572
    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.

  4. #4
    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

  5. #5
    Hi all,

    so i found the eeprom.h file in this location

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

    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

  6. #6
    Looking at eeprom.c this is the line that generates that error message.
    https://github.com/PaulStoffregen/co...4/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 by Spencez; 06-18-2022 at 11:57 PM. Reason: wording

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,572
    Try 0xEF0.


    Does anyone have any ideas why this is happening?
    Probably because E2END is meant to be the address of the last byte, not the number of bytes. So 0xEF1 would be off by 1.

  8. #8
    Ah,

    that makes sense. Computers-count-from-zero strikes again!!!

    lol

    NM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •