EEPROM wear leveling

Status
Not open for further replies.

spencoid

Well-known member
I am using the EEPROM to store a few bytes of data during power offs. I am being careful to only post data if it has changed but i am still concerned about the million write cycle limit. I am trying to figure out how to write the few bytes to different locations over time to level the wear on the EEPROM. I can think of some methods using a stored index etc but the index itself needs to be in the same location or the program will not know where to find it. There must be some way to solve this problem. Of does the EEPROM do wear leveling itself and therefore i don't have to worry about this?
 
Which Teensy are you using? EEPROM works differently on the various models.

i am testing with the 3.2 which is adequate for my simple projects but would also be interested in how it works on the 3.5 and 3.6 which i have just started using for more complicated tasks. i am having great fun with the audio library and the 3.5. i am amazed at how much work i can chuck at this one and not even notice a difference in performance :)
 
On Teensy 3.x, the hardware automatically wear levels. It actually uses flash memory and RAM to emulate EEPROM (and Teensy LC uses a similar lower performance software-based approach without the dedicated RAM).

To get higher endurance on Teensy 3.x you can edit hardware/teensy/avr/cores/teensy3/avr/eeprom.h. Just reduce the size of E2END. Smaller size will increase the wear leveling, but of course you get less writable EEPROM data.

This only applies on Teensy 3.x. The software algorithm used on Teensy LC wear levels actual usage across a fixed space, so there's nothing to tune on Teensy LC. Reducing the E2END doesn't give you different endurance on LC, but it does on Teensy 3.2, 3.5 and 3.6.
 
great!

that is great, figuring out how to do wear leveling is beyond my capabilities. you regularly amaze me by all the details you have covered :)
can you explain how to choose a value for E2END the default seems to be 0x80 what is the range of values to use. would there be a simple formula to calculate the max leveling for a particular size of data space?
 
Where do you get E2END=0x80 from? Nothing uses that value. Teensy 3.2 is "__MK20DX256__"; E2END=0x7FF.

Look at the datasheet, "6.4.1.4 Reliability specifications". Teensy 3.2 has up to 2kB flexram with 32kB backing flash. You get 175'000 erase cycles with that default configuration. The minimum size supported by the Teensy code is 32 bytes, so you have a 32kB / 32 = 1024 backing ratio for about 13'000'000 cycles.

Teensy 3.6 has 2x the endurance at the same backing ratio and 256kB backing flash.

AN4282 has a description how the EEPROM emulation works.
 
Last edited:
Paul: maybe add this on the EEPROM page under 'write endurance'. If I had known the Teensy did wear leveling, it would have saved me a lot of FRAM chips :( .
 
Where do you get E2END=0x80 from? Nothing uses that value. Teensy 3.2 is "__MK20DX256__"; E2END=0x7FF.

from this location, C:\Arduino\hardware\teensy\cores\teensy3\avr the eeprom.h files is as follows, should i change anything?

#ifndef _AVR_EEPROM_H_
#define _AVR_EEPROM_H_ 1

#include <stddef.h>
#include <stdint.h>

#define E2END 0x80

#endif
 
It seems you have an ancient version of Teensyduino.

i had copied the text from the copy of eeprom.h at the location that was suggested by Paul. this was in fact an ancient installation that is not (i think) being used. i have the latest teensyduino installed and the only location i can install to does have the newer eeprom.h.

when i compile a sketch in the arduino IDE, it lists the newer location as the source for eeprom.h so i guess i could delete the old stuff.

i read the datasheet for the chip but can not make sense out of the description of the eeprom wear leveling.

is it safe to leave the following code? i only need to write 10 bytes of data to eeprom but other programs might need more in the future.

does the wear leveling automatically adjust based on amount of data written? should i even worry about this? i am building a controller for a still and write the temperature setting and heater pwm to eeprom every time the user changes the values so it will be there on powerup.

how many write cycles can i assume with the default? if i want to increase this as much as possible, what E2END should i use for each of the teensy 3 variants

#ifndef _AVR_EEPROM_H_
#define _AVR_EEPROM_H_ 1

#include <stddef.h>
#include <stdint.h>

#include "avr_functions.h"

#if defined(__MK20DX128__) || defined(__MK20DX256__)
#define E2END 0x7FF
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
#define E2END 0xFFF
#elif defined(__MKL26Z64__)
#define E2END 0x7F
#else
#define E2END 0
#endif

#endif
 
Paul: maybe add this on the EEPROM page under 'write endurance'. If I had known the Teensy did wear leveling, it would have saved me a lot of FRAM chips :( .

I've seen it posted around over time - so it is a recurring issues with the sizing and wear leveling/endurance so having it on the web/wiki would be good.

I assumed the 'wear leveling' was a natural fallout of the use of FLASH to back it. It can't be updated in place - so changed data is moved to a new 'page' and made current from there and then the old 'page' can be wiped for re-use.
 
this is why i use i2c eeproms, if the address ever wears out, swap address, but in 3 years my HVAC uses the same first 2 bytes and still does today.
 
If it uses flash in stead of EEPROM, then how relevant is the EEPROM endurance page anway? :confused: It also brings me to wonder what the real endurance of the storage is. E.g. my application is asleep most of the time, only to awake on a pulse input to increment a counter. I need to able to handle around 100k to 1M increments during the lifetime of my application. Because I assumed it could the storage could only handle around 100k writes, I opted for fram.
 
Well I used Everspin MRAM (Magnetoresistive random-access memory) in one of my projects because I was worried about wear leveling.
It's been working for 1 year great @ 40 Mhz SPI and I can shut off the power anytime I want not worried about data corruption.
 
Status
Not open for further replies.
Back
Top