How to use the command 'avrdude' (with examples)

How to use the command 'avrdude' (with examples)

The avrdude command is a driver program for programming Atmel AVR microcontrollers. It is used to read and write data to AVR microcontrollers, as well as listing available devices and programmers.

Use case 1: Read AVR microcontroller

Code:

avrdude -p AVR_device -c programmer -U flash:r:file.hex:i

Motivation: This use case allows you to read the contents of an AVR microcontroller and save it to a file in Intel HEX format (.hex). This is useful for backup purposes or for analyzing the firmware running on the microcontroller.

Explanation:

  • avrdude: The command itself.
  • -p AVR_device: Specifies the type of AVR microcontroller being used. Replace AVR_device with the appropriate device name, such as atmega328p.
  • -c programmer: Specifies the programmer being used to communicate with the AVR microcontroller. Replace programmer with the appropriate programmer name, such as usbasp.
  • -U flash:r:file.hex:i: Specifies the operation to be performed. In this case, we want to read (r) the contents of the flash memory (flash) of the microcontroller and save it to a file (file.hex) in Intel HEX format (i).

Example output:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading flash memory:

Reading | ################################################## | 100% 16384 bytes
Reading | ################################################## | 100% 32768 bytes

avrdude: writing output file "file.hex"

avrdude: safemode: Fuses OK (E:FF, H:DF, L:FF)

avrdude done.  Thank you.

Use case 2: Write AVR microcontroller

Code:

avrdude -p AVR_device -c programmer -U flash:w:file.hex

Motivation: This use case allows you to write new firmware to an AVR microcontroller from a file. This is useful for updating the software running on the microcontroller with the latest version or for uploading custom programs.

Explanation:

  • avrdude: The command itself.
  • -p AVR_device: Specifies the type of AVR microcontroller being used. Replace AVR_device with the appropriate device name, such as atmega328p.
  • -c programmer: Specifies the programmer being used to communicate with the AVR microcontroller. Replace programmer with the appropriate programmer name, such as usbasp.
  • -U flash:w:file.hex: Specifies the operation to be performed. In this case, we want to write (w) the contents of the file (file.hex) to the flash memory (flash) of the microcontroller.

Example output:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "file.hex"
avrdude: input file file.hex auto detected as Intel Hex

avrdude: writing flash (16384 bytes):

Writing | ################################################## | 100% 2.08s

avrdude: 16384 bytes of flash written
avrdude: verifying flash memory against file.hex:
avrdude: load data flash data from input file file.hex:
avrdude: input file file.hex auto detected as Intel Hex

avrdude: input file file.hex contains 16384 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.87s

avrdude: verifying ...
avrdude: 16384 bytes of flash verified

avrdude: safemode: Fuses OK (E:FF, H:DF, L:FF)

avrdude done.  Thank you.

Use case 3: List available AVR devices

Code:

avrdude -p \?

Motivation: This use case allows you to list all the available AVR devices supported by avrdude. This is useful when you are not sure about the exact device name to use in other commands.

Explanation:

  • avrdude: The command itself.
  • -p \?: This option lists all the available AVR devices supported by avrdude.

Example output:

Device signatures (from file):
    m8 = 0x1e9307
    m88 = 0x1e930a
    m168 = 0x1e9406
    m328p = 0x1e950f
    usb1286 = 0x1e9781

Available AVR devices:

Use case 4: List available AVR programmers

Code:

avrdude -c \?

Motivation: This use case allows you to list all the available AVR programmers supported by avrdude. This is useful when you are not sure about the exact programmer name to use in other commands.

Explanation:

  • avrdude: The command itself.
  • -c \?: This option lists all the available AVR programmers supported by avrdude.

Example output:

Valid programmers are:
  - arduino    = Arduino
  - arduino-ft232r = Arduino: FT232R connected to ISP
  - buspirate = The Bus Pirate
  - butterfly  = Atmel Butterfly Development Board
  - bsd       = Brian Dean's Programmer
  - bsd-hack  = Brian Dean's in-circuit hack programmer
  - dt006     = DT006 serial programmer
  - dapa      = Direct AVR Parallel Access
  - dice      = DICE emulator
  - dragon_dw = Dragon with debugWire
  <...>

Related Posts

Using the coreauthd command (with examples)

Using the coreauthd command (with examples)

The coreauthd command is a system daemon that provides the LocalAuthentication framework.

Read More
How to use the command 'docker rename' (with examples)

How to use the command 'docker rename' (with examples)

This article will demonstrate how to use the ‘docker rename’ command and provide examples of its use cases.

Read More
How to use the command 'git submodule' (with examples)

How to use the command 'git submodule' (with examples)

Git submodule is a command that allows you to inspect, update, and manage submodules within your Git repository.

Read More