Monday 19 July 2010

Using avrdude

You have to install avrdude first before being able to enjoy using it. Winavr usually comes packaged with avrdude. Then under windows ,open the command window and type in avrdude, you should get the following list of what avrdude can do.
















To get a list of supported programmers e.g. dasa, dapa, stk500 e.t.c., type in avrdude -c asdf
To get a list of parts supported by avrdude, type in avrdude -c avrisp. Thats the list of chips that avrdude knows about. Almost all of them are ISP programmable.

-P <port> tells avrdude where to look for your programmer
-U <memtype>:r/w/v:<filename>[:format]: tells avrdude how to put data on the chip
<memtype> can be flash, eeprom, hfuse(high fuse), lfuse (lowfuse), efuse (extended fuse).
r/w/v can be read, write or verify
<filename> the input (writing or verifying) or output file (reading)
[:format] optional, the format of the file. You can leave this off for writing, but for reading use i for Intel Hex (the prevailing standard)

e.g to read the low fuse into a file use the command -U lfuse:r:lfusefile.hex:i
to write a file called bobo.hex to the flash use the command -U flash:w:bobo.hex
to verify a file called mystuff.eep from the eeprom use the command
-U eeprom:v:mystuff.eep

Example:
In the command window type in avrdude -c usbtiny -p attiny2313 -U flash:w:test_leds.hex
avrdude should go through the following steps:
1. initializing the programmer (you won't see this if it works)
2. initializing the AVR device and making sure it is ready for instructions
3. reading the device signature (0x1e910a) which confirms that the chip you specified in the command line (attiny2313) is in fact the chip the programmer is connected to
4. erasing the chip
5. reading the file and verifying it is a valid file
6. writing the flash
7. verifying the flash

















Burning fuses
Fuse is a separate chunk of flash that is not written to when you update the firmware. They define things like clock speed, crystal type, whether JTAG is enabled, what the brownout (minimum voltage) level is, e.t.c. Setting the fuses incorrectly may 'brick' the chip e.g. you may disable future programming or make it so the chip is expecting an external crystal when there isn't one.
To program the fuses use:
-U lfuse:w:<0xhh>:m
-U hfuse:w:<0xhh>:m
-U efuse:w:<0xhh>:m
where <0xhh> is the desired fuse value in hex. But first you will want to calculate the fuse values using the very convenient AVR fuse calculator.
Triple check the fuse values, check again to make sure you aren't disabling ISP programming or the reset pin or setting the clock speed to 32kHz, then verify again that you have the correct chip for calculation. Finally you can try writing them to the chip.
If the programmer is not connected properly to the chip you will get the following message:










This simply means that the programmer could not 'talk' to the chip. 99% of the time it is a problem with wiring. Check that the chip is powered, plugged properly to the programmer, the programming cables are plugged in properly e.t.c. If you are using a 'simple' programmer such as a serial or parallel port bitbang programmer it could mean the programmer is at fault.

For most microcontrollers, the .hex files are not cross-compatible. This causes a signature failure. Once the signature is different from the expected one it stops. For example try to run this command avrdude -c usbtiny -p atmega8 -U flash:w:test_leds.hex









It stops at step 2. This is because code that is compiled for an attiny2313 wont run on an atmega8.

No comments:

Post a Comment