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

Thread: Teensy 3.0 and EEPROM usage

  1. #1
    Member
    Join Date
    Oct 2012
    Location
    Portland, OR
    Posts
    36

    Teensy 3.0 and EEPROM usage

    I am able to run the following code on an Arduino board and it works as expected by retrieving stored values from EEPROM. When it is run on the Teensy 3, the values retrieved from the EEPROM after powering it off are not as expected.

    On the Arduino - the values in memory correctly reflect the increasing index. On the Teensy 3 - I am getting the value 255 in each memory index.

    OS: Windows 7 64-bit

    Steps to reproduce
    1) Upload/Run the code below to store some values in EEPROM
    2) Comment out the first_time() function
    3) Upload/Run the code again to display the stored values

    I'd like to know if someone can validate this is an issue on the Teensy 3- or that my code is wonky.....

    Thanks!

    -------------------------------------------------------------------------------------------------------------------------------------------
    #include <EEPROM.h>

    #define VALUES 26

    void setup()
    {
    Serial.begin(38400);
    first_time(); // comment out after first run - used to store values in EEPROM
    delay(3000); // delay so we have time to launch terminal
    display_values();
    }


    void loop()
    {
    }


    void first_time()
    {
    for (byte x=0; x<VALUES; x++)
    EEPROM.write(x,x);
    }

    void display_values()
    {
    for (byte x=0; x<VALUES; x++)
    {
    Serial.print("Position: "); Serial.print(x); Serial.print(" Value: "); Serial.println(EEPROM.read(x));
    }
    }

  2. #2
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    635
    My Teensy 3 is currently busy with a different experiment, so I haven't tried your code yet. But I note you mentioned "after powering off". Does it work if you don't power off? If so, I'm guessing it has to do with the so-called "FlexMemory" in the Freescale ARM part which is apparently partly FlexRAM and partly FlexNVM (Flash?) which I do not understand, but maybe you are somehow getting the "RAM" rather than the non-volatile part (?) see for example chapter 28 in the data sheet, http://cache.freescale.com/files/32b...64M50SF0RM.pdf

  3. #3
    EEPROM is wiped out at each upload, but is working normally otherwise in my tests.
    For the moment I use an SD card to keep values between uploads

  4. #4
    Member
    Join Date
    Oct 2012
    Location
    Portland, OR
    Posts
    36
    Thanks for the input - if the EEPROM is wiped out at each upload, this explains the difference I'm seeing between arduino functionality.

  5. #5
    To save someone the trouble:

    I thought this might have to do with the .hex file containing data in the FlexRAM (0x14000000) region and thus overwriting. In the Makefile the objcopy command specifies "-R .eeprom" to remove a .eeprom section. But I did some work with the linker input file to try to add this section (and then explicitly remove it with objcopy) and this didn't seem to make a difference for the test program posted earlier.

    So my guess is that it's actually the hardware bootloader (on the extra chip) that's overwriting this. I'd love to hear different. Being able to have multiple Teensy's on the same host computer with different USB "names" (based on an EEPROM resident serial number) is a longer term goal of mine.

    -c

  6. #6
    Paul said on kickstarter that he burns a different MAC on every Teensy 3 sent on a special WORM in the freescale chip, it should be adequate for this use, but I have no Idea how to access it.

  7. #7
    This is old, but for posterity: this thread has the code needed to read the mac address.

  8. #8
    Junior Member
    Join Date
    Aug 2013
    Location
    San Rafael, CA
    Posts
    1
    Ok, I get that the eeprom is cleared on every upload, and I found that power cycling seem to retain the eeprom, but it also seems like it's cleared every time you hit the reset (activate?) button, even if you don't upload anything. Has any one else noticed that or is it just me?

  9. #9
    Member Dawnmist's Avatar
    Join Date
    Nov 2012
    Location
    Australia
    Posts
    51
    Quote Originally Posted by jon View Post
    Ok, I get that the eeprom is cleared on every upload, and I found that power cycling seem to retain the eeprom, but it also seems like it's cleared every time you hit the reset (activate?) button, even if you don't upload anything. Has any one else noticed that or is it just me?
    The reset button on the teensy resets the device into reprogram mode - if you have the teensy loader running on your pc when you do that it then automatically reprograms your teensy with the last compile you did. (If you don't have the teensy loader running, the teensy would sit there in reprogram mode forever waiting to download a new program).

    If you just want to restart the teensy, unplug and replug the usb. (Or if I remember correctly you can put a button between "Reset" and "Ground" - the on-board button connects "Program" and "Ground").

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,344
    Teensyduino 1.16 will fix this problem, so the EEPROM will be preserved when you upload code.

  11. #11
    Junior Member
    Join Date
    Apr 2013
    Posts
    3

    Unhappy Teensy 3 , Teesiduino 1.16 and EEPROM

    Quote Originally Posted by PaulStoffregen View Post
    Teensyduino 1.16 will fix this problem, so the EEPROM will be preserved when you upload code.
    Paul,
    i installed Arduino 1.0.5, Teensyduino 1.16 and uploaded my program to test if the eeprom will keep the programmed values.
    I closed arduino AND teensyduino before i started my program. Then i changed EEPROM values and re-powered the Teensy 3.

    No change compared to Version 1.16!

    I later i noticed that a small window (updating bootloader) remained open (hidden behind my USB-TreeViewer window) indefinately.

    After reinstallation of the Teensyduino 1.16, no further bootloader update was activated.

    But the EEPROM does not keep the programmed values.

    Any idea what is going wrong?

    Regards

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,344
    First, use Help > Verbose Info from Teensy Loader's menu. When it detects your Teensy, it will show the bootloader version. 1.01 is the old version, 1.02 is the new one (which is supposed to preserve the eeprom). The first step is to verify which version your board currently has.

    If you're on 1.02, the next step (seems like I write this every day on these forums) is to post the test code, so I can try to reproduce the problem here.

  13. #13
    Junior Member
    Join Date
    Apr 2013
    Posts
    3

    Teensy 3 + Teensyduino 1.16 and EEPROM --- Solved

    Quote Originally Posted by PaulStoffregen View Post
    First, use Help > Verbose Info from Teensy Loader's menu. When it detects your Teensy, it will show the bootloader version. 1.01 is the old version, 1.02 is the new one (which is supposed to preserve the eeprom). The first step is to verify which version your board currently has.

    If you're on 1.02, the next step (seems like I write this every day on these forums) is to post the test code, so I can try to reproduce the problem here.
    @Paul
    Thanks for the fast reply ... the bootloader update obviously failed; the version was 1.01. So >> if the message window does not dissapear, the update failed.

    After completely removing all Arduino and Teensyduino parts and usb drivers, and reinstallation, the Teensy bootloader was now updated to 1.02!
    No remaining message window any more.

    The EEPROM content is now preserved as expected.

    Regards

  14. #14
    Junior Member
    Join Date
    May 2014
    Posts
    1
    i am using TWR-K60F120M .I want use flex nvm as E2prom.please suggest the source code.
    then how to check?

  15. #15
    Junior Member
    Join Date
    Sep 2014
    Posts
    13
    PaulStoffregen
    Teensyduino 1.16 will fix this problem, so the EEPROM will be preserved when you upload code.

    Sorry Paul, and how to clear EEPROM every time when I upload the code? use v1.19
    Tried to play with -R .eeprom in objcopy, but without success...

    Nikolai

Posting Permissions

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