Developing Software for the Atmel AVR with AVR-Eclipse, AVR-GCC & AVRDude
Developing software – or better firmware – for the Atmel AVR can be quite easy or quite complicated. A lot of people like to just use vi, some source files and a make file. Here at Interactive Matter we are a tad lazy and want a fully fledged IDE, with code completion, one click building, no make files and buttons to flash the AVR. The easiest was is to achieve this with Open Source Software, using avr-gcc, avrdude and avr-eclipse. This guide explains how to install and use it.
First of all you have to install avr-gcc and avrdude for your system. There are several packages available. So I just give short hints for some operating systems:
- If you are using Linux your package manager will provide you some options. There are far too many distributions out there and if you are using Linux you should be able to find and install it yourself. But most distros bring a package manager where you can install avr-gcc and avrdude. Make should allready be installed – if not it is often found in package named ‘build-essentials’ or similar.
- If you are using Windows you need to install WinAVR. You can download it from sourceforge. The WinAVR guys provide a very nice installation guide.
- If you are using Mac OS X you just install CrossPack for AVR Development. Objective Development provides some convenient download packages, grab and install them and everything is fine. Do not forget to install a make tools. It comes with XCode (my preferred option) or MacPorts or Fink.
Downloading and installing Eclipse and the necessary plug-ins
To develop ATMEL AVR software with eclipse you need Eclipse, especially the Eclipse CDT (C/C++ Development Toolkit). Just download the version for your operating system and install it. In most cases it can be run in any directory whether it the Applications Folder of MAC OS X, C:\Program Files, /usr/local/bin or any local directory.
Now it is time to start eclipse and install the avr-eclipse plugin. In eclipse open the Help menu and select the option to Install New Software.
This opens the screen to specify the plug-in to install. Here you just enter the update URL of AVR-Eclipse (http://avr-eclipse.sourceforge.net/updatesite/), press enter and select the AVR Eclipse Plugin:
After you click Next you will be asked a lot of question, if you accept licenses or if you trust unsigned software – to install answer them all with yes. When the installation is finished Eclipse wants to restart, you should do it.
Voila, you have installed the AVR-Eclipse plug-in. Next step is to configure the plug-in. Open the Eclipse Preferences, on MAC OS X under Eclipse, for other operating systems under the menu Window. First configure the avrdude. Open the option AVRDude:
Click on Add to configure your avrdude and programmer. Now you get a very big menu to configure all the options:
In the left pane you have to select your type of programmer (or the compatible type), ensure that you configure the correct port in the lower pane and, if needed, the baud rate. Enter a name for the configuration, click OK and you are done. Next is to verify that the AVR-Eclipse plug-in got all the paths right. Click on the Paths panel and check the paths:
It is OK, if the plug in did not find Atmel Part Description Files. They are delivered with the official Atmel Packages and not publicly available, you can simply ignore it.
Creating your first AVR project
To create a new AVR project simply select the menu New, Project it will open a wizard to guide through the initial setup of the project:
From the wizard you select C Project (or C++ Project if you want to use C++).
Click Next and select the project type as AVR Cross Target Application and enter a nice project name:
After you click Next you can select the available configurations, Debug or Release. I personally do not use the AVR debugger, so I just create a Release configuration:
Now you are finished and click Finish. Now the C/C++ Perspective opens – or at least Eclipse asks to open it and you can start programming. A useful first step is to add a file ‘main.c’ containing the main routine. For this you right click on your project and select New and then Source File:
A nice little wizard pops up asking you for a name – ‘main.c’ in our case and if you are creating a C source file or a C header file – here a C source file is appropriate:
Now you can really start programming, adding source and header files as you like and start implementing your code.
It is a good idea to set the target hardware quite early in your development cycle, since that defines which constants are defined. To do this you open the project properties, by right clicking on the project and selecting Properties from the menu.
In the properties settings you first navigate to the AVRDude settings and select your programmer, so that Eclipse is able to talk to your programmer and target hardware. The programmer you have defined during set up is now in the list and you can simply select it.
After this is done you can select the Target Hardware options and select your target hardware here. In this dialogue you can either pick it from the drop down list or read it from the target hardware itself. I suggest connecting your programmer with the target hardware and read out the value. So you do not have to search the correct value and you test your whole setup, the programmer and the target hardware. If you can read out the target hardware, you will be able to program it.
Another good idea is to go back to the AVRDude section and set the fuse bits. Select direct hex value. Here you can also read them from the target hardware (the third icon next to the hex value) and edit to your needs (the first icon next to target hardware):
Now you have done everything to successfully develop for your ATMEL AVR device in Eclipse. To build your project, simply click on the hammer in the tool bar or press Ctrl-B or Command-B. Eclipse will the compile your project and generate the necessary firmware files.
If you have done it successfully, you can upload it to your target hardware, by clicking the upload icon, or pressing the corresponding shortcut. Be sure that you have selcted your AVR project in the left pane – else you got the nice warning ‘No AVR project selected’ since the firmware uploader thinks you want to upload a single source file or so.
Finished! The rest is up to you. Now you got everything to develop AVR programs with all the comfort Eclipse offers. Here at Interactive Matter we do not use anything else, since it is so convenient. No make files, point and click for nearly everything and the power of code completion.
If you want to debug your newly created firmware you can refer to the Debugging Guide on the AVR-Eclipse Wiki.