Teensy 3.0 and EEPROM usage

rbrockman

Active member
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));
}
}
 
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/32bit/doc/ref_manual/K20P64M50SF0RM.pdf
 
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
 
Thanks for the input - if the EEPROM is wiped out at each upload, this explains the difference I'm seeing between arduino functionality.
 
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
 
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.
 
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?
 
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").
 
Teensy 3 , Teesiduino 1.16 and EEPROM

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
 
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.
 
Teensy 3 + Teensyduino 1.16 and EEPROM --- Solved

:rolleyes:
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
 
i am using TWR-K60F120M .I want use flex nvm as E2prom.please suggest the source code.
then how to check?
 
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
 
Back
Top