avrdude 5.10, arduino mega 2560, command line uploading

Note: The following probably applies to the arduino UNO as well, as it also uses an onboard atmega 8u2, rather than the old raw serial converter.

Part 1 of probably many. I’ve inherited some arduino code, targetting the quite new mega2560 boards. You know, the ones that include an onboard atmega8u2, rather than the original old serial adapters. In many ways, this is a welcome step into the future. Anyway, this place doesn’t even have a regular AVR ISP programmer, and with the onboard real usb, the code running on the 8u2 is actually effectively an AVR ISP programmer itself, talking the stk500 protocol.

I am trying to move some of this code slowly out of the arduino IDE, and towards a more standard shared tree of c/c++. I have mostly succeeded in building plain hex files from the command line, based on arduino libraries (for things like LiquidCrystal and Ethernet and so on) but was having problems getting them to program. By editing arduino’s “preferences.txt” and adding “upload.verbose=true” I could see that when programming from the arduino IDE, it was using a private patched version of avrdude (5.4-arduino) with the programmer type of stk500v2, and that it was issuing a reset, via some sort of DTR toggle…


c:\tools\arduino-022\hardware/tools/avr/bin/avrdude -CC:\tools\arduino-022\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -cstk500v2 -p atmega2560 -P COM5 -b 115200
... version stuff ...
Using Programmer: stk500v2
Overriding Baud Rate: 115200
avrdude: ser_open(): setting dtr
avrdude: Send: . [1b] [20] . [00] . [03] . [0e] . [11] . [01] . [01] ' [27]

Ok, so now I had enough to try and run it myself, using avrdude 5.10, as comes with recent versions of WinAVR


C:\Users\karlp>avrdude.exe -p atmega2560 -P COM5 -c stk500v2 -v -U lfuse:r:-:h -b 115200
---snip---
avrdude.exe: stk500_2_ReceiveMessage(): timeout
avrdude.exe: stk500_2_ReceiveMessage(): timeout

But, as you can see, this just timed out. Looking at the LEDs, I could see that the board wasn’t getting magically reset. With a bit of reading and searching, I found out that avrdude added a way of resetting the board, if you use the programmer type of “arduino”


Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude.exe: Send: 0 [30] [20]
avrdude.exe: Send: 0 [30] [20]
avrdude.exe: Send: 0 [30] [20]

Interesting, following the lights on the board, I could see that this was now resetting properly, but clearly, those were not the right commands. It seems that the “arduino” programmer type, is set up to talk to the bootloader on the atmega328 of the prior versions of arduino, the Duemilanove and so on, that still had a direct USB-serial bridge, from the FTDI chip. So, if the “arduino” programmer does the reset, but the wrong protocol, looks like I’ll have to reset it myself.

I finally tried holding reset on the board, issuing the command with the programmer of “stk500v2” and immediately releasing reset. Presto!


C:\Users\karlp>avrdude.exe -p atmega2560 -P COM5 -c stk500v2 -v -b 115200
... more snipped ....
Programmer Type : STK500V2
Description : Atmel STK500 Version 2.x firmware
Programmer Model: AVRISP
Hardware Version: 15
Firmware Version Master : 2.10
Vtarget : 0.0 V
SCK period : 118.3 us

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude.exe: Device signature = 0x1e9801
... more snipped ...

Hooray! we’re working from the command line again. Now, if only the arduino gang’s pile of extra patches for avrdude would keep making their way back into mainline. It seems they don’t play well with others :(

Leave a comment ?

20 Comments.

  1. Thanks ! But why they are doing this, this way will prevent automation :(

  2. You can get the avr tool chain to do the reset itself by editing avrdude.conf and adding (in the Atmel STK500 Version 2.x firmware section)

    reset = 4;

    which pulses DTR.

  3. After a week of headbanging I found this.

    I upgraded to Eclipse Indigo and Arduino 1.0 (avrdude 5.11) and found I could not upload to mega2560.

    This suggestion works – thanks

  4. Justin, could you tell us more, I’m very interested into your solution, but could not get it working.

  5. Justin solution don’t work for me

    But it’s work great with “wiring” programmer. The diffenrce is here:

    avrdude.exe: wiring_open(): releasing DTR/RTS
    avrdude.exe: wiring_open(): asserting DTR/RTS

    Avrdude 5.11
    Arduino Mega2560 R3

  6. Use -c wiring in stead of -c stk500v2
    than it will work!

  7. Only with a new enough version of avrdude :) With 5.10, as in the title of this post, the “wiring” programmer type doesn’t exist.

  8. Thanks for the -cwiring tip! I was searching all over on how to upload my hex to my mega using avrdude

  9. Does someone have a sample avrdude.conf patch? The config file is so complicated there…there are tons of references to stk500v2…I’m trying to get the upload command within the arduino app/gui to work.

  10. Yes. That’s work by using -cwiring.
    Using avrdude 5.11 (the one in the zip package from arduino)
    But it is a mess !
    Why the arduino trace says : -cstk500v2
    And when we copy/paste we need to change this point to make avrdude working !?

  11. Works for me. I used avrdude 5.11 with command line:

    avrdude.exe -V -F avrdude.conf -p atmega2560 -c wiring -P COM9 flash:w:blink.cpp.hex -vvvv

    In my avrdude.conf file I added the ‘reset = 4’ line:

    id = “wiring”;
    desc = “Wiring”;
    type = wiring;
    reset = 4;

  12. Hi guys !

    I patched my avrdude.conf file with a reset information. Unfortunately, the problem is always present …

  13. Just to give you my modification:

    programmer
    id = “wiring”;
    desc = “Wiring”;
    type = wiring;
    reset = 4;
    ;

  14. My “Eleven” by Freetronics version of Arduino IDE refuses to upload and gives me the 115300avrdude.exe write error. I don’t know C/C++ well enough to understand the above help. Could someone give me what to put into my Windows 7 PC to make it work?
    Thanks.

  15. Bear in mind this post was written more than three years ago. Both arduino and avrdude have had multiple updates since then.

  16. Krishna Mohan Bandi

    Restarted the machine.

    Arduino Mega2560 with com3 (will be different for you) is selected.

    Selected “ArduinoISP” (not ArduinoasISP)

    Open sketch from “ArduinoISP” examples

    Upload ….

    Next change Board settings to “ATTiny85″, COM3, 1 MHz

    On a command prompt, run this

    C:\Program Files\Arduino\hardware\tools\avr\bin>avrdude.exe -C”C:\Program Files\Arduino\hardware\tools\avr\etc\avrdude.conf” -p atmega2560 -P COM3 -c Wiring -v
    -b 115200

    After running this my Blink was uploaded to ATTiny85 (from menu directly)

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Trackbacks and Pingbacks: