# Burning arduino bootloader with avrdude and AVR dragon on ATmega32U4 failing

I am attempting to burn a bootloader on a ATmega32U4 aka. Arduino Micro which is not succeeding. I am using a AVR Dragon with ISP interface.

avrdude -c dragon_isp -p m32u4 -P usb -U flash:w:Caterina-Micro.hex -U lfuse:w:0xff:m -U hfuse:w:0xd8:m -U efuse:w:0xcb:m -U lock:w:0x2f:m


When this commando is executed i get bunch of following errors:

savrdude: stk500v2_jtagmkII_recv(): failed


OS: OSX Mavericks

avrdude: v6.1

UPDATE

When i set the -B flag with 200 it clearly starts burning the bootloader, but is this due to a hardware flaw? It takes more than 3 minutes to burn.

avrdude -c dragon_isp -p m32u4 -P usb -U flash:w:Caterina-Micro.hex -U lfuse:w:0xff:m -U hfuse:w:0xd8:m -U efuse:w:0xcb:m -U lock:w:0x2f:m -v -B 1000
avrdude: Device signature = 0x000100
avrdude: Expected signature for ATmega32U4 is 1E 95 87
Double check chip, or use -F to override this check.


Or:

avrdude -c dragon_isp -p m32u4 -B 1000

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.26s

avrdude: Device signature = 0x1e9587
avrdude: safemode: Verify error - unable to read efuse properly. Programmer may not be reliable.
avrdude: safemode: To protect your AVR the programming will be aborted


And:

avrdude -c dragon_isp -p m32u4 -B 200000

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 2.46s

avrdude: Device signature = 0x1e9587
avrdude: safemode: Fuses OK (E:CB, H:D8, L:FF)
avrdude done.  Thank you.


When used in ISP mode, the AVR Dragon behaves similar to an AVRISP mkII (or JTAG ICE mkII in ISP mode), so all device-specific comments will apply there. In particular, the Dragon starts out with a rather fast ISP clock frequency, so the -B bitclock option might be required to achieve a stable ISP communication.

http://linux.die.net/man/1/avrdude

       -B bitclock
Specify the bit clock period for the JTAG interface or the ISP clock (JTAG ICE only).  The
value is a floating-point number in microseconds.  The default value of the JTAG ICE results
in about 1 microsecond bit clock period, suitable for target MCUs running at 4 MHz clock and
above.  Unlike certain parameters in the STK500, the JTAG ICE resets all its parameters to
default values when the programming software signs off from the ICE, so for MCUs running at
lower clock speeds, this parameter must be specified on the command-line.  You can use the
'default_bitclock' keyword in your \${HOME}/.avrduderc file to assign a default value to keep
from having to specify this option on every invocation.


http://www.nongnu.org/avrdude/user-manual/avrdude_4.html

It sounds like the Dragon is sending data faster over ISP than the ATmega can manage. This is quite likely when you are running the ATmega from the default clock source. The -B parameter is the way to solve these issues.

The device is shipped with Low Power Crystal Oscillator (8.0 - 16MHz) enabled and with the fuse CKDIV8 programmed, resulting in 1.0MHz system clock with an 8MHz crystal.

• I cant really figure out what the bitclock should be set to? I am using a 16MHz external oscillator. – JavaCake Feb 10 '15 at 13:43
• See my changes. If you didn't change the fuses, your AVR is clocked at 16 / 8 = 2 MHz. Check the datasheet for maximum SPI rate at a given system clock. – jippie Feb 10 '15 at 13:47
• I made a trial and error by only reading, and i hat to go somewhere near 200000 before it was able to read the device signature correct and check the fuses. – JavaCake Feb 10 '15 at 13:51
• See my last update. If i excecute the commando again afterwards it fails. – JavaCake Feb 10 '15 at 13:52
• I don't have experience with specific numbers for the bitclock. So I can't help in sizing @JavaCake – jippie Feb 10 '15 at 13:52