Eclipse is a free, powerful, and full-featured development environment that can be set up to work with AVR and Arduino. This page is very much a work-in-progress, please feel free to add to it or improve it.
Below is explanation how to setup Eclipse with WinAVR and the Eclipse plugin AVR-eclipse. There is an easier 100%free and opensource way to use Eclipse. For details see http://www.baeyens.it/eclipse/
PlatformIO is free and open-source cross-platform code builder and library manager. It doesn't depend on any additional libraries/tools from an operation system. It allows you to use PlatformIO beginning from PC and ending with credit-card sized computers (like Raspberry Pi, BeagleBone, CubieBoard).
All instructions are described in the main documentation Integration PlatformIO with Eclipse IDE.
There are no current packages, but it's easy to install as per above. Create e.g. /usr/local/pckg/eclipse
and unpack the downloaded eclipse archive. Get the eclipse C/C++ release with all the Linux add-ons. Create a symlink in /usr/local/bin
to the eclipse
executable in the unpacked eclipse directory. Installing plugins from inside eclipse gets them installed in the user's home directory, $HOME/.eclipse/
zypper -v ar -k -f http://download.opensuse.org/repositories/CrossToolchain:/avr/openSUSE_11.4/
zypper -v in avrdude avr-libc avr-example cross-avr-gcc cross-avr-insight
The avr-eclipse plugin cannot automatically find the WinAVR installed with the IDE. Therefore you need to either configure the Eclipse plugin to find WinAVR in the IDE location, or install WinAVR in the default location.
In Eclipse, select Window->Preferences, then click the AVR tree view entry.
Select OK to close the Preferences window.
Open the project properties (right click the project and select properties). Select AVR->AVRDude the tab programmer. Create a new programmer configuration using the new button.
One more step is needed (under Win7 with Eclipse 4.2, AVR plugin v2.4, and Arduino IDE v1.0.1) to get AVRDude working. When invoked from Eclipse, AVRDude cannot find its config file. To fix this, copy the AVRDude config file from:
"C:\path-to-arduino\hardware\tools\avr\etc\avrdude.conf" to
"C:\path-to-arduino\hardware\tools\avr\bin\avrdude.conf".
You should now be able to compile and upload Arduino projects in Eclipse.
Note: As these are workspace settings you may have to redo this setup for each workspace you use.
Install the latest version of [http://winavr.sourceforge.net/ | WinAVR]]. This should work "out of the box" with the latest version of the AVR plugin, as long as you install WinAVR to the default directory. If it doesn't, follow the instructions for using WinAVR here: Programming AVR with Eclipse and WinAVR
There are three ways to get the Arduino core library:
The library source code is included in the Arduino IDE download, in the hardware/cores/arduino directory. At the very least, you will need the header files from that directory accessible to your Eclipse project:
* HardwareSerial.h * WProgram.h * wiring.h * WConstants.h * binary.h * pins_arduino.h * wiring_private.h
You will also need the .a static library.
The resulting program becomes substantially smaller when linking with a static library, so this is the only sensible option. (The link order matters too!)
This is the preferred method. However, I (Ecologisto) couldn't use it on Mac as I didn't find the specified files. The third option did work fine on mac though.
From any Arduino IDE project, get the core.a file in the compilation subdirectory. To generate this file you will need to create and verify a project in the Arduino IDE. It can be any program, such as the Blink program. Make sure that the correct target board is selected in the Arduino IDE.
The compilation subdirectory is a temporary folder. For example, in Windows 7, the object files might be stored in the following directory:
C:\Users\<username>\AppData\Local\Temp\buildXXXXXXXXXXXXXXXXXXXXX.tmp
And for Linux it will be:
/tmp/buildXXXXXXXXXXXXXXXXXXXXX.tmp/core.a
And on a Mac (>=10.5) it will be somwhere under:
/var/folders (Example: /var/folders/3V/3V-hlvHMEDCp4QCrrmPOKE+++TI/-Tmp-/build8628825626808181146.tmp)
The X's in the build...tmp directory are a hash that map to the project whose temporary files are held in the directory. The temporary files are named after the project, so you can verify that you're copying the correct library.
Copy the core.a file into your own project directory, and rename it to libArduinoCore.a. You can call it anything, so long as it starts with "lib" and ends with ".a". It might be a good idea to name the file after its target, e.g. libArduinoMegaCore.a, so that you can always tell what the library's target architecture is.
You can copy the entire contents of the hardware/cores/arduino directory into your Eclipse project so that it is compiled into the application every time. This requires that you use C++ projects, and the projects will take a bit longer to compile. This generally isn't a very good idea unless you're hacking the core code.
You can compile your own static library in Eclipse. The best way is to create this as a library project, and to define a build configuration for each combination of AVR CPU and clock frequency you have.
The sources are copied from the Arduino IDE. Download that, and unpack it somwhere.
328P_16MHz
(no spaces!). Add a descriptive text. Copy settings from Debug. Click OK. Select the configuration just added, click Set active. Click OK.
328P_8MHz
, 1280_16MHz
.
${workspace_loc:/${ProjName}/src}
. Click OK.
ln -s
).arduino_core
the name of the library project created earlier, and src
the name of the source directory in the library project.
; avr-nm -C -n ${OUTPUT} >${BuildArtifactFileBaseName}.symbol
This project setup is as close as possible to the Arduino IDE. On Linux it is possible to use the same source files for an Arduino sketch and an eclipse project (just don't edit them with both at the same time), and compile/upload either with eclipse or the Arduino IDE.
*.pde
of type C++ source file, and
-x c++
" to the C++ compiler settings.
"${workspace_loc:/arduino_core/src}"
"${workspace_loc:/${ProjName}/arduinolib}"
"${workspace_loc:/${ProjName}/lib}"
"${workspace_loc:/arduino_core/328P_16MHz}"
-Wl,--gc-sections
to the linker options.
#include <WProgram.h>
, even the .pde files. It doesn't hurt with the IDE, which does it automatically.
When you try to build you get a prompt saying something like "The application was unable to start correctly (0xc0000142). [...]". The workaround described on http://www.ulrichradig.de/forum/viewtopic.php?f=6&t=2842 (in german) worked fine for me: Download this file and replace the existant file in "<WinAVR installation path>\utils\bin\" and retry to build.
Another workaround in english is described here.
The C++ standard apparently requires this function when using certain language features. This is e.g. the case when using the Print class, or the Serial object, which probably means most Arduino programs. Interestingly, when compiling programs with the Arduino IDE this function remains undefined and no error is produced. It seems this can be achieved with eclipse AVR programs and the following linking order: user program files, user libraries, Arduino libraries, libarduino_core.a, libm.a.
If you do need this function, the most flexible is to put this into a file pure_virtual.cpp
in the project's source folder:
extern "C" void __cxa_pure_virtual() { #ifdef __AVR__ asm("cli"); #endif while (1) ; }
The contents of the __cxa_pure_virtual function can be any error handling code; this function will be called whenever a pure virtual function is called. This file can be excluded from being compiled into the project by right-clicking on its name, selecting properties, and checking "exclude from build".
Using new, delete, and dynamic memory management generally is not recommended for small embedded devices because it can become a resource hog. If you must have it, create a .cpp
file in the project source folder with this content:
#include <stdlib.h> __extension__ typedef int __guard __attribute__((mode (__DI__))); void * operator new(size_t size) { return malloc(size); } void operator delete(void * ptr) { free(ptr); } void * operator new[](size_t size) { return malloc(size); } void operator delete[](void * ptr) { if (ptr) free(ptr); } int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);} void __cxa_guard_release (__guard *g) {*(char *)g = 1;} void __cxa_guard_abort (__guard *) {}
Turning on "pedantic" compiler warnings by adding '--pedantic' to AVR Compiler -> Miscellaneous -> Other flags and AVR C++ Compiler -> Miscellaneous -> Other flags could save some headache.
The last trap is in the fact that by default printf is not supporting float numbers. However because the C++ projects can be complex, it is wise to go to Project Options/Libraries section, you might want to include
but NOT libprintf_min, libscanf_min.
The Arduino environment issues a reset command prior to uploading. This reset command is essential for any kind of bootloader communication. If your hardware is not reset there is no way for avrdude to communicate with the bootloader. Any attempt will result in errors like:
"avrdude: stk500_2_ReceiveMessage(): timeout".
Newer versions of AVRDude (such as the one shipped with CrossPack) will also do this.
Instead of using programmer stk500v1 with AVRdude, use programmer arduino and it creates the reset automatically. In the project properties, change AVR -> AVRDude, Programmer tab, Programmer configuration. Edit the existing one or add a new one.
If you have an older version and are using Windows, you can overcome this problem with this little app. Attach:newavrdude.exe
To use this, you need to:
1) rename the avrdude.exe that is currently being used by eclipse to "realavrdude.exe" 2) Make sure that in the eclipse configuration for avrdude, you specify the port override. This should add something like "-P//./COM7" and it needs to be argument #3 (if this causes a problem for anyone, let me know and I'll build in some configuration stuff). 3) copy newavrdude.exe into the same directory as realavrdude.exe, and rename it to avrdude.exe
When using the Arduino IDE, you just have to define setup() and loop() functions and the IDE already has a main functional defined in the core library that calls setup() and loop() functions.
When setting up the Arduino core library as described above, it is functionally identical to the Arduino programming environment. That is, don't provide main(), but do define setup() and loop(). This is the easiest option.
If you must have your own main(), remove it from the arduino_core library. Eclipse does not define the main() function for you. However, you can use Arduino's default main() function by copying the main.cxx file from the hardware/cores/arduino directory in the Arduino IDE package. You might have to rename this file to main.c for Eclipse to recognize it as a code file. Linking in main.cxx will allow you just to define the setup() and loop() functions like you would in the Arduino IDE.
You must #include "WProgram.h" in your application program to gain access to the Arduino API.
If you choose to define your own main function, you must NEVER return from main(). I mean, you-MUST-NEVER-return-from-main. In human language, this could be translated as "the main() function must contain some kind of endless loop, because if it ends, the Arduino won't stop the program but will just keep reading random data as code". You must also always add a call to init(); as your first instructions. Not doing this will prevent any time-related functions from working.
So, your basic code will usually look like :
int main(void) { /* Must call init for arduino to work properly */ init(); /****************************/ /* Add your setup code here */ /****************************/ for (;;) { /****************************/ /*** write main loop here ***/ /****************************/ } // end for } // end main
Configure the correct USB serial port in AVRDude. It's one of /dev/ttyUSBN, with N being some digit. Best in the long run is to configure udev rules for your Arduino board serial numbers that create a symbolic link to the USB device currently being used by your board. The link name remains constant.
Since we either upload our code direct via a serial port as with the "Arduino Serial" or via USB (which also only simulates a serial port with the FTDI chip on the Arduino borad) we need to know which serial port our Board is connected to.
On Windows, the FTDI virtual COM port driver doesn't register its COM port until the Arduino board is plugged in. With the board plugged into USB, type "devmgmt.msc" into CMD to open the device manager. Go to "Ports (COM & LPT)" and find the "USB Serial Port (COMx)" where x is the number of the port connected to the Arduino. This COM port will usually be the same on your machine even if you reboot or unplug the Arduino, but might differ on different machines.
Go back to your project settings, and go the AVR/AVRDude page. Create a new programmer configuration. You only need to do this once; for other Arduino projects, you can reuse this configuration.
For Diecimila and Duemilanove, the "Programmer Hardware" is "ATMEL STK500 Version 1.x firmware". If you have a recent version of AVRDude, you can also choose "Arduino" which uses a protocol similar to STK500 1.x Version. For the Uno it should work as well.
Enter the name of your serial port in the "Override default port" field. Usually this is something like "/dev/cu.usbserialx" in *NIX and something like "//./COMx" in Windows. Override the default baud rate to 19200 for Arduinos based on the ATmega168, or 57600 for Arduinos based on the ATmega328p. If you receive an error similar to
avrdude: stk500_getsync(): not in sync: resp=0xe0
on a ATmega328p, try 115200 baud rate.
Once you've configured the programmer, save it, then go to the "Advanced" tab and check "Disable device signature check".
If you are using WinAVR-20090313 or earlier on Windows, then you will need to replace the default avrdude.exe and avrdude.conf in the WinAVR directory with the ones from the following directories in the Arduino IDE folder:
hardware\tools\avr\bin\avrdude.exe hardware\tools\avr\etc\avrdude.conf
If you've checked "AVR Dude" in the Additional tool in toolchain panel of the C/C++ Build Settings, your program will get upload at each build. Else, you can just right click your project in the Explorer and choose "AVR/Upload Project to Device" or click the AVR upload button.
If everything worked out fine, your Eclipse console will print something like
avrdude: verifying ... avrdude: 1280 bytes of flash verified avrdude done. Thank you. Finished building: avrdudedummy
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 be aware this may be a potential security leak) server on your computer and open it in the Eclipse terminal. Then, on any unix, just type :
cat /dev/your_serial_port/
The Arduino Blink example implemented in an Eclipse project can be found on github right here. It contains the Arduino Core Library and is therefore completely self contained, the Arduino IDE is not needed. All command line options are configured so that they are as similar to the Arduino IDE as possible creating equally small binaries. It can be imported into Eclipse pretty easily using its Git extension providing a good starting point for your application. An installation manual is available there too.
modification after 31 december 2018