smallchip
AVR Tools

Kok Chen, W7AY [w7ay@arrl.net]
Last updated: May 23, 2008



Introduction

AVR Tools provides a Mac OS X GUI for avrdude. AVR Tools also includes a terminal emulator which can be used to talk to serial ports, such as the spare RS-232 port on the Atmel STK500 Development board. The terminal emulator can be run stand-alone, without connecting AVR Tools to any development board.

Various resources are available to enable you to write AVR code without using the Terminal interface in Mac OS X (see Resources page). AVR Tools allow you to download and inspect code, EEPROM and fuses on the AVR without using Terminal.

AVR Tools is not a supported product, but simply a project that I wrote for myself to use. If you have similar needs, AVR Tools is completely free.

AVR Tools is built as a Universal Binary application and works natively with both the PowerPC and the Intel based Macintosh running Leopard (Mac OS X 10.5). You can download both the AVR Tools application and Xcode project from the Download page. The sources in AVR Tools are GPL free, and you are free to make any changes that you want.

The terminal emulator (Term.m) in AVR Tools is an Objective-C extension of NSTextView class. It can be used as sample code for any Cocoa application that needs to communicate with a Mac OS X serial port through a text view.

There is a set of tutorials on how to use the tools to build and download a working program to an AVR on an STK500 development board.


avrdude

AVR Tools uses avrdude to perform the actual download and uploads to an AVR development board. avrdude is an open source Unix executable that you will have to download separately. AVR Tools does not embed any of the avrdude source code in it, but simply runs avrdude as a task when it is needed. If you don't already have avrdude in your system, follow the instructions here to download the entire AVR tool chain for Mac OS X.


Sessions

An AVR Tool session consists of a set of selections (location of hex file, serial port to the development board, the AVR chip used, etc) that can be saved and re-opened.

After launching AVR Tools, you can select a New Session or open an existing session file.

filemenu

Each session can be saved (or saved into a file with a different name). The saved file is a Cocoa dictionary (similar to a plist file) with the properties of the session. The saved file has an avr extension and it can also be opened by double clicking on the file in the Finder.

When you select New Session, a new AVR Tools session window will appear, showing the Program tab. The Download button in this tab view is used to program new firmware into your AVR.

initwin

Use a Browse button to select which hex file to download.

To clear either the Flash or the EEPROM fields, click Browse button and then Cancel from the file open dialog. That will clear the corresponding text field. AVR Tools avoids touching the memory of a hex file field that are not defined..

If your file does not use the .hex extension, uncheck the .hex only checkbox. With the .hex only selected, all other files (except folders) are grayed out, making it easy to find files with the .hex extension.

The scrolled text view under the text fields contains the console log from avrdude. The Clear button at the bottom left of the window clears this log. You can cut and paste from this log, but text that is typed into this text view will be ignored. If you want to talk directly to the STK500 programming port, you can use the Terminal emulator (described later).

If this is a newly created session, you will need to first fill a few other items in the other tab views before you click on the Download button.

The Fuses tab lets you set the fuses in the AVR chip. You will usually not need to change the default fuses that are shipped in the chip. If you leave a fuse field empty, that fuse will not be touched. If you want a fuse to be programmed, enter a two digit hex value, such as 62 or bf.

fuses

The Device tab contains a popup menu for you to select the AVR chip that you are programming.

device

The Programmer tab lets you select the development board that you are using for programming. avrdude supports a number of prgrammer, but I have only tested AVR Tools on the Atmel STK500. Please make sure that you select the "Version 2" STK500 (as shown below) if you have a more recent STK500. If you select the original Atmel STK500 from the popup menu, avrdude will take extra time to discover that it really is talking to a version 2 board. If you choose to use the high voltage programming function on the STK500, you will need to select the high voltage version of the STK500 in the popup menu.

programmer

Finally, you need to select the serial Port that you are using to communicate with the programmer. The example below shows a Keyspan USB-serial port adapter selected.

port

If you are not sure of the port name of the serial port, you can find it by getting a list of serial ports. Select the Show Serial Ports item in the Window menu:

serial

This should bring up a Serial Ports window. By removing the USB adapter of the port that you will be using, you should see a Removed message with the name of the port, as shown below:

portwindow

When you plug the device back in, the window should report that the port has been Added.

You can check what is currently in your AVR chip by using the Dump tab.

dump

The Read Memory button will upload the Flash and EEPROM memories into two Intel formatted Hex files called avrFlashFile.hex and avrEepromFile.hex. The download folder is selected by using the Browse button; it is defaulted to your home folder.

Each of the fuses (if it exist) is downloaded and displayed inn green into the log window. The following shows the Fuse Extended Byte (eFuse) that is dumped (value is 01 hex) from a new ATmega168:

efuse

(AVR Tools actually asks avrdude to read the fuse into a file in your /tmp directory. AVR Tools then reads the file back when avrdude is done.)

If you get a message that the fuse dies not exist, you might check if the log shows any errors. For example, if ATtiny85 is chosen as the device and the ATmega168 is in the programmer's socket, you might see the log below:

wrongdevice

Notice in the above, that avrdude says that it has read back the device signature from an ATmega168 instead of the device signature that it expects from an ATtiny85.


Downloading code

Once all devices and ports have been set up, go back to the Program tab and click on Download. You should see avrdude's progress printed to the log text view. Once you have saved this session into a file, and open the session at a future date, you will not need to do any setups. All the fields are saved into the session file.


Saving sessions

You can save the session to a file (.avr extension) that contains the name of your current hex files, fuses, device, programmer and serial port settings. You can for example save this together with your AVR project so you would not need to set everything up again in the future. Use the Open... or Open Recent in the AVR Tools File menu to open this saved session.

You can also double click on the session file to launch AVR Tools and open the session file. If you have not previously saved a session file, a Save will behave as Save As... .

A saved AVR Tools session file has the following Finder icon:

avricon


Terminal Emulator

AVR Tools comes with a terminal emulator. To start the emulator, click on the Terminal tab of the session window. You will be presented with the serial port parameters (these parameters are also saved to the session file):

termwin

Click on the Open Connection button when all the parameters are set up. This will open a separate emulator window. Anything that you type in that second emulator window will go out on the serial port and anything that the serial port receives will be printed to the text view in the emulator window. If you have selected the crlf checkbox, each newline that you type will be sent to the serial port as a pair of carriage return/linefeed characters.

The serial port is disconnected when you close that second emulator window.