AVR/avrdude

From OmegaV-wiki
Jump to: navigation, search

Contents

avrdude, AVR MCU programmer

avrdude is a piece of software for programming AVR µCs. It is mostly used under Linux, but can also be used under Windows - and binaries are distributed as a part of the WinAVR package. The Windows port should have identical functionality, but more information about this can be found in avrdude's manual.

Installing avrdude


Simple usage

STK500

  1. Connect your STK500 to the COM-port, and power it on
  2. Find out what model your microcontroller is, and find out what avrdude calls it
    • To se a full list go here, or you can run: avrdude -c stk500
    • When you find your model, e.g. ATMEGA8515, write down what it says to the left of your model (m8515)
    • Example of a line output by avrdude -c stk500: m8515 = ATMEGA8515 [/etc/avrdude.conf:5385]
    • m8515 is the avrdude model number, ATMEGA8515 is the Atmel model number. The part in the brackets should be ignored.
  3. Find out what com-port your STK500 is connected to, and what the device name is.
    • The com-port is likely to be something like /dev/ttyS* , where * is a number of your com-port, to find out which com-ports you have you can run: ls /dev/ttyS*
    • If you are using a usb to rs232 converter its likely that its path is /dev/ttyUSB0, you can run: dmesg right after you connect the converter to find out where its attached, look for something like pl2303 converter now attached to ttyUSB0
  4. Flash your compiled image using: avrdude -c stk500 -p m8515 -P /dev/SOMETHING -U flash:w:rom.hex
    • Note: Replace m8515 with the part number you find in step 2, /dev/SOMETHING with what you found in step 3 and rom.hex with the name of your image.

AVR Dragon

ISP

  1. Connect your AVR Dragon to the usb port and the Dragon should power on.
  2. Power up your device and connect it to the Dragons ISP header if you haven't already done so.
  3. Find out what model your microcontroller is, and find out what avrdude calls it
    • To se a full list go here, or you can run: avrdude -c dragon_isp
    • When you find your model, e.g. ATMEGA8515, write down what it says to the left of your model (m8515)
    • Example of a line output by avrdude -c stk500: m8515 = ATMEGA8515 [/etc/avrdude.conf:5385]
    • m8515 is the avrdude model number, ATMEGA8515 is the Atmel model number. The part in the brackets should be ignored.
  4. Flash your compiled image using: avrdude -c dragon_isp -p m8515 -P usb -U flash:w:rom.hex
    • You might need to run this as root/sudo because of some permission issues.
    • Note: Replace m8515 with the part number you find in step 2, /dev/SOMETHING with what you found in step 3 and rom.hex with the name of your image.

JTAG

  1. Connect your AVR Dragon to the usb port and the Dragon should power on.
  2. Power up your device and connect it to the Dragons JTAG header if you haven't already done so.
  3. Find out what model your microcontroller is, and find out what avrdude calls it
    • To se a full list go here, or you can run: avrdude -c dragon_jtag
    • When you find your model, e.g. ATMEGA8515, write down what it says to the left of your model (m8515)
    • Example of a line output by avrdude -c stk500: m8515 = ATMEGA8515 [/etc/avrdude.conf:5385]
    • m8515 is the avrdude model number, ATMEGA8515 is the Atmel model number. The part in the brackets should be ignored.
  4. Flash your compiled image using: avrdude -c dragon_jtag -p m8515 -P usb -U flash:w:rom.hex
    • You might need to run this as root/sudo because of some permission issues.
    • Note: Replace m8515 with the part number you find in step 2, /dev/SOMETHING with what you found in step 3 and rom.hex with the name of your image.

Advanced usage

Setting fuse-bits

Setting fuse bits is basically the same as reading and writing from flash, meaning you use the -U switch to specify what and where to write. Most AVRs got 2 fuse bytes: highfuse and lowfuse, but a few other e.g. Atmega128(L) also got a 'extendedfuse' byte. Refer to your devices datasheet for a description of each fusebit.

The syntax of the -U switch

<memorytype>:<operation>:<filename>[:format]

  • memorytype can be:
    1. flash to use the flash memory
    2. hfuse to use the highfuse
    3. lfuse to use the lowfuse
    4. efuse to use the extended fuse
    5. calibration to use RC oscillator calibration data.
    6. eeprom to use the EEPROM
    7. lock to use lock byte
  • operation can be:
    1. r to read from <memorytype>
    2. w to write to <memorytype>
    3. v to verify <memorytype>
  • filename can be:
    1. name of the file you want to read from or write to
    2. the data you want to write to the fuse, e.g. 8bit hex number
  • format can be
    1. i for intel hex
    2. s for Motorola S-record
    3. m to write bytevalue to memory, 0x as prefix for hex value, a leading 0 for octal and just the number for decimal
    4. a for auto detection of format, only for input and not detect stdin (default for write operation)
    5. d for declimal value comma-seperated list, only valid for read operation
    6. h for hex value, only valid for read operation
    7. o for octal value, only valid for read operation
    8. b for binary value, only valid for read operation (default for read operation)

Examples

  • Reading fuses to file:
    • avrdude -c stk500 -p m8515 -P /dev/SOMETHING -U hfuse:r:high.txt -U lfuse:r:low.txt
  • Writing hexadecimal value 0xC4 to highfuse
    • avrdude -c stk500 -p m8515 -P /dev/SOMETING -U hfuse:w:0xC4:m

Using avrdude's terminal mode

Connect

To enter terminal mode simply add -t at the end of your avrdude command, like this: avrdude -c <programmer> -p <avr> -P <port> -t

  • Replace <programmer>, <avr> and <port> with whatever you have.

Valid commands

 dump   : dump memory  : dump <memtype> <addr> <N-Bytes>
 read   : alias for dump
 write : write memory : write <memtype> <addr> <b1> <b2> ... <bN>
 erase  : perform a chip erase
 sig    : display device signature bytes
 part   : display the current part information
 send   : send a raw command : send <b1> <b2> <b3> <b4>
 parms  : display adjustable parameters (STK500 and JTAG ICE only)
 vtarg  : set <V[target]> (STK500 only)
 varef  : set <V[aref]> (STK500 only)
 fosc   : set <oscillator frequency> (STK500 only)
 sck    : set <SCK period> (STK500 and JTAG ICE only)
 help   : help
 ?      : help
 quit   : quit
dump

dump <memtype> <addr> <nbytes>

  • Read nbytes from the specified memory area, and display them in the usual hexadecimal and ASCII form.
read
write
  • Manually program the respective memory cells, starting at address addr, using the values byte1 through byteN. This feature is not implemented for bank-addressed memories such as the flash memory of ATMega devices.
erase
  • preform chip erase
sig
  • Display the device signature bytes.
part
  • Display the current part settings and parameters. Includes chip specific information including all memory types supported by the device, read/write timing, etc.
send
  • Send raw instruction codes to the AVR device. If you need access to a feature of an AVR part that is not directly supported by AVRDUDE, this command allows you to use it, even though AVRDUDE does not implement the command.
parms
  • STK500 only: Display the current voltage(Vtarget and Varef) and master oscillator parameters(oscillator and SCK_period).
  • JTAG ICE only: Display the current target supply voltage and JTAG bit clock rate/period.
vtarg
  • Set the target's supply voltage to voltage Volts.(stk500 only)
  • usage: vtarg <voltage>
    • voltage between 0.0V and 6.2V
aref
  • Set the adjustable voltage source to voltage Volts. This voltage is normally used to drive the target's Aref input on the STK500.(stk500 only)
  • usage: aref <voltage>
    • voltage between 0.0V and vtarg
fosc
  • Set the master oscillator to freq Hz. An optional trailing letter M multiplies by 1E6, a trailing letter k by 1E3.
  • Usage: 'fosc <freq>
    • to turn the oscillator off: fosc off
sck
  • STK500 only: Set the SCK clock period to period microseconds.
    • usage:sck <µseconds>
  • JTAG ICE only: Set the JTAG ICE bit clock period to period microseconds. Note that unlike STK500 settings, this setting will be reverted to its default value (approximately 1 microsecond) when the programming software signs off from the JTAG ICE. This parameter can also be used on the JTAG ICE mkII to specify the ISP clock period when operating the ICE in ISP mode.
help / ?
  • display available commands
quit
  • quits terminal mode
Personal tools