Setting up Eclipse for AVR projects
For many hobbyists the first AVR integrated development environment (IDE) that they will encounter will be the Arduino IDE.
The Ardunio IDE goes out of its way to make it easy for you to quickly bash out test code and get it up and running as fast as possible without having to worry too much about what’s going on in the background with compilers, linkers and the avrdude upload software. This is great and I still use it regularly to try out quick ‘what if’ scenarios. However, the Arduino IDE is completely unsuitable for real project development due it’s ultra-basic multi-file support, complete lack of access to compiler options and an editor that I’m going to be polite and call ‘limited’.
For real work you will need to move on to either a command-line/makefile environment or choose a compatible IDE.
Eclipse is a full-featured cross-platform IDE that has been around for a long time now. Originally written for java programmers, it has been extended over the years to include a perfectly competent C/C++ environment. Best of all it’s completely free. The rest of this article will give you step-by-step instructions on how to get Eclipse up and running for AVR development on a Windows computer. My environment is Windows 7 x64 but the instructions should be portable to XP and Vista.
Step 1. Install a JRE
Skip this step if you know you already have a Java Runtime Environment (JRE) on your PC. Otherwise surf to the java.com website and install the free JRE. The reason that you’re doing this is because Eclipse is written in java and needs a java virtual machine to run.
Step 2. Download and install Eclipse CDT
Take yourself off to the downloads page at Eclipse.org and download the latest version of the Eclipse IDE for C/C++ Developers. It comes packaged in a zip file containing a folder called ‘eclipse’. There is no fancy installation program, just drag the ‘eclipse’ folder out of the zip file and into your ‘Program Files’ directory.
When that’s done you will probably want to create a shortcut to the eclipse.exe program that you will find in the ‘eclipse’ directory that you just created.
Step 3. Download and install WinAVR
Eclipse knows how to organize and edit C/C++ files but it does not have a clue how to compile them, and it does not come with all the header files and libraries that you need to be an effective AVR developer. For this, we need WinAVR. So off you go to the WinAVR download page and install it. This one comes with it’s own installer so you should have no problems installing it.
Here’s a tip: don’t be tempted to install it into a directory that has spaces in its name such as “Program Files”. The tools it installs are ported from Unix and Unix tools are notoriously incompatible with directory names that have spaces in them. Just accept the default suggestion and you’ll be fine.
Step 4. Install the Eclipse AVR plugin
Launch Eclipse using the shortcut to eclipse.exe that you created in step 2. If this is the first time that you have launched Eclipse then it will ask you for a workspace location. This is the default location in which Eclipse will create projects. Change it if you want, or just accept the default.
Go to the Help->Install New Software option and enter ‘http://avr-eclipse.sourceforge.net/updatesite’ into the Work with: field at the top. Hit enter and you should have a screen that looks like this.
Click image to magnify it.
Check the boxes as shown in the image above and then just go through the wizard until you’ve got the plugin installed. Eclipse will want to restart at the end. Let it.
Step 5: Configure AVRDude
AVRDude is the program that we use to take your compiled masterpiece and upload it to the AVR board. In this step we will assume that you are using an Arduino board and will show you how to configure AVRDude in Eclipse to talk to it.
You will need to know which serial port (COMx) that your Arduino is plugged into. If you don’t know, then switch it on now and fire up the Arduino IDE. The IDE shows you all available serial ports under the Tools->Serial Port menu option. It should be obvious which one is your Arduino.
Back to Eclipse…
Select the Window->Preferences menu option. Expand the ‘AVR’ option on the right and click on ‘AVRDude’. The AVR plugin allows you to have multiple AVRDude configurations and we are going to create just one for your Arduino board.
Click on the Add… button and you’ll get a window like this one.
Click image to magnify it.
Fill in the fields like I’ve done. Of course you don’t have to use the same name and description as I have but do note the syntax for entering the COM port (//./COMx) and the baud rate of 57600. I may be the odd one out here, but on my system sometimes Windows gives me COM3 and sometimes COM4. It’s highly annoying because each time it does the port flip I have to come back here and change the AVRDude configuration to match. Bear that in mind if you suddenly find that you can’t upload code to your board that was working perfectly well the previous day!
When you’re done click OK to add this configuration to your list.
Step 6: Check the paths to the WinAVR tools
Select the Window->Preferences menu option. Expand the ‘AVR’ option on the right and click on ‘Paths’. You should get a window like this:
Click image to magnify it.
The AVR plugin automatically configures itself with the relevant paths but do just eyeball them to make sure they look OK.
Congratulations you are now ready to create your first AVR project using an enterprise-class development environment.