Archive for janvier, 2009

AVR Programming with Eclipse on a Macbook Pro

janvier 29th, 2009 | Category: Apple,Embedded,Geek,Tech

Since I’ve been placed in the « Low-Level team » at Novariant, I’ve learn a lot of stuff regarding embedded system. Being in SONIA also helped to developed this interest in embedded and robotic stuff… but the requirements in SONIA are not really the same as those I encounter at work.

At work, the timing requirements are extremely important if you want to get the best precision in the industrie. Knowing that, and planning to start my career in the embedded computing world, I decided to take the course « LOG550 – DĂ©veloppement de système temps rĂ©els » which means that I will learn how to program on a microcontroller. Unfortunately, this courses is not in my standard program at university (not offered to GTI student), BUT, since I already worked for a company in the embedded field and that I was in the SONIA project it was easy to get a derogation for it.

The development board used in LOG550 is an STK500 from AVR and the microcontroller is the ATMEGA32. Since I like embedded stuff, I bought the kit. Instead of only being able to touch to this hardware at school, I can now « PLAY » with it at home.

Well, having the kit is one thing but programming it is something else and for that I must have a good IDE. Unfortunately, AVR is selling their things with an IDE that is made for Windows… I though that every embedded programmers would be smart enought to not use Windows and I can’t understand why AVR Studio is Windows only… But well there is better replacement anyway and Eclipse is one of them.

So here is how I setuped everything to make it work with my Macbook Pro. (The steps can easily be adapted for any platform because Eclipse is multiplatform and AVR toolchain also)

You need:

  • The STK500 starter kit
  • The ATMEGA32 Microcontroller
  • A serial to USB adapter (only if your computer doesn’t have a serial port)

Now lets start with the software installation. The first thing you need is the AVR toolchain so you’ll be able to compile stuff for the microcontroller. I’m using a Mac so the toolchain is in the « AVR MacPack » basicly it contains a special gcc for avr. For users of linux, check your package manager for it and for the unfortunate … there is WinAVR. Look here if you want more information on the toolchains.

Ok, now that we have our toolchains installed, lets move on Eclipse installation. I suggest you to download the bundle for C/C++ « Eclipse IDE for C/C++ Developers » to get a clean IDE. I’ve download the latest, which is called Ganymede at the moment. Now you need to install the AVR plugin, like any other plugins you use the update manager to do it.

Update Site (Eclipse 3.4)

Go to the Software update dialog (Help > Software Updates…)

Then select the Available Software tab. Click on the ‘Add Site… button o the right hand side and enter the URL of the update site:


Then click on OK. The AVR Eclipse update site is now shown in the list of update sites. Select the « AVR Eclipse Plugin » and press the Install… button in the top right corner.

From the plugin’s wiki

You’re done ! Eclipse is installed and setuped with the AVR Plugin. Now you have to create a C project to begin… I followed this little guide and adapted it to my needs, basicly you change the toolchain, the MCU and the frequency. I have a 16MHz crystal so I changed it to 16000000.

There is still some little settings to make everything work. We will go to the properties of your new project and create a new programmer configuration.

Properties of your project  –> AVR –> AVRDude and select the Programmer tab. Now click on New… enter a name, select your programmer hardware (mine is an Atmel STK500 version 2.x Firmware) and if you have to use a USB to serial adapter give a path to it in the « Override default port (-P) » field. For me this window look like that:


I did not use the internal crystal of the ATMEGA32 so I had to change the Fuse Bits for it. Properties of your project  –> AVR –> AVRDude and select the Fuses tab and select Direct hex values. Now, make sure your STK500 is hooked to your computer and that the ATMEGA32 is in place and also that everything is powered. Then click on the third icon (the one that look likes an MCU) on the list like below.

This will read the current fuses bit from the MCU and populate the empty fields. Now we have to modify them so we can tell the MCU to use an external crystal. For this click on the first icon on the list to start the editor. The only parameter I had to change is « SUT_CKSEL ».

You should get something looking like this.

Now, for some reasons my configuration was not generating the HEX need for the MCU and AVR plugin. To fix this, go to the properties of your project –> C/C++ Build –> Settings –> Additionals Tools in Toolchain and make sure that « Generate HEX file for Flash memory » is checked.

Also, take a look at the other configurations there. By preference I changed « AVR Compiler –> Languages Standard » and set it to « ISO C99 + GNU Extensions » it adds « -std=gnu99″ to the compilation (with this you can now use a variable declaration in your for loop header). I also point the directories to the include folder of the AVR Toolchain to make it easier to see the different « .h » files inside eclipse.

I hope I did not forget something, if I did, simply drop me a comment.



No comments