As I said, here's a little how-to on how to setup Eclipse to program the Arduino. It is fairly incomplete, so I'm posting it here for interested people to maybe comment and extend it in order to make a complete step-by-step.
So, first : This have been done on Eclipse 3.3.2 (Europa), on Mac OS X.4. It might work as well on any unix, but I can't guarantee anything for Windows platforms.
Configuring Eclipse and AVR Plugin
Eclipse
C Developpement Toolkit
AVR Plugin (Don't hesistate to go for 2.2 beta 1 instead of 2.1 release)
Target Management Project (optionnal)
and the AVR-GCC toolchain compiled and ready to go. Tutorials and binaries exists everywhere for many platforms, I'm not going to double them here.
First, configure the AVR Plugin in the Preferences window. This means setting up folders on where to find the different avr binaries and config files. It usually is :
/usr/local/bin for binaries
/usr/local/etc for avrdude.conf
You'll also need a folder named PartDescriptionFiles which you can get from an installation of AVR Studio. YOu'll have to install it on a Windows machine, anyway. A friend can easily do it for you and give you back the folder.
Creating an "Arduino Lib" project
Create a new C/C++ project and copy the following files into it :
From your Arduino installation, the following files located on /hardware/cores/arduino :
HardwareSerial.h
WProgram.h
wiring.h
WConstants.h
binary.h
pins_arduino.h
wiring_private.h
From any Arduino project, get the core.a file in the applet subdir and add it, to. I renamed it decimilia_core.a to prevent mistaking and allow handling of multiple Arduino boards. Note you can also build everytime, but this may be a bit longer and is mostly useless, except if you're planning to hack into it.
You're not going to even build your project, it's just a library for your Arduino projects.
Your first Arduino project
Create a new C or C++ project with "AVR cross-target executable" as a target. Go to your project's preference and set them as the following :
AVR Target Hardware : For Decimila, Atmel168 with a MCU Clock frequency of 16000000
C++ Build/Settings/AVR C++ Compiler/Optimization : Optimize for size (-Os)
(same for the assembler)
C++ Build/Settings/AVR C++ Compiler/Directories : Add the folder of the previously created ARduino Library to the list of include dirs
On Assembler and Compiler, you might also want to disable debugging symbols
AVR C++ Linker, change the command line pattern to :
${COMMAND} --cref -s -Os ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -lm ${FLAGS}
And the "Command" to avr-gcc instead of avr-g++ (may be already be the default if you're making a C project instead of a C++ one)
It works with default settings, too.
AVR C++ Linker/Objects : Add the core.a file you've imported and maybe renamed from the Arduino library.
Writing code
You must #include "WProgram.h"
No loop() and setup() here, only
int main(void);
You should NEVER return from main(). The easiest way to do this is :
int main(void) {
/* Setup instructions */
for (;;) {
/* main loop */
}
}
You must always add a call to init(); as your first instructions. Not doing this will prevent any time-related functions to work.
Uploading to the Arduino
For a Decimilia, the avrdude command looks like this :
avrdude -F -pm168 -cstk500v1 -P/dev/cu.usbserial-A4001uwp -b19200 -D -Uflash:w:./your_executable_name.hex:i
You can add it as a post-build command
Serial port monitor
If you have Target Management Project installed, just go to the Window menu / Show View / OTher.. And choose Terminal/Terminal. Open it with a serial link and choose the serial port your Arduino is connected to. Notice you'll probably have to disconnect the terminal while uploading.
As the RXTX library is a troublemaker for many people, there is a workaround : Just start a SSH or Telnet (please check your security setup before doing this !!!) server on your computer and open it in the Eclipse terminal. Then, on any unix, just type
cat /dev/your_serial_port/
This tutorial sucks
Yes, a lot of things are still to do :
– Creating a default Arduino project witch will prevent from doing a complete config of each project.
– Getting a deeper integration of avrdude
btw, please especially reports if your programs built within Eclipse are bigger than the ones built with the Arduino env. The modified linker call should prevent this, and in fact makes even smaller executables than Arduino.
PLEASE, do not reports problems or questions about Arduino on Eclipse anywhere else in this forum than on this thread. Arduino/Eclipse is just a geek's hack, and I don't think Arduino people will want to discuss it or search solutions for it. (Owners/Moderators, if you don't think this is needed, just remove it ^_^)