Eclipse and WinAVR in Windows

Atmel’s AVR series of microcontrollers are fantastic.  They have all the features of their Microchip PIC competitors, but they have much more helpful documentation, and they use a port of GCC (AVR-GCC) for code compilation.

Eclipse is a top notch (I might argue, the top notch IDE suite.)  Whats better, is Eclipse is open-source so anyone can write plug-ins for it.

The two combine to be an extremely powerful solution to microcontroller firmware development and programming.

Here’s how to install them to work together:

Installing

  1. Download and Install AVRStudio, required for the programmer drivers.  (Currently build 628)
  2. Download and Install Eclipse, I chose the “Eclipse IDE for C/C++ Developers“.  (Currently Ganymede)
  3. Download and Install WinAVR.  (Currently version 20080610)
  4. Launch Eclipse
  5. Download and Install the AVR-Eclipse plug-in.  In Eclipse, click Help-> Software Updates…
  6. Click on the “Available Software” tab.  Click the “Add Site…” button.  Enter the following into the text box:
  7.  http://avr-eclipse.sourceforge.net/updatesite/
  8. Click OK.  Click on the newAVR-Eclipse Banner and Click the Install Button. You should see this:
  9. Eclipse AVR-Eclipse Plugin
  10. If that doesn’t work, try the direct download option here.

Compiling

  1. Launch Eclipse
  2. Create a new project (File -> New -> C Project)
  3. Enter the name and location for your project
  4. For Project type select: “AVR Cross Target Application / Empty Project”
  5. For Toolchains select: AVR-GCC Toolchain
  6. Eclipse New AVR-GCC Project

  7. You are now able to compile AVR source (below is a sample program) from within Eclipse using the AVR-GCC toolchain.  But can you program target microcontrollers?
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>

#include "test.h"

int main(void)
{
    int counter = 0;
    int mask;

    PORTE.DIR = 0xFF;

    while(1)
    {
        mask = 1 << counter;

        PORTE.OUT = mask ^ 0xFF;

        _delay_ms(50);

        counter++;
        if(counter >=8){ counter = 0; }
    }
}

Programming

  1. The easiest way to program is to open AVR Studio, click the Cancel button to close the open project dialog, click the tiny AVR icon on the toolbar:
  2. AVR Studio Program Button

  3. …select your programmer (if it didn’t autodetect) and locate your compiled .hex file:
  4. AVR Studio Programming Screen

  5. …and program it.  From AVR Studio, you can set various fuses and configuration settings — this is invaluable.
  6. AVR Studio is slow though, and its a relative pain to switch to it, click the AVR button, click the program tab, click the … button under Flash to program the flash memory, navigate your file structure to your recently compiled .hex file, then click Program.  It should also be noted that (at least with the JTAGICE mkII), the programmer holds the processor in reset until you close the AVR dialog.  This is annoying because you keep having to close and re-open the window each programming iteration.
  7. There is a way, using AVRDude, to program right from Eclipse but it uses different drivers, at least for my JTAGICE mkII  (LibUSB drivers vs. Jungo drivers) so it won’t work without switching drivers.  Switching drivers is no big deal, but then my programmer will no longer work under AVR Studio — so I can’t set fuses, lockbits, etc.  (Note: I know there is apparently a way, with filter drivers from sourceforge, but I spent 3 hours trying to get the filter drivers to work to no avail, google it and ymmv.)
  8. I left the drivers as they were (Jungo drivers) and make a simple programming batch file that navigates to your .hex, programs and displays the result (named AVRProg.bat):
@cd \
@cd Projects\Demo\_Firmware\Debug
C:\Progra~1\Atmel\AVRToo~1\JTAGICEmkII\jtagiceii.exe -d ATXMEGA128A1 -e -pf -vf -if Demo-1.0.hex
@pause

Here I:

  1. Switch to the root directory
  2. Switch to my debug directory (where the .hex file ends up)
  3. Run the programmer script (I use a JTAGICE mkII), but you can find the various other scripts up a few levels in the same directory.
  4. (In this case, the target is an ATXMEGA part, the -pf flag means program flash and -vf flag means verify flash)
  5. Pause so you can see how the programming went.  (If you don’t care, you can remove this line or comment it out with a proceeding double colon, ::).

The programmer immediately releases the processor from reset, you can close the programming dialog whenever.

You should be well on your way to coding, compiling and programming for these bad ass microcontrollers.

Posted Thursday, February 26th, 2009 under firmware, tips and tricks.

5 comments

  1. Great post! Just wanted to let you know you have a new subscriber- me!

  2. Patrick says:

    Thanx for the post..but i have a question..i have a erreur message..my #include stdio.h is not reconnize…do you know what can be the probleme??
    tx

  3. Patrick says:

    All my include
    :
    #include
    #include
    #include
    #include
    #include
    They have a red wave ender it..

  4. Hi Patrick-

    Seems like you don’t have the paths set correctly. Try re-installing winavr and making sure the top two checkboxes are set – notably the one “Add Directories to PATH”.

    Does that help?

    Also, in Eclipse if you right click on the project and go into project properties, open C/C++ Build, then Environment.

    Is your path (variable PATH) set correctly? What is it? Does it match where you installed WIN-AVR?

  5. B.Rose says:

    Hi Patrick,

    thanks for taking the time to create this helpful tutorial. your tutorial helped me lot. could you please put some more images in Installing part (1-9 steps) of your blog like this one http://puranranablog.blogspot.com/2011/05/winavreclipse-ide.html

Leave a Reply