Setting up Arduino development environment under Mac OS X

Oct. 8, 2011, 11:56 a.m.

Arduino is a great open source micro controller platform utilizing AVR microcontrollers. This is a short how-to setup a development environment for arduino on Mac OS X using Eclipse.

Arduino stuff

Versions: OS X Lion / Eclipse Indigo / Arduino 022

I had to read several blog entries and how-to's to get a general idea what's going on, so I'll try to outline the big picture (or at least the part i understood) first:

What we're basically doing here is cross compiling, which means we build for a certain architecture (AVR) on another system (our MAC). Therefore we need a compiler toolchain (we'll use Crosspack for MAC), that generates binaries (.hex files) from our source code. Eclipse is our IDE and needs to know how to talk to our toolchain, therefore we'll use a Eclipse Plugin called 'AVR Eclipse Plugin'. The arduino core is basically a software layer that builds on stuff from the AVR library (avr-libc) and has functions for several common tasks (for example attaching to a hardware interrupt). We can compile the whole arduino core into one static library and use it in our projects. To get our binaries onto the AVR chip we'll use an AVR ISP mkII flasher via usb.

  1. Download and install Eclipse CDT.

  2. Install AVR Eclipse Plugin via Eclipse Help / Install new software: http://avr-eclipse.sourceforge.net/updatesite/.

  3. Get GNU AVR-GCC toolchain: avr-libc, avr-gcc, avr-binutils and avrdude for example via Crossback -> Note: I ran into problems here, when I tried to install the toolchain via Mac Ports. Here I got a rather old version of the avr-gcc compiler (4.0.2), that doesn't support the AVR 328p chip (the one that's used on Uno board, for example). You'll need a compiler > 4.3.0 for that, and Crossback currently includes 4.3.3.

  4. Download and install Arduino package (dmg for OS X).

  5. Build a static library for arduino core, following the guide here, section 'Compiling your own static library'. These are the basic steps:
    5.1 Create a new C project in Eclipse, Project type 'AVR Cross Target Static Library' (name it ArduinoCore, for example)
    5.2 Right click the project, Properties
    5.3 Select your hardware under AVR - Target Hardware (for example ATmega328P, 16000000 Hz for Uno or Ethernet (with or without POE) board)
    5.4 C/C++ Build - Settings - Tool Settings - AVR Compiler - Debugging - No debugging info
    5.5 C/C++ Build - Settings - Tool Settings - AVR C++ Compiler - Debugging - No debugging info
    5.6 C/C++ Build - Settings - Tool Settings - AVR Compiler - Optimization - Size Optimizations (-Os)
    5.7 C/C++ Build - Settings - Tool Settings - AVR C++ Compiler - Optimization - Size Optimizations (-Os)
    5.8 Import all files except 'main.cpp' from '/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino' into your project
    5.9 Build the project, a libArduinoCore.a should have been generated

  6. Create a new C Project in Eclipse, named ArduinoBlink for example. Again we have to change a few settings but later on we can use Eclipse's copy project functionality, so we have to do this only once. So right click on the project and change the following:
    6.1 Set MCU and clock frequency like in 5.3
    6.2 Open C/C++ Build - Settings
    6.3 Additional tools in toolchain: check 'Generate HEX file for Flash memory' and 'Print Size' and check 'AVRDude'.
    6.4 AVR Compiler - Directories: Add include path to your arduino core source.
    6.5 AVR Compiler - Debugging: No debugging info.
    6.6 AVR Compiler - Optimization: Size optimizations (-Os).
    6.7 AVR Linker - Libraries: Add library path and library to our ArduinoCore lib in workspace.
    6.8 Open AVR - AVRDude
    6.9 Create a new programmer configuration and within there set 'Override default port (-P)' to 'usb'.

  7. Click Build or the hammer icon and your first arduino binary will be compiled, linked and uploaded to the board.

If you have any questions concerning this How-To or additional remarks, feel free to contact me.

tags: arduino avr development eclipse environment mac osx

read more