In this tutorial, you will learn exactly what AVR DUDE is? How to install it? and how to upload a HEX file on any Arduino board or AVR Microcontroller using AVRDUDE.
First lets get into the details of AVRDUDE!
AVRDUDE:
AVRDUDE is an acronym for AVR downloader uploader. It is an open-source software used to program AVR microcontrollers. You can also use it to program EEPROM, Flash memories, and even fuse and lock bits.
AVRDUDE is available as a Command-line program and you will have to type in commands to perform read, write or verify operations.
AVRDUDE also has an interactive mode called terminal mode. This mode allows you to enter interactive commands to display and modify various device memories, perform a chip erase, and much more. We will discuss it with examples later in this tutorial.
There are also some 3rd party GUI packages that are handy if you are not comfortable with the command-line. however, the command-line program is more preferred and you can easily automate the build process using makefile which we will discuss in the upcoming tutorial.
AVRDUDE can be used effectively via the command-line to read or write the on-chip memories they include EEPROM, flash memory, fuse bits, lock bits, and signature bytes.
If you want to upload a hex file to the flash memory of your microcontroller you can easily do it using the command line. On the other hand, the Interactive terminal mode makes it easier if you are exploring memory contents, modifying individual bytes of EEPROM, or programming fuse/lock bits.
AVRDUDE Options:
Avrdude provides you many options and functionalities which can be listed in the command-line. Let’s discuss the most common options that are more commonly used. You should note that these options are case sensitive.
-C (Config-file)
– (capital)C is used to specify the config file for configuration data. The file contains all the programmer and microcontroller definitions that are supported by AVRDUDE. If you have a programmer or a microcontroller that Avrdude doesn’t know about you can add the details of its configuration in this file.
In Windows, it searches for the config file in the folder where AVRDUDE is installed. We will also see how to install AVRDUDE later in this tutorial.
-c (programmer-id)
-(small)c tells AVRDUDE about the type of programmer that is used to program the microcontroller. AVRDUDE knows about several common programmers so use this option to specify which one you are using. For each of the supported programmer, the programmer-id parameter is listed in the configuration file.
For a complete list of programmers type “avrdude -c help” in the command line. You will see a complete list of programmers that are supported by the AVRDUDE. Here help is just some nonsense parameter to get it to spit out the list of programmers.
-p (Part id)
-(small)p tells AVRDUDE about the type of microcontroller that is connected to the programmer. Its parameter must be the Part ID listed in the config file. Here are the part-id’s of the microcontrollers that are supported by the AVRDUDE.
PRT ID | uC NAME | PRT ID | uC Name | |
c128 | AT90CAN128 | m32 | ATmega32 | |
pwm2 | AT90PWM2 | m324 | ATmega324 | |
pwm3 | AT90PWM3 | m328 | ATmega328 | |
1200 | AT90S1200 | m3290 | ATmega3290 | |
2313 | AT90S2313 | m48 | ATmega48 | |
2333 | AT90S2333 | m64 | ATmega64 | |
2343 | AT90S2343 (*) | m640 | ATmega640 | |
4414 | AT90S4414 | m644 | ATmega644 | |
4433 | AT90S4433 | m649 | ATmega649 | |
4434 | AT90S4434 | m6490 | ATmega6490 | |
8515 | AT90S8515 | m8 | ATmega8 | |
8535 | AT90S8535 | m8515 | ATmega8515 | |
m103 | ATmega103 | m8535 | ATmega8535 | |
m128 | ATmega128 | m88 | ATmega88 | |
m1280 | ATmega1280 | t12 | ATtiny12 | |
m1281 | ATmega1281 | t13 | ATtiny13 | |
m16 | ATmega16 | t15 | ATtiny15 | |
m161 | ATmega161 | t2313 | ATtiny2313 | |
m162 | ATmega162 | t25 | ATtiny25 | |
m163 | ATmega163 | t26 | ATtiny26 | |
m164 | ATmega164 | t45 | ATtiny45 | |
m169 | ATmega169 | t85 | ATtiny85 |
For a full list of Supported Devices type “avrdude -c arduino -p help” in the command-line. Here help is just some nonsense parameter to get it to spit out the list of supported microcontrollers.
-b (Baud Rate)
– (small)b option overrides the serial communication baud rate, specified for that programmer in the configuration file.
-P (Port)
– (capital)P is used to identify the port to which the programmer is connected. I will tell you how to identify this port later in this tutorial.
-v (verbose Output)
– (small)v option enables verbose output. When you enable this command you will see extra information about the command that you have executed.
-U memtype:OP:filename:format
– (capital)U specifies the memory operation to be performed. Let’s discuss the different parameters that this option takes.
This option takes various parameters, “memtype” specifies the memory type to be programmed, “op” defines the operation to be performed, ”filename” is the source or destination file to be read or written to, and “format” parameter specifies the format of the file.
memtype:
AVRDUDE supports various memory types present on the microcontroller. The memtype parameter is used to specify the type of on-chip memory to be programmed. These are the memtypes that can be accessed by the AVRDUDE.
- eeprom: The EEPROM of the device.
- efuse: The extended fuse byte.
- flash: The flash ROM of the device.
- fuse: The fuse byte in devices that have only a single fuse byte.
- hfuse: The high fuse byte.
- lfuse: The low fuse byte.
- lock: The lock byte.
OP:
The OP parameter specifies the type of operation to be performed. This field takes a single character that can be “r”, “w” or “v” for read write or verify operations.
- r: read the specified device memory and write to the specified file
- w: read the specified file and write it to the specified device memory
- v: read the specified device memory and the specified file and perform verify operation.
filename:
The filename parameter specifies the name of the file to read or write. You should also specify the extension of the file along with the file name.
format:
The format parameter is optional and contains the format of the file to read from or write to. Possible values of this parameter are “i, s, r, and a”. The details of each of these format are provided in this slide. The Intel HEX format is the most popular and is commonly used among them.
- i: Intel Hex
- s: Motorola S-record
- r: raw binam
- m: immediate mode
- a: auto detect
This was an overview of AVRDUDE we will use all of these option in AVRDUDE examples tutorial given below. Let’s see how to install AVRDUDE first.
How to Install AVRDUDE ON Windows:
In the second part of this article, I will also tell you to install AVRDUDE on your windows computer.
If you have Arduino IDE installed on your Windows PC then for sure you have AVRDUDE already installed on your computer. You can verify it by opening the command prompt and typing “AVRDUDE” there.
Type “command prompt” in the search field on the taskbar and open it by pressing enter. Then type “avrdude” there.
If you see this message
“‘avrdude’ is not recognized as an internal or external command, operable program or batch file.“
Then AVRDUDE Is not installed on your machine and you should follow this tutorial to install AVRDUE on your machine.
On the other hand, if you see a list of available options for AVRDUDE when you type it in the command prompt. Then it means that AVRDUDE is already installed on your computer and you can just use it to upload programs onto your Arduino Boards.
Lets See how to install AVRDUDE:
Open this link and downlead the software from here AVRDUDE ZIP.
Go to C drive or any other drive you like. Make a new folder with the Name “AVRDUDE” and copy the zip file to this folder.
Extract the contents of the zip file to this folder. There should be two files “avrdude.exe” and “avrdude.conf“. The First file is the executable AVRDUDE program whereas the second is the configuration file for AVRDUDE. Which contains the definitions of all programmers and microcontrollers supported by the software.
Next, you have to add this folder to the path variable. To do this go to your desktop and right-click on “This PC“. Then click on properties.
Click on the advanced system settings on the right. A window will pop up showing you the “System Properties”.
Click on the environment variables button in the lower right corner. In the system variable section, you will see a variable named “path”. Select the variable and click on edit.
Click on the new button paste the path and click ok. Now, the program path is set in the environment variables and the installation is complete.
To very the successful installation of AVRDUDE, open the command prompt again and type “AVRDUDE”. if you see a list of all the options associated with AVRDUDE then your AVRDUDE program is all set and running.
Now you can use this program to flash Arduino boards and AVR microcontrollers.
There is also another method by which you can install AVRDUDE on your windows machine. AVRDUDE is also included in WINAVR Toolchain. This toolchain includes open source software development tools for AVR microcontrollers.
You can also download and install WinAVR toolchain. It has AVR-GCC compiler along with other tools that will help you compile and generate hex files from your code. We will have complete tutorials on how to use these tools in the upcoming posts.
AVRDUDE In Action:
In the third part of this tutorial, we will see how to use AVRDUDE for performing different operations.
How to use AVRDUDE in interactive Mode:
AVRDUDE interactive mode is very handy if you want to read and write to the fuse, lock bits, or chunk of memory. To go into the interactive mode type AVRDUDE in the command prompt. Then type the programmer-id that you are using. In my case, I am using Arduino Uno board as an ISP programmer so that’s why I have typed “avrisp“.
Next, you have to provide the name of the microntroller chip you are working with. I am programming Arduino Pro Mini and it has an “atmega328p” microcontroller chip so I have used “m328p” for this option.
You also have to provide the serial com port on which the Arduino is connected. You can easily find the comport from the device manager.
Go to the search field in the taskbar, type “device manager” and press enter. You will see the list of all the connected devise. Expand the “Ports” section you should see the COM port for your Arduino board. In my case, it’s COM8, so I have mentioned it using the -C (dash Captical C ) option.
Let’s talk about the baud rate now. Most of the programmers have baud rate specified in the “avrdude.config” file. In my case, I am using ARDUINO UNO as an ISP programmer with a baud rate of 19200. The baud rate is not set correctly for “avrisp” in the config file in my case and the default baud rate doesn’t work as demonstrated.
There are two solutions to this problem lets discuss both of them.
First, I can override the default baud rate by using the -b option and giving the program the correct baud rate of 19200. This will work and the program as demonstrated here.
Or I can add the baud rate information in the config file. It is also very easy to do so let’s do it. Open the config file and search for “avrisp” as this programmer does have the baud rate specified like some of the others. Let’s give it a baud rate of 19200 and save and close the file. It will work as well as shown.
Finally, type “-t” to take the Arduino into interactive mode. AVRDUDE will then verify the device signature to check if the right device is connected. You will see “avrdude>” which shows that AVRDUDE is now in terminal mode.
Yes! it works like a charm. You can now type help to see all the available commands in the interactive mode as shown below.
- dump: dump memory : dump
- read: alias for dump
- write: write memory : write …
- erase: perform a chip erase
- sig: display device signature bytes
- part: display the current part information
- send: send a raw command : send
- parms: display adjustable parameters (STK500 only)
- vtarg: set (STK500 only)
- varef: set (STK500 only)
- fosc: set (STK500 only)
- sck: set (STK500 only)
- spi: enter direct SPI mode
- pgm: return to programming mode
- verbose: change the verbosity
- help: help
- ?: help
- quit: quit
How to read the values of efuse, hfuse, lfuse, and lock byte in the interactive mode?
To read the values of the fuses type the read command followed by the fuse name. Let’s demonstrate it for efuse first. Type read and then type efuse and press enter. You can see that the value of efuse is set to 0xfd. Similarly, let’s demonstrate it for the other fuse and lock bytes.
- read efuse : To read the extended fuse byte.
- read hfuse: To read the high fuse byte.
- read lfuse: To read the low fuse byte.
- read lock: To read the lock byte.
How to write the values of efuse, hfuse, lfuse and lock byte in the interactive mode?
let’s see how can we write a new value to the efuse. I will write the same value on to the Atmel atmega328p because I don’t want to change the fuse settings of my Arduino Pro Mini. However, we will discuss in detail what each fuse and lock bits do and we will change them to change the settings of the AVR microcontroller.
To write to fuse byte, type “write” followed by the fuse name in my case it’s efuse, then type the address as it’s only a single byte so the address will be 0x0000, and finally type the 8-bit hex value, I have chosen 0xff.
You can then read the contents of the efuse again in order to very the changes. I don’t want to change the settings of my Arduino Pro Mini so I will change the efuse byte back to 0xfd. But I future tutorials we will learn about each fuse bits and we will change them.
- write efuse 0x0000 0xfd
- write hfuse 0x0000 0xda
- write lfuse 0x0000 0xff
- write lock 0x0000 0x3f
How read the flash memory in the interactive mode?
You can easily read chunks on memory in the interactive mode. Lets read 8 byte of flash memory from address 0x0000 to 0x0008. Simply in terminal type “read” then type “flash” and then type the start address followed by the number of bits you want to read, in my case its 8.
When you press enter you will see contents of the flash memory for those addresses on the terminal.
- read flash 0x0000 8
- read flash 0x0040 16
How read the EEPROM memory in the interactive mode?
Just like the flash memory, you can read the contents of EEPROM memory in the interactive mode by typing write and then EEPROM followed by the starting address and the number of bits. You will see the contents of EEPROM for those addresses on your terminal.
- read eeprom 0x0000 8
- read eeprom 0x0010 4
How to use AVRDUDE:
Now lets see how can we use AVRDUDE to read and write from Arduino.
How to Upload HEX file on Arduino using AVRDUDE?
You can easily upload any HEX file on Arduino any of your Arduino boards using AVRDUDE. To do this task write type AVRDUDE in the command prompt then specify the programmer-id (in my case its AVRISP), next type the microcontroller-id (I am using arduino pro mini so its m328p in my case). After than mention the port and baud rate for me the port is COM8 and the baud rate is 19200.
Then type -U to specify that you are doing a memory operation and then flash colon w to specify that it’s a write operation then colon file name (in my case file name is adduino.hex) and finally type a colon followed by “I” to specify that its an intel hex file.
- avrdude -c avrisp -p m328p -P com8 -b 19200 -U flash:w:adduino.hex:i
This is a simple blink program where the yellow led is connected to Pin 8 of my Arduino Pro Mini board. Here is my setup, I am using Arduino Pro Mini board as ISP programmer and it is connected to Arduino Pro Mini using the SPI communication module. The yellow led is connected to PB0 or Pin 8 of Arduino Pro Mini.
How to Download the program from Arduino Flash Memory using AVRDUDE?
You can also easily download the contents of the flash memory using avrdude. To perform this task type -U to specify the memory operation and then type flash followed by colon then “r” then the output file name and then colon “i”.
- avrdude -c avrisp -p m328p -P com8 -b 19200 -U flash:r:adduinoDownload.hex:i
You will then find a HEX file named “arduinoDownload” in the current folder. This is the hex code that we have downloaded from Arduino Pro Mini board.
How to Download the data from Arduino EEPROM using AVRDUDE?
You can also easily download the contents of the EEPROM using avrdude. To perform this task type -U to specify the memory operation and then type eeprom followed by colon then “r” then the output file name and then colon “i”.
- avrdude -c avrisp -p m328p -P com8 -b 19200 -U flash:r:adduinoEEPROM.hex:i
You will then find a HEX file named “arduinoDownload” in the current folder. This is the EEPROM data in the intel hex format that we have downloaded from Arduino Pro Mini board.
I hope that you have learned a lot from this tutorial. Keep intouch because we will be discussing more interesting topics very soon.