Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. 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.

Saturday, May 1, 2010

Searching a new IDE for Scala

Ever since I started trying and using Scala I used the nightly build of the Eclipse-Plugin. I was never really happy with it, it works fine for smaller projects but slows down to a crawl if used with larger projects. Also it has some annoying glitches with unit-tests (no support for scalatest and junit works sometimes and sometimes not), auto-completion, presentation compiler showing false errors and compilation.
Recently I started to lock up completely on certain code-fragments, forcing me to kill the process and restart Eclipse. Unfortunately it was "reproducible", so I actually had to (cosmetically) change some code I was trying to write in order to avoid to lockup. (Miles Sabin et al are doing a great work, it just needs some time, I really admire what they're doing)


That's why I started looking to alternative ways to code Scala. First I tried IntelliJ withthe  Scala-Plugin: Tried it, but didn't fall in love with it... I probably should've given it more time, but I was afraid, that it was going to have to same behavior as Eclipse (fine for small, bad for larger projects).


During surfing on the net I also found several posters, that really liked the sbt along with some text editor (some guys even pair it with an IDE), so I gave it a try. It does a great job at setting up your project and managing its dependencies (similar to maven, but easier).

Here's the scala/build/ScalaBase.scala (my project is named ScalaBase and uses the new cps-plugin of Scala 2.8):
import sbt._
 
class ScalaBaseProject(info: ProjectInfo) extends DefaultProject(info) with AutoCompilerPlugins {      
  val continuations = compilerPlugin("org.scala-lang.plugins" % "continuations" % "2.8.0-SNAPSHOT")
  override def compileOptions = CompileOption("-P:continuations:enable") :: super.compileOptions.toList
 
 
  val slf4j = "org.slf4j" % "slf4j-api" % "1.5.11"
  val logbackcore = "ch.qos.logback" % "logback-core" % "0.9.20"
  val logbackclassic = "ch.qos.logback" % "logback-classic" % "0.9.20"
 
  val scalatest = "org.scalatest" % "scalatest" % "1.0.1-for-scala-2.8.0.RC1-SNAPSHOT" % "test"
  val toolsSnapshot = ScalaToolsSnapshots
}

But what's really great: Start it up with
[~/scala/myproject] sbt
then type
~test-quick
and then edit your source files. As soon as you save a file it compiles all the affected classes and tests and then executes only the tests that were recompiled! This is great and gives you immediate feedback without stopping you from coding on. And it's really quick too (seems to take half the time of Eclipse-plugin to compile my code).

For more infos see the sbt documentation.