EEMEM directive and EEPROM storage in .HEX files

Great to see a fix turning up in SVN. Yay!

Ladyada fixed the bootloader side of things for the Atmega328 chips she's currently sending out, so Atmega328-based boards will be among the first that eventually also support uploading to the EEPROM area.

For now, at least we can use the EEMEM directive, without Arduino creating .hex files that are too big.

If you can figure out a way to get avr-objcopy to create the .eep files without generating a warning if they're empty, that would be even better. Otherwise, you'll probably need to extract them manually on the command line.

Sorry I did not catch that before. This seems to work for me:

--- /app/Compiler.java      Mon Oct 13 20:04:37 2008
+++ /app/Compiler.java      Mon Oct 13 20:02:31 2008
@@ -215,6 +215,7 @@
       commandObjcopy.set(3, "-j");
       commandObjcopy.add(".eeprom");
       commandObjcopy.add("--set-section-flags=.eeprom=alloc,load");
+      commandObjcopy.add("--no-change-warnings");
       commandObjcopy.add("--change-section-lma");
       commandObjcopy.add(".eeprom=0");
       commandObjcopy.add(buildPath + File.separator + sketch.name + ".elf");

Edit: This is (obviously) against revision 513, not 514.

Great, that seems to work. I'm generating the .eep files again. Do you think it makes sense to upload the EEPROM data with avrdude on every upload?

Trying to upload anything to the eeprom section on a non-fixed bootloader always results in an upload error (unless you want to turn off verification). So at the very least uploading the .eep section should probably be an option that lives in boards.txt.

Come to think of it, that could be a very good solution, because for example all 328s that Ladyada is shipping currently have the fix in place, so they are eeprom-capable. Atmega328-based Arduinos would have a different entry in boards.txt. And if a user wants to prevent his/her eeprom section from getting overwritten, he/she can edit the boards.txt file to disable the upload. One could even make two copies of a board config; one with and one without eeprom uploads.

Sounds like a good plan. I'll add it (at some point). We will be switching to the updated bootloader as well.

Can somebody summarize the status of this thread? Is the EEMEM directive now supported and .eep upload working with the bootloader?

Since the 0013 release and newer (or was it 0012?), .eep files are created, but not uploaded. You can upload them manually using avrdude.

should I create a patch that allows manual upload of .eep files out of the IDE? Can they be uploaded by the bootloader or only via isp programmer? Or maybe the IDE must upload the .eep file if the size is not zero or at least ask the user in this case?

Maybe users want to read the eeprom and have a look at the contents in the Editor as well?

Or is the eeprom a topic for professional users only and they all know how to handle avrdude?

Here’s a patch that should let you specify in boards.txt whether or not the eep file gets uploaded.

Index: AvrdudeUploader.java
===================================================================
--- AvrdudeUploader.java      (revision 540)
+++ AvrdudeUploader.java      (working copy)
@@ -49,6 +49,10 @@
     } else {
       Collection params = getProgrammerCommands(uploadUsing);
       params.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i");
+      String eepFile = buildPath + File.separator + className + ".eep";
+      Boolean uploadEEPROM = Preferences.getBoolean("boards." + Preferences.get("board") + ".upload.eeprom_section");
+      if (uploadEEPROM && (new File(eepFile)).exists())
+        params.add("-Ueeprom:w:" + eepFile + ":i");
       return avrdude(params);
     }
   }
@@ -67,6 +71,10 @@
       "-b" + Preferences.getInteger("boards." + Preferences.get("board") + ".upload.speed"));
     commandDownloader.add("-D"); // don't erase
     commandDownloader.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i");
+    String eepFile = buildPath + File.separator + className + ".eep";
+    Boolean uploadEEPROM = Preferences.getBoolean("boards." + Preferences.get("board") + ".upload.eeprom_section");
+    if (uploadEEPROM && (new File(eepFile)).exists())
+      commandDownloader.add("-Ueeprom:w:" + eepFile + ":i");
 
     if (Preferences.get("boards." + Preferences.get("board") + ".upload.disable_flushing") == null ||
         Preferences.getBoolean("boards." + Preferences.get("board") + ".upload.disable_flushing") == false) {

The reason not to turn this option on for all boards is that there is a bug in most 168-based bootloaders out there that will make the eep uploading process fail. This bug was fixed with the 328-compatible bootloader recently, so all 328-based arduinos should be fine.

ok, thank you.

I will test it later and combine it with my local AvrdudeUploader modifications.