Go Down

Topic: Arduino EEPROM retains old data even after flashing with a new program (Read 3253 times) previous topic - next topic

electrophile

I have a custom 5V 16Mhz Arduino Uno (a breadboard Uno of sorts) that runs the grbl firmware. After the initial flashing I can see all the settings (through the serial monitor) and everything works. However, if I make any changes to the firmware files and re-flash it, I can see that the old settings values have not been replaced with the new ones. I can only assume that these values are in the EEPROM and are not being erased on every re-flash cycle. I then tried the eeprom_clear program from Examples in the Arduino IDE and then re-flashed with the new firmware settings, after which I can see the new settings values.

I did some digging and found that the EESAVE fuse is responsible for this. However the Uno does have this fuse bit unprogrammed (set to 1). Why then am I able to see the old EEPROM settings and have to explicitly run an eeprom clear program before re-flashing with the updated firmware?


Jiggy-Ninja

The standard flash with the Arduino bootloader does not flash the EEPROM. In fact, I believe the Optiboot variant loaded onto them does not support the EEPROM commands at all. Any changes to the EEPROM must be happening in your sketch.

The EESAV fuse only effects the function of the Chip Erase command. It is impossible for this feature to be used when uploading with the bootloader, because that would erase the bootloader as well as the old program.

Did you write your sketch to detect uninitialized memory and write the settings to it?
Hackaday: https://hackaday.io/MarkRD
Advanced C++ Techniques: https://forum.arduino.cc/index.php?topic=493075.0

electrophile

The EESAV fuse only effects the function of the Chip Erase command. It is impossible for this feature to be used when uploading with the bootloader, because that would erase the bootloader as well as the old program.
Yes the program is writing values to the EEPROM. Isn't the Arduino IDE supposed to clear the eeprom AND the flash memory when a new program is uploaded? Doesn't the -e option of avrdude do that?

DrAzzy

This is correct behavior - uploading an new sketch doesn't trash anything you might have in the eeprom.

The bootloader used does not support clearing the eeprom - it won't fit in 512 bytes of you add that functionality - so -e or no -e, uploading via opinion won't clear the eeprom. I'm not at my desk so I can't confirm, but looking at platform.txt i don't think -e is used for normal uploads.

Chip erase is an ICSP command anyway - it clears the entire flash including the bootloader (note that it can only be executed via ICSP or hvsp, not through bootloader)
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy


electrophile

This is correct behavior - uploading an new sketch doesn't trash anything you might have in the eeprom.

The bootloader used does not support clearing the eeprom - it won't fit in 512 bytes of you add that functionality - so -e or no -e, uploading via opinion won't clear the eeprom. I'm not at my desk so I can't confirm, but looking at platform.txt i don't think -e is used for normal uploads.

Chip erase is an ICSP command anyway - it clears the entire flash including the bootloader (note that it can only be executed via ICSP or hvsp, not through bootloader)
Thanks! This helps.

Go Up