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.

Prerequisites

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.

{ 44 comments… read them below or add one }

Jono July 24, 2010 at 01:46

Many thanks for that. Very useful and easy to follow. You wouldn’t know of an ARM eclipse plugin?

Reply

Marcus July 24, 2010 at 16:38

I have no real ARM experience, but there is an ARM Plugin for Eclipse. But I don’t know how it works or hog good it is.

Reply

Dorf July 24, 2010 at 03:13

Hey,

I tried installing the way you have it set up but when I get to the part to configure avr-dude, the AVR option is missing from Eclipse. I followed your instructions installed CrossPack, Eclipse, downloaded the plug-in but something went wrong.

Any other tips, I’m on osx 10.5.8 if that matters.

Cheers!

Reply

Marcus July 24, 2010 at 12:15

Don’t know. The AVR Eclipse plugin can have really bad days. If it is a fresh install I would suggest to remove Eclipse, all Eclipse settings and reinstall. Check the Console if Eclipse has issued any emergency messages. If nothing helps, just ask the guys over at AVR Eclipse, they have quite some support resources.

Reply

Ed July 30, 2010 at 18:09

Hi.
Great job.
I know that you don’t use debugger but you probably have one configuration for debug your project.
Do you have any tutorial that you can point it to me?
Thanks

Reply

Marcus August 19, 2010 at 07:24

On the AVR Eclipse Wiki is a good description how to debug.

Reply

Mike August 18, 2010 at 22:40

Hai,

I tried this manual on my new macbook but i do not get it to work. I follow all the steps but i keep getting an error that it cannot find make. I used different versions of eclipse and crosspack :(

Reply

Marcus August 19, 2010 at 07:18

You are right, that is a step I have forgotten to describe:
You have to install build tools like make. For Mac it comes with XCode (my preferred option) or MacPorts or Fink.
On most Linux systems it is allready installed.
For Windows I would suspect Cygwin to provide it – but my knowledge is somewhat limited.

Reply

Mike August 19, 2010 at 10:12

Tnx for the fast reply, i will try it when i come home. I thought that the Xcode would be installed already on my macbook?. I just got my macbook this week

Michael November 10, 2011 at 13:16

Been reinstalling and configuring Eclipse for a week now trying to get rid of this make problem – CrossPack installs a make program which works fine if you compile their demo from the command line. I’ve just resolved problem by copying their copy of make from /usr/local/CrossPack-AVR-20100115/bin to /usr/bin (and /usr/sbin for good measure) which are the only paths Eclipse seems to search (besides the project directory). Think the bug is in Eclipse as no amount of configuring alternative paths to the CrossPack folders would get it to include those paths when searching for make. Using Eclipse Indigo on OS X 10.6.8

Eric C September 1, 2010 at 13:22

Great stuff!

When I get to picking hardware from avrdude list (“Click on Add to configure your avrdude and programmer.”), mine is not in the list. I’m using STK525 ( http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3878 ). I currently have to use FLIP software to program it, which isn’t bad, but requires a makefile, etc. I poked around the AVRDude project website, but couldn’t find anything regarding the 525 or flip.

Reply

Marcus September 1, 2010 at 13:32

If it is not on the AVRDude list then it is simply not supported by avrdude. Perhaps you can try WinAVR to see if you have more luck.
Sorry for this answer.

Reply

Martin October 3, 2010 at 11:38

Following you excellent instructions above, I went to view the Properties for my AVR project, and I see two AVRDude entries under the AVR key?
The first displays a dialogue with the message “AVRDude is not supported for Static library projects”. The second entry shows the six tabs (programmer, Flash/etc) with green legends.

Can you offer any clues as to what is happening here?

Regards,

Reply

Marcus October 3, 2010 at 13:34

You probably have selected ‘AVR Cross Target Static Library’ as project type. Since this is a library to use in other projects it cannot be downloaded to an AVR. You want to select ‘AVR Cross Target Application’ as project type ;)
As far as I know you cannot easily convert it – but creating a new project with the correct project type is quite easy.

Reply

Frank November 10, 2012 at 15:40

i have the same problem and i´ve bin the i select ‘AVR Cross Target Application’ as project type.

Paul December 11, 2010 at 06:02

Many thanks for documenting this, and sincerely appreciated. Works great for me on the Axon mcu with Pololu ISP . I found my version of AVR Studio doesn’t have “open declaration” (i.e., go to the code or definition for this function), which is there on Eclipse – so that was one of the reasons to switch over. I also appreciate the “one touch” send-to-target using avrdude vs. the bootloader method (turn off, click send, turn on). Cheers.

Reply

Kurt December 13, 2010 at 08:06

Thanks for this setup tutorial. It didn’t help me setup for AVR dev using Eclipse, but it DID let me know I was doing everything right – and the install still isn’t working.

I also am running 10.5.8 on a MacBook. Have just done fresh installs of Eclipse for C/C++, the AVR Plugin and the Crosspack toolchain. Everything is good up until I’m supposed to see the AVR option in starting a project – then no “AVR” appears.

Hopefully this will get some attention and be fixed. I’m really eager to develop for AVR using C on my Mac!

Reply

Marcus December 13, 2010 at 10:37

If the AVR Option do not appear in the settings you have perhaps not installed the Eclipse AVR Plugin.
To create a new project keep in mind that you have to select a static C project. If you do not have a AVR option there you should also check the correct installation of the AVR Eclipse Project.
Hope that helps

Reply

Alastair D'Silva January 16, 2011 at 21:48

You may be interested in a couple of related projects of mine:

MHV AVR Tools is similar to WinAVR, but includes the current GCC compiler & AVR-LibC runtimes: http://www.makehackvoid.com/project/MHVLib

MHVLib is a runtime library for AVR microcontrollers, developed in Eclipse. You can grab the project files here: http://www.makehackvoid.com/project/MHVLib

Reply

borg February 22, 2011 at 20:37

Hi
thanks for a great tutorial. have everything working except when im trying to build the project i get the following error is there anyone who have seen this problem before.
make: *** [first avr p.elf] Error 1 first avr p

Reply

Marcus February 22, 2011 at 20:45

Sorry I cannot help. Is this the complete error message?
But perhaps somebody else knows the solution.

Reply

borg February 22, 2011 at 21:01

hm
yes i know there is no errror when runing on pc and it does not complain on the code the problem occures when running on mac it does not produce an hex file

Reply

Justin June 28, 2011 at 05:20

I was having a problem where a hex file was not being generated. I found that there is an option to generate a hex file under the project properties.
project>properties
C/C++ build>Settings
Additional Tools in Toolchain
check the box next to:Generate HEX file for Flash Memory.
This took me a while to figure out.

Reply

silvere April 9, 2011 at 18:44

Hello,

I can’t find out on which port is my serial converter connected to (for the configuration).
Do you know how to get this info ?
System profile app doesn’t give any answer.

cheers
silvere

Reply

Marcus April 9, 2011 at 19:24

If you are on mac or linux the easiest ist to watch the output of dmesg while plugging in the programmer – it should tell you there which port is assigned to your programmer (if it is FTID based) – other programmers just use the interface ‘usb’ and avrdude will be able to find itself.
Without knowing the programmer and OS it is quite hard to tell.
But even with both it is questionable if I really know howit works – everything is a bit different.
Hope it helps though

Reply

silvere April 10, 2011 at 14:37

Thanks for your reply.
I think it’s because a HL 340 usb to serial converter, which is not compatible with Mac. I ordered a keyspan as i know it’s for mac.
Then as you said, avrdude will be able to find itself.

Thanks a lot

Silvere

silvere April 13, 2011 at 18:40

Hello I want to share the fix for this. I run on a Imac 10.6.
So I got the keyspan converter and in order to use it with eclipse the configuration of the Overide Default Port is located in /dev/tty.KeySerial1
Then the baud rate is 115200 in order to program with the STK500

I hope this is help.

Paul Asselin June 27, 2011 at 10:56

Hi, First of all thank you for such a wonderful post.
I’m stuck in Eclipse, when I go into Preferences (I’m on a Mac), I go in the AVR tab and when I click Add, nothing happens.
I have tried it on three different versions of Eclipse and I’ve re-installed every necessary package. Would you know the cause of the problem? Otherwise, I might try contacting the avr-eclipse group.
Thanks again,
Paul

Reply

Marcus June 27, 2011 at 12:28

Hi,

I do not really understand what you like to add – but asking in the avr-eclipse group might b the better idea for bugs. This is just a description how it should look like. There are probably many things that con go wrong.

Reply

Agu Chux July 18, 2011 at 16:41

I need to setup my AVRISP to work with eclipse and developing on 89S52, any help

Reply

ksiedzulek August 8, 2011 at 18:46

hi,

after bulding project I have recieven these errrors:

make: *** [AVR.elf] Error 1

and

undefined reference to `main’

what should I do? please help me:(

Reply

go August 9, 2011 at 12:28

Uhm, it actually means you are missing the main() function. This is the function that is called when the microcontroller is powered up. But perhaps it is there, but the wrong signature. The main function must be void main(void).

Reply

Venkat M. Reddy February 3, 2012 at 20:58

Thank you very much for this awesome tutorial. I believe for most people who are reasonably familiar with electronics, bits bytes and software it is figuring out where to starts and initial baby steps. This has been an awesome introduction no talk all ACTION… Keep up the good work if you still are creating such awesome introductions….
VeAr

Reply

Marcus February 3, 2012 at 21:41

Thanks for the kind words

Reply

Nelson April 26, 2012 at 05:38

Hi there!
Well I’m really new into AVR’s and I just bought an AVR programmer. I have a mac but I was using a Windows partiton in order to use winAVR, but for some reason Windows doesn’t install the hardware. I’ve tested the programmer in other computers (windows based) and it worked, so now I know the hardware is OK. I followed up your tutorial so I can use mac, but I can’t setup the hardware. I know that in the programmer hardware list I have to select the AVRISP or the STK500, but I don’t know how to setup the communication ports. For Windows I had to install an emulator and after that write some command lines like “install PortName=COM2 PortName=COM6″ in a software called com0com. I have the next warning window “avrdude: see_open(): can’t open device “unknown”: No such file or directory”. I hope somebody can help, still i’ll keep on trying. Thanks for your time.
Nelson :)

Reply

Nelson April 26, 2012 at 05:56

I forgot to mention, my programmer is supposed to work with AVRkit 2.0

Reply

Daniel May 13, 2012 at 01:15

Thank you very much for this awesome tutorial. All work fine. I’m using xubuntu 12.04.

Reply

Aditya July 25, 2012 at 15:18

i used the steps above and i was able to build. Now i have two doubts:

1. Where do i find the “Programmer Hardware (-c)”? I am using atmega8.

2. I went with the default for my above question. After the build is succesful, i get this as my error:
“”"Launching /usr/local/CrossPack-AVR-20120217/bin/avrdude -pm8 -cstk500 -Uflash:w:AVR_TEST1.hex:a
Output:
avrdude: ser_open(): can’t open device “unknown”: No such file or directory
avrdude execution aborted”"”
What does this mean and how can i avoid it?

Thanks

Reply

Aditya July 25, 2012 at 15:20

I forgot to mention that by default i meant “Atmel STK500 Version 2.x firmware”

Thanks

Reply

David December 1, 2012 at 19:37

Thank you for the tutorial

I’m trying to use this to code for Arduino, but I don’t know why in “Target Hardware” I cannot open the dropdown list to choose the correct option, nor I can “Load from MCU”

Could you help me please?
Thank you

Reply

Peter March 20, 2013 at 00:29

Thank you for the tutorial!

I’m using WINDOWS and the “Juno” Eclipse version. Following your tutorial worked fine until the point that my AVR DRAGON does not seem to be able to read the fuse and lock bits via the AVRDude window. After installation of the libusb-win32 driver, I can read out the controller internals perfectl using e.g. “cmd” typing “avrdude -patmega162 -cdragon_jtag -Pusb”. Even within the “Target Hardware” section of AVR’s properties, the read-out of the MCU Type works. But no read-out within the AVRDude settings window (fuse and lock bits). Choosing “Load from MCU” leads to the error message [avrdude: usbdev_open(): did not find any USB device "usb"].

What could this be?

Thanks.

Reply

Peter March 20, 2013 at 14:21

The solution was found.

After each operation the AVR DRAGON detaches and re-attaches himself from/to the USB. So, for the operating system there is a time periode where the USB device is not present (app. at least 1s time). Issuing subsequent AVRDude invocations with less than 1s delay causes the AVR DRAGON not to be found on USB. When configuring subsequent invocations of AVRDude with a delay of at least 1s time solves the problem in this case, because Eclipse invokes AVRDude two times for fuses and lock bits.

Thank you.

Reply

jilali June 13, 2013 at 17:04

hello
is a grear work
I using ATMEL in my project ATmega 16 for developing a kit for robot
i like to use a open source for this kit like arduino or wiring
what i do?
please help me?

thank you

Reply

alf-arobase July 21, 2013 at 16:47

hi, i just wanted to thank you for this tutorial, because it’s clear, illustrated and well writed even a newbie like me could achive some AVR programmation with a bus pirate. sooo Thank You!

Reply

Leave a Comment