This is a quick primer on using Eclipse, AVR, and MacOS. A detailed guide is provided on the Arduino website, but I’ve documented the particularities of MacOS here.
Before you begin, download the following software:
- Latest GCC (either from XCode, or Fink [package = gcc4.5-4.5.0-1000])
- Latest AVR Tool Suite- easiest to get it from CrossPack
- Eclipse (Downloads: Galileo or Helios)
- Eclipse AVR Plugin – get Version 2.3.1 NOT anything newer
Instructions
- Install GCC, Eclipse, and the AVR tool suite
- Test GCC and AVR Tool Suite
- Open terminal
- Type “gcc –version”
- Type “avr-gcc –version”
- You should see something like this:
- Launch Eclipse and ensure you have the C/C++ perspective.
- Look at top right hand of screen – you should see:
- If not, click the square icon with the gold plus in the upper right hand corner to change perspectives.
- Select Other…
- Select “C/C++“.
- If you don’t have the C/C++ perspective, add the perspective via the Eclipse download manager
- Click on “Help->Install New Software…“
- Select Helios in the drop down labeled “Work with:”
- Click the arrow next to “Programming Languages”
- Check “C/C++ Development Tools“
- Click Next, Next, I Accept, and Finish
- Wait for the install and click “Restart”
- Quit Eclipse
<<This is where we deviate from the install instructions on the Eclipse AVR Plugin website. I’m still working on getting v2.3.4 working on the Mac>>
- Unzip the Eclipse AVR Plugin
- Copy the contents of “features” to the “features” directory of your Eclipse install
- Copy the contents of “plugins” to the “plugins” directory or your Eclipse install
- Start Eclipse
- You should see the “AVR” icon next to the build icon.
Now, adjust avrdude settings in Eclipse by using latest processor, port, and baud rate:
avrdude -pm328p -cstk500 -P/dev/tty.usbserial-A600aftj -b57600 -t
For each of your “main” files, you need to have the following “method” to ensure linking with the C++ libraries work properly:
extern "C" void __cxa_pure_virtual()<br />{<br /> while (1);<br />}<br />
Now you can configure your first project according to the instructions on the Arduino website.
One point to note – ensure you set up the linker properly. I struggled for 2 days trying to get my program to link properly. It suddenly started working and I really have no clue what I changed to make it work. One of last things I set was the linker command line and the optimizations, so perhaps that was it.
-ffunction-sections -fdata-sections -Wl,--gc-sections
Note – Adding the above to the optimizations seems to make the generated files larger, but the resulting hex file seems to be the same size with and without the flag.
${COMMAND} --cref -s -Os ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -lm ${FLAGS}
One final and very important suggestion. Once you get a project working properly, always copy that project as a starting point. It’s a lot easier than trying to recreate all the steps necessary to get all of this working.
That should be it.
Other Links
- Lady Ada Mac Setup – http://www.ladyada.net/library/avrdevtut/setup-mac.html
- http://homepage.mac.com/chen/w7ay/AVR%20Tools/Contents/resources.html
- Windows-based, but a good reference: http://robertcarlsen.net/2009/10/31/arduino-in-eclipse-989