Upload Using Programmer - Terribly Slow and erases EEPROM

I'm working on a sketch that is uploading to a sparkfun pro micro (Leonardo clone / 32u4) and to fit all the features I want I've removed the bootloader from the 32u4. I am using a USBTinyISP programmer board.

I've got a few issues / questions though.

First, using the File menu...Upload Using Programmer option does work, but it is excruciatingly slow. Much slower than using the USB bootloader. When I've used avrdude directly on non-arduino projects, it has always run quite fast. Are the avrdude parameters saved somewhere that I can edit them directly to speed up the burn process?

Second, same scenario, using File -> Upload Using Programmer, the upload erases my EEPROM every time. I have settings saved to EEPROM so they will survive reboots / power cycles / testing but it defeats the purpose if the EEPROM is going to get erased every time I re-upload the sketch. I know this is an option in avrdude, so, same question as above - where can I find the avrdude settings, so I can edit them to preserve EEPROM during uploads?

And finally, on this page: http://arduino.cc/en/Hacking/Programmer it mentions that you can add an upload.using= parameter to your boards.txt file, to set the default for that board to use the programmer. I have set this up in my boards.txt file for this board (created a new entry for it) and set the parameter to usbtiny but the IDE seems to ignore this setting. Is this a case of the documentation not keeping up with the code? Is the syntax different nowadays? Here's the entry from my boards.txt file:

proMicroICSP.name=ICSP ProMicro 3.3
proMicroICSP.upload.protocol=arduino
proMicroICSP.upload.maximum_size=32768
proMicroICSP.upload.using=usbtiny
proMicroICSP.bootloader.low_fuses=0xde
proMicroICSP.bootloader.high_fuses=0xd8
proMicroICSP.bootloader.extended_fuses=0xcb
proMicroICSP.bootloader.path=diskloader
proMicroICSP.bootloader.file=DiskLoader-ProMicro8.hex
proMicroICSP.bootloader.unlock_bits=0x3F
proMicroICSP.bootloader.lock_bits=0x2F
proMicroICSP.build.mcu=atmega32u4
proMicroICSP.build.f_cpu=8000000L
proMicroICSP.build.core=arduino
proMicroICSP.build.variant=proMicro8

Thank you!

Steph:
Second, same scenario, using File -> Upload Using Programmer, the upload erases my EEPROM every time.

That's a fuse setting in the processor. What is the processor exactly, and what are your fuse settings?

Ah so it is! I'm using the ATMega32u4 and it looks like it was set up with the EESAVE bit cleared - the fuses are what are listed in my post above, from the boards.txt file.

I'll change the fuses and that should take care of that problem at least.

Thanks!

Edited to add: I think I figured out why it takes so long to reflash the chip. It is doing the write then it does the verify stage afterwards, even though I have turned off verifications in the preferences panel. (Using the latest version.) I guess that no-verify option only applies when you are uploading via the bootloader, but not when uploading via programmer.

Steph:
the fuses are what are listed in my post above, from the boards.txt file.

If you say so, but the boards.txt file is not definitive.

To be sure do an avrdude -v and see what it actually reports. eg.

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5

The hfuse and lfuse settings match, extended doesn't:

avrdude: safemode: lfuse reads as DE
avrdude: safemode: hfuse reads as D0
avrdude: safemode: efuse reads as FB

In the above listing, I've already changed hfuse so that EESAVE is set - when I changed the fuses I also edited my boards.txt file.

Thanks again!

I finally figured out how to set the boards.txt file so that a single board is uploaded using the programmer while everything else continues to use the bootloader.

On this page: http://arduino.cc/en/Hacking/Programmer it says to add a line to your board definitions with an "upload.using" parameter:

If you would rather use an external programmer for only an individual board, you can edit the boards.txt file in the hardware/ sub-directory of the Arduino application directory. Set the board.upload.using parameter to the identifier of one of the programmers in programmers.txt.

What I have found is that to make this work, you actually have to remove (or comment out) the line with the "upload.protocol" parameter. As per the source code in AvrdudeUploader.java:

    // if no protocol is specified for this board, assume it lacks a 
    // bootloader and upload using the selected programmer.
    if (usingProgrammer || boardPreferences.get("upload.protocol") == null) {

You do not need to add an upload.using parameter at all, the IDE simply uses whatever programmer you have already selected in the GUI. With this change made, clicking the Upload icon automatically compiles the sketch then uploads it with the selected programmer -- exactly what I was looking for.

I don't have a solution for the slow upload, but 2 out of 3 isn't bad. :slight_smile:

Cheers!