user84946: When trying to flash my genuine arduino micro with avrdude from cmd on a Manjaro system I get the infamous error
avrdude: stk500_getsync() attempt x of 10 ...
Im adding this post to the many other that ask about this error because all of them are trying to use the IDE to flash the arduino, whereas I can use it no problem on both Linux and Windows, but when using avrdude from cmd on Linux I get this error. This confirms that the board is fine and there are no shorts on the reset pin or any other possible physical cause of this issue, something appears to be wrong in the avrdude configuration.
This is my Makefile:
default: build

build:
    avr-gcc -mmcu=atmega32u4 main.c -o main

flash:  
    avr-objcopy -O ihex -R .eeprom main main.hex
    avrdude -F -V -c arduino -p m32u4 -P /dev/ttyACM0 -b 115200 -U flash:w:main.hex

Can you suggest anyway to fix this?
EDIT:
Problem Solved!
The error was in the -c parameter, for the atmega 32u4 it's supposed to be avr109 and not arduino.

user4143: There are two common ways of resetting an Arduino into the bootloader:

For UART based boards (Uno, Mega2560 etc) just opening the port resets the board
For USB based boards (Micro, etc with the 32u4 chip) you have to manually tell it to reset

Yours is option 2 - unless you tell it to reset the board it won't do anything. The IDE normally handles that for you.
But it's simple: just cause the CDC/ACM port to be opened at 1200 baud and closed again. The simplest method is to use stty to do it for you:
stty -F /dev/ttyACM0 speed 1200

You should find that it then resets the board. Adding a short delay to allow the USB to reset would be good too. So your whole programming routine could look something like:
flash:  
    avr-objcopy -O ihex -R .eeprom main main.hex
    stty -F /dev/ttyACM0 speed 1200
    sleep 1
    avrdude -F -V -c arduino -p m32u4 -P /dev/ttyACM0 -b 115200 -U flash:w:main.hex

In Makefiles I find it useful to set the port as an overridable variable:
PORT?=/dev/ttyACM0

Then use ${PORT} everywhere instead of /dev/ttyACM0 - then you can use make PORT=/dev/ttyACM1 if you need to without having to edit the Makefile. Great if you have multiple boards.

84946: <p>When trying to flash my genuine arduino micro with avrdude from cmd on a Manjaro system I get the infamous error</p>
<p><code>avrdude: stk500_getsync() attempt x of 10 ...</code></p>
<p>Im adding this post to the many other that ask about this error because all of them are trying to use the IDE to flash the arduino, whereas I can use it no problem on both Linux and Windows, but when using avrdude from cmd on Linux I get this error. This confirms that the board is fine and there are no shorts on the reset pin or any other possible physical cause of this issue, something appears to be wrong in the avrdude configuration.</p>
<p>This is my Makefile:</p>
<pre><code>default: build

build:
    avr-gcc -mmcu=atmega32u4 main.c -o main

flash:  
    avr-objcopy -O ihex -R .eeprom main main.hex
    avrdude -F -V -c arduino -p m32u4 -P /dev/ttyACM0 -b 115200 -U flash:w:main.hex
</code></pre>
<p>Can you suggest anyway to fix this?</p>
<p>EDIT:
Problem Solved!</p>
<p>The error was in the <code>-c</code> parameter, for the atmega 32u4 it's supposed to be <code>avr109</code> and not <code>arduino</code>.</p>
 4143: <p>There are two common ways of resetting an Arduino into the bootloader:</p>
<ol>
<li>For UART based boards (Uno, Mega2560 etc) just opening the port resets the board</li>
<li>For USB based boards (Micro, etc with the 32u4 chip) you have to manually tell it to reset</li>
</ol>
<p>Yours is option 2 - unless you tell it to reset the board it won't do anything. The IDE normally handles that for you.</p>
<p>But it's simple: just cause the CDC/ACM port to be opened at 1200 baud and closed again. The simplest method is to use <code>stty</code> to do it for you:</p>
<pre class="lang-bash prettyprint-override"><code>stty -F /dev/ttyACM0 speed 1200
</code></pre>
<p>You should find that it then resets the board. Adding a short delay to allow the USB to reset would be good too. So your whole programming routine could look something like:</p>
<pre class="lang-bash prettyprint-override"><code>flash:  
    avr-objcopy -O ihex -R .eeprom main main.hex
    stty -F /dev/ttyACM0 speed 1200
    sleep 1
    avrdude -F -V -c arduino -p m32u4 -P /dev/ttyACM0 -b 115200 -U flash:w:main.hex
</code></pre>
<p>In Makefiles I find it useful to set the port as an overridable variable:</p>
<pre class="lang-bash prettyprint-override"><code>PORT?=/dev/ttyACM0
</code></pre>
<p>Then use <code>${PORT}</code> everywhere instead of <code>/dev/ttyACM0</code> - then you can use <code>make PORT=/dev/ttyACM1</code> if you need to without having to edit the Makefile. Great if you have multiple boards.</p>
