AVR Dragon Write Arduino Bootloader On Linux To ATMega328p

This article will contain a small summary on how to write an arduino bootloader to an AVR ATMega328p on Debian linux using the AVR Dragon. <a id="more"></a><a id="more-700"></a>

Get an AVR Dragon

I got mine from watterott.com.

Solder a 40pin ZIF socket to your AVR Dragon as described here

3. Wire the pins using the following diagram.

pinout dw

Provide a external oscillator to your avr chip. Just connect connect pin 9 and 10 (XTAL1,XTAL2) to an 16 MHz crystal.

Avr atmega328 pins

Each of the two pins of the the quartz crystal should be connected to an 22pF capacitor. The capacitor then connects to GND of the a avr dragon Ext_Power connector.

avrdragon arduino

avrdragon arduino top

I got the following error when trying to program the chip when using no external oscillator:

$  make atmega328_isp  ISPTOOL=dragon_isp
avrdude  -c dragon_isp -p atmega328p -P usb -b 115200 -e -u -U lock:w:0x3f:m -U efuse:w:0x05:m -U hfuse:w:0xDE:m -U lfuse:w:0xFF:m
avrdude: jtagmkII_setparm(): bad response to set parameter command: RSP_FAILED
avrdude: jtagmkII_getsync(): ISP activation failed, trying debugWire
avrdude: jtagmkII_setparm(): bad response to set parameter command: RSP_DEBUGWIRE_SYNC_FAILED
avrdude: failed to sync with the AVR Dragon in ISP mode
avrdude: jtagmkII_close(): timeout/error communicating with programmer (status -1)

avrdude done.  Thank you.

make: *** [isp] Error 1

4. Create the following udev file within /etc/udev/rules.d to enable AVR Dragon detection and restart your udev (or force a reload).

z60_avarice.rules:

SUBSYSTEM!="usb_device", ACTION!="add", GOTO="avarice_end"

# Atmel Corp. JTAG ICE mkII
SYSFS{idVendor}=="03eb", SYSFS{idProduct}=="2103", MODE="660", GROUP="dialout"

# Atmel Corp. AVR Dragon
SYSFS{idVendor}=="03eb", SYSFS{idProduct}=="2107", MODE="660", GROUP="dialout"

LABEL="avarice_end"

You can validate your rule by examining the output of the lsusb command:

   Bus 007 Device 008: ID 03eb:2107 Atmel Corp. AVR Dragon

5. Install avrdude

apt-get install avrdude

6. Get the arduino bootloader and use avrdude to write it

Somehow the bootloaders which i found in the Arduino SDK (0022) (eg. arduino-0022/hardware/arduino/bootloaders/atmega) did not work properly for my Arduino UNO Board. I could not push sketches to the board when using those bootloaders.

The optiboot bootloaders on the otherhand worked for me. They can be found here: arduino-0022/hardware/arduino/bootloaders/optiboot.

You have two options:

  • a) Use the build script provided. The buildscript within the optiboot folder is faulty since it contains comments after the fusebit settings. Those comments introduce a whitespace which messes up the avrdude command. You can also get an updated version of <a href="http://code.google.com/p/optiboot/">optiboot here</a>.

make atmega328_isp  ISPTOOL=dragon_isp

Possible issues: The following error was caused by avrdude since the avr dragon was not directly ready to accept new commands after the fusebits have been set. You can just call the avrdude command manually. Perhaps there is a avrdude setting which fixes this issue.

avrdude  -c dragon_isp -p atmega328p -P usb -b 115200 -U flash:w:optiboot_atmega328.hex -U lock:w:0x2f:m
avrdude: usbdev_open(): did not find any USB device "usb"
make: *** [isp] Error 1
  • b) Call the avrdude command manually:

avrdude  -c dragon_isp -p atmega328p -P usb -b 115200 -e -u -U lock:w:0x3f:m -U efuse:w:0x05:m -U hfuse:w:0xDE:m -U lfuse:w:0xFF:m
avrdude  -c dragon_isp -p atmega328p -P usb -b 115200 -U flash:w:optiboot_atmega328.hex -U lock:w:0x2f:m

7. Test your arduino chip

I just removed the ATMega328p from the dragon and placed it in an arduino uno socket to test it.