Showing posts with label mac os x. Show all posts
Showing posts with label mac os x. Show all posts

Wednesday, May 26, 2010

Setup Arduino with Eclipse

While I think the Arduino IDE is great to play around with an AVR microcontroller it reaches its limits when used with bigger projects. They often need a better source code organisation, esp. if one's using C++ classes. Because of that I mostly switch to an Eclipse based development environment after an initial kickoff phase.

The setup of the eclipse based development environment for Arduino is a bit of a challenge. Following my setup procedure, based upon Robert Carlsen's Blog on a Mac OS X Snow Leopard and a Boardiuno:
  • install XCode if not already done (else make will fail)
  • install Cross Pack for AVR development
  • install Arduino IDE
  • Download and install Eclipse for C/C++ developers
  • Install the AVR-Eclipse Plugin to Eclipse
    • Help -> Install new software
    • http://www.eclipse.org/downloads/ is the update site
    • restart eclipse
  • check the paths in Eclipse preferences / AVR / Paths
    • should point to the cross pack
    • Atmel Part Description Files is not needed
  • add a AVRDude config (Eclipse preferences / AVR / AVRDude -> Add)
    • Name: Boarduino
    • Programmer Hardware: STK500 Version 1.x
    • Baudrate: 57600
    • Set port (find the port by 'ls /dev/cu.*', i.e. /dev/cu.usbserial-FTELSJ9T)
  • create a new CPP project (or checkout my template)
    • New C++ Project
    • AVR Cross Target Application
    • don't press finish, but next
    • select hardware (ATMega 328P and 16 Mhz (16000000) for Boarduino)
    • finish
  • Open the properties of the newly created project
    • AVR / AVRDude: Select the programmer ("Boarduino")
    • under C/C++ Build/Settings (for both targets, Debug and Release)
      • under "Additional Tools in Toolchain" check only:
        • Generate HEX file for flash
        • Print Size
        • AVRDude (optional, directly uploads after compilation)
      • under AVR compiler
        • change command from "avr-gcc" to "avr-g++"
        • Directories: add "/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino"
        • Debugging: no debugging info
        • Optimization: size (-Os)
      • under AVR C++ compiler
        • change command from "avr-gcc" to "avr-g++"
        • Directories: add "/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino"
        • Debugging: no debugging info
        • Optimization: size (-Os)
      • under AVR C++ Linker
        • Add Library
          • Name: core
        • Add Library Path
          • Path: ${workspace_loc:/Blink/lib}   (if the project name is "Blink")
  • Open Arduino IDE and an example project
    • set your Arduino (in Tools/Board)
    • Click Verify/Compile in the toolbar while pressing shift
    • Extract the folder name from the log-panel (beginning with /var/folders/....)
    • copy the core.a from the folder into <eclipse-project>/lib/libcore.a
  • Compile the project in Eclipse


Notes:
you might have to define 
    extern "C" void __cxa_pure_virtual(void);
    void __cxa_pure_virtual(void) {}
in your projects main.
And also:
    #undef int
    #undef abs
    #undef double
    #undef float
    #undef round
if you get compile errors in math.h and several other system-files.


Versions used:
  • Eclipse 20100218-1602 (3.5 SR2)
  • AVR Eclipse 3.2.1
  • Arduino IDE 0018
  • CrossPack AVR 20100115

Good luck.