0

When uploading my sketch to my Genuino Micro with the Arduino IDE, everything works perfectly. This is the command issued:

C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/bin/avrdude 
-CC:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/etc/avrdude.conf 
-v -patmega32u4 -cavr109 -PCOM10 -b57600 -D 
-Uflash:w:C:\Users\<user>\AppData\Local\Temp\arduino_build_31080/KeyboardBase.ino.hex:i

All just working like it should (except that the com-port selected is actually COM6, not COM10).

But, if I try to use that exact same command from the command line, avrdude gets stuck for minutes and the arduino is still executing the sketch I've put on it.

C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/bin/avrdude
-CC:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/etc/avrdude.conf 
-v -patmega32u4 -cavr109 -PCOM6 -b57600 -D 
-Uflash:w:C:\Users\<user>\AppData\Local\Temp\arduino_build_31080/KeyboardBase.ino.hex:i

avrdude: Version 6.3, compiled on Dec 16 2016 at 13:33:19
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8/etc/avrdude.conf"

         Using Port                    : COM6
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega32U4
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : butterfly
         Description     : Atmel AppNote AVR109 Boot Loader

Connecting to programmer: .^C

avrdude needs to be run from cmd because I'm building a sketch with partly modified libraries, so it's built and uploaded manually with make.

I already tried running cmd as administrator, using -v -v to get more info, and changing the baud-rate, plugging the Arduino into a different USB port and restarting my machine (the same problem occurred yesterday but I didn't manage to fix it) none of that helped. What else can I try?

  • Are you sure that the com port is 6 instead of 10? If the Arduino IDE doesn't have problems uploading on that port, should you try 10? Or did you just plug it into a different port that time you programmed it – Carrot M Apr 6 '17 at 21:53
  • I recommend reading the "Uploading Code to the Leonardo, Leonardo ETH and Micro" section of arduino.cc/en/Guide/ArduinoLeonardoMicro. There are some special things that need to be done to upload to the ATmega32U4 boards: First the serial port is opened at 1200 baud and then closed, which signals to the firmware that it should reset the microcontroller. After the reset that serial port disappears and the IDE waits for a new port to appear before uploading to that port. Some of this may be done via the IDE rather than solely AVRDUDE. You could try using the Arduino IDE CLI instead. – per1234 Apr 6 '17 at 23:46
  • @CarrotM No, the two commands you see where issued directly after one another, the Arduino was plugged into the exact same port. The IDE displays the Arduino being connected on COM6 in the GUI as well. Trying to use COM10 on cmd leads to a hard fail with a "system couldn't find this path" error message, so it's just the IDEs verbose mode bugging out there. – iFreilicht Apr 7 '17 at 8:54
  • @per1234 that seems to be a good indication of what's going wrong, I'll try that out this evening! – iFreilicht Apr 7 '17 at 8:54
  • Ok, I managed to make it happen. Thanks for your help! – iFreilicht Apr 7 '17 at 19:33
1

@per1234 was correct:

Note that the auto-reset is initiated when the computer opens the serial port at 1200 baud and then closes it

From Arduino.cc

In practise, this means that avrdude first has to be executed like so:

$ avrdude -patmega32u4 -cavr109 -PCOM6 -b1200

Where COM6 is the same serial port the arduino is being displayed on in the Arduino IDE. The exit code of this will not be 0 and display a lot of error messages (even with -q -q), but it does exactly what it should.

After a short delay (in a makefile, use sleep 1), the Arduino will reconnect, ready to be programmed. That's when the actual programming command has to be issued:

$ avrdude -v -patmega32u4 -cavr109 -PCOM10 -b57600 -D -Uflash:w:mysketch.ino.hex:i

Notice that the serial port is now a different one! That's why the Arduino IDE actively searches for a new Arduino instead of using the same serial port set in the "Tools" menu, as I pointed out in my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.