by on
Dorkbot

I generally dont use my dragon. Its notoriously fragile and complicated compared to my trusty avrisp-mk2. However somewhere between loaning it out and taking it to dorkbot meetings my mark2 has gone awol for several months now.
bootloader programming setup.
And since I am stuck using the dragon I might as well share a little.

Avrdude.

If you are going to be building or burning bootloaders you need to get a toolchain for your platform. On the mac I recommend that you get the latest CrossPack-AVR from objective devlopment (formerly AvrMacPack). It will have a complete set of tools to program the avr which is kept in sync with winavr which is the definitive tool-chain. Included in this is Jeorg Wunch’s avrdude the definitive open source avr programmer.

Asking the tools.

To get avrdude to tell you about what programers are avaliable you tell it to use something you know it doesnt support.

$ avrdude -c junk

avrdude: Can't find programmer id "junk"

Valid programmers are:
c2n232i  = ...blah blah blah ...
dragon_dw = Atmel AVR Dragon in debugWire mode [/usr/local/CrossPack-AVR-20090415/etc/avrdude.conf:540]
dragon_hvsp = Atmel AVR Dragon in HVSP mode  [/usr/local/CrossPack-AVR-20090415/etc/avrdude.conf:532]
dragon_pp = Atmel AVR Dragon in PP mode    [/usr/local/CrossPack-AVR-20090415/etc/avrdude.conf:524]
dragon_isp = Atmel AVR Dragon in ISP mode   [/usr/local/CrossPack-AVR-20090415/etc/avrdude.conf:516]
dragon_jtag = Atmel AVR Dragon in JTAG mode  [/usr/local/CrossPack-AVR-20090415/etc/avrdude.conf:508]
...

We can see here that there are 5 entries listed as dragon entries; one for each of the 5 modes which is supported. In this case I am only going to use the isp mode (dragon_isp).

Burning bootloaders

Most AVR parts have two different programming areas and a set of fuses and locks to configure how the chip is to behave. In order to program the bootloader we need to set the fuses to unlock that area and while we are there we want to set some other fuses telling it to use the external crystal, the size of the boot section and to boot to the bootloader so we use the following command line.

$avrdude  -pm168 -cdragon_isp -Pusb -e 
-Ulock:w:0x3F:m -Uefuse:w:0x00:m -Uhfuse:w:0xdd:m -Ulfuse:w:0xff:m

“-cdragon_isp” says to use the dragons 6 pin isp header. the “-Uxxxx:w:0xNN:m” writes the fuse values and the -e tells avrdude to erase the chip first. Erasing the chip is the only way to unset most lock and many flag bits.

How did I get this particular set of fuses? I asked the tools — I went to the arduino and I told it to burn a bootloader and watched what it tried to do. A careful read of the datasheet will get you to the same place and there are also several “avr fuse calculator” sites as well. In this particular case I “cheated”.

Now that the boot section has been unlocked, we burn the bootloader and while we do this we also re-lock the boot section. This prevents the bootloader from getting overwritten untill we mean it.

$avrdude  -v -v -v -v -pm168 -cdragon_isp -Pusb 
-Uflash:w:ADABOOT_8h13_16MHZ.hex:i 
-Ulock:w:0x0F:m

And were done (except for the part where you use/test it)

And if you wanted to do this more than once you can make it into a make file like the one attached here (http://dorkbotpdx.org/files/ADABOOT.zip)

One thing I did notice with OSX and avrdude with the dragon is that osx doesn’t let avrdude see the dragon if called immediately after you are done with it. In the makefile I resolve this by sleeping for a few seconds between the two steps listed above.

See also….

Leave a Reply

  • (will not be published)