6

I'm finishing an application which will use some non-volatile parameters stored on an AVR Atmega644P EEPROM. The initial EEPROM values were generated using the EEMEM attribute (like described on this tutorial) and burned to the AVR using avrdude like this:

avrdude -c usbasp -p atmega644p -u -U eeprom:w:application.eep

The application runs and retrieves the correct EEPROM values, but if I upgrade just the firmware with avrdude -c usbasp -p atmega644p -u -U flash:w:application.hex the EEPROM seems to be erased too, for the values read are "all ones" instead of the previously loaded ones. So I ask, is there any way to burn the firmware to flash but avoid the EEPROM to be erased (using avrdude)?

Claudio
  • 396
  • 5
  • 13

2 Answers2

11

Before reflashing any Atmel AVR MCU you need to erase it. Erase procedure by default clears FLASH, EEPROM and lock bits. There are 2 ways to solve your issue:

  1. Read EEPROM, erase all, program all including your backed-up EEPROM.
  2. Set EESAVE fuse bit. In this case EEPROM will not be erased during Erase procedure. But you will need to clear this flag some day later if you want to clear and/or reflash EEPROM.
x4mer
  • 986
  • 1
  • 9
  • 13
  • This issue is not specific to avrdude, but to all Atmel AVR MCU programmers. – x4mer Feb 06 '14 at 14:00
  • So if I ever have to update the eeprom values from the running application using, say, the `eeprom_update_byte` function, I can't have the EESAVE fuse set? – Claudio Feb 06 '14 at 14:12
  • 5
    EESAVE fuse only relates to external MCU programming. Your code is not affected in any way, feel free to write whatever you want to EEPROM. – x4mer Feb 06 '14 at 14:21
  • 5
    Just a useful update: I just tested and when the EESAVE fuse is set it does preserve the EEPROM on a flash erase/program, but it doesn't block you from burning a new EEPROM file either. – Claudio Feb 06 '14 at 18:19
1

It worked for me on an ATtiny84 using PlatformIO as IDE with the following AVRDUDE command

upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

where $UPLOAD_FLAGS was set by the platformio.ini config file.

My EEPROM values are retailed during new program flash but I can still programmatically read and write to EEPROM - happy days!