Arduino‎ > ‎

Eclipse IDE

There are some tutorials on the internet, which describe how to set up an AVR tool chain and use the Eclipse IDE to develop programs for the Atmel AVR line of microcontrollers:


I will extend these tutorials with a method to compile Ardino programs by linking against a slightly modified version of the Arduino framework code.
In brief you need to follow these steps to get a working environment to build Atmel AVR programs:

First of all you need a working AVR tool chain, so you can compile AVR programs on the command line. Refer to the other tutorials on how to get this up and running.

Second you need the Eclipse IDE. If you only plan to develop C/C++ programs, choose the Eclipse IDE for C/C++ Developers package:


Then install the AVR Eclipse plugin


by adding this update site


and installing the AVR Eclipse Plugin feature.

After that you need a workspace project that contains the Arduino core code and all the libraries you are going to use in your own projects.

Another more detailed tutorial can be found in the Arduino Playground http://www.arduino.cc/playground/Code/Eclipse.

Arduino Framework project

I have compiled an Eclipse project that contains all the Arduino core core (currently based on Arduino version 0022) a small subset of third party libraries and my own libraries. Of course you can add other libraries to this project. Modifications must be done to the file paths of #include directives, since we cannot rely any more on the magic done by the Arduino IDE.

Download my latest Arduino Eclipse Framework project


and unzip into your Eclipse workspace directory. Then import the "Existing Eclipse Project" de.grapelabs.arduino.framework.

There are some build configurations defined, all with a crystal clock 16 MHz. You can define more build configurations as needed. 
Choose for example the atmega168_16000000 configuration and compile the project. You should get a libarduino.a file in the atmega168_16000000 subdirectory.

Your own project


Create a new empty C++ project with type AVR Cross Target Application for the AVR-GCC Toolchain.
Open the project properties and under AVR/AVRDude specify the programmer to use and select the MCU type and clock frequency (under AVR/Target hardware). The MCU name (e.g. atmega168) and clock frequency (e.g. 16000000) must match the name of build configuration of the framework project (e.g. atmega168_16000000).
Then we need to specify some toolchain settings. Under C/C++ Build/Settings add the path "${workspace_loc:/de.grapelabs.arduino.framework}" to AVR Assembler/Paths, AVR Compiler/Directories and AVR C++ Compiler/Directories.
So that the linker will be able to find the framework library, go the AVR C++ Linker/Libraries settings and add arduino to the list of libraries and the path "${workspace_loc:/de.grapelabs.arduino.framework}/${AVRTARGETMCU}_${AVRTARGETFCPU}" to the list of library paths. This dynamically generated library path enables you to have different project with different MCUs.
Also enable the options Generate HEX file for Flash memory_ and _Generate HEX file for EEPROM under Additional Tools in Toolchain.

Now you can create your Arduino program file, for example blink.cpp:
#include <WProgram.h>

void setup() {
 pinMode(13, OUTPUT);
}

void loop() {
 digitalWrite(13, LOW);
 delay(250);
 digitalWrite(13, HIGH);
 delay(250);
}

int main() {
 init();
 setup();
 sei();
 for (;;) {
 loop();
 }
 return 0;
}
As you can see, you have to write a main function (which is magically provided if you use the Arduino IDE) and have to add a #include <WProgram.h> directive.
Executing Project/Build Project should now create a hex file which you can finally upload to your development board by clicking on the AVR toolbar button.