Building the ArduPilot APM2.x firmware with Eclipse on Windows (for real)

A few years ago, I wanted to start a professional UAV business. I did some tests with the Multiplex EasyStar II as a rather unexpensive and easy to fly R/C plane and after it went quite well (which shall be covered in another post), I started buying some more fancy equipment along with an APM2.5 from diydrones.com.

The EasyStar II with a FlyCamOne and a Wii Nunchuk to control the camera head

The EasyStar II with a FlyCamOne and a Wii Nunchuk to control the camera head

The APM is an open source autopilot board based on the AVR Atmega2560. It was supposed to do the flying, so I could have concentrated on other tasks.

diydrones APM2.5 Autopilot Board

diydrones APM2.5 Autopilot Board

As life went a different direction (but definitely not south ;o) ), the UAV thing never happened(, yet).

Just recently I found the board in my drawer and I wanted to use it in a HIL setup together with FlightGear. The firmware for the board has become quite complex since the last time I looked at it, so I wanted to use Eclipse as the IDE instead of the Arduino IDE. It took a while to find the latest and greatest firmware for the board, though, since diydrones has discontinued the AVR based APM. While their page had some not so clear infos on which software version was the most recent and final one that would still run on the Atmega, I somehow found it was V3.4.0. After downloading and importing the package into Eclipse and trying to compile the code, all I got was a bunch of error messages and none of the pages I found about the topic had a real solution…

Long story short, here is how I made it work:

  1. Download ArduPilot-Arduino-1.0.3, basicly a customized Arduino IDE
  2. Download ArduPlane-release-AVR
  3. Unzip 1) to a folder that has no spaces in its name. (Actually we are only interested in the WinAVR package inside (ArduPilot-Arduino-1.0.3-windows\hardware\tools\avr\), so it would be sufficient to unzip that part to a folder that has no spaces in its name and forget about the rest.) Note that the no-spaces rule does apply to the parent folders, too!
  4. Unpack 2) anywhere you want, preferably to your project folder.

I happened to put 1) on the desktop (it wasn’t going to stay long) and 2) inside 1)

Inside the package of 2), there is a folder named “mk”. It contains some *.mk files, which are being used by make and are referring back and forth to each other, since they try to cover all kinds of OSes and setups. You have to edit three files:

  • environ.mk:
    – Anywhere before line 32 (preferably right before it) enter the following:
    SKETCHBOOK := ..
    This will help the compiler find the libraries
    – At line 107 (which was 106 before adding the line above), change the line as following:
    BUILDROOT := build
    This will put the compiled files into a folder named “build” inside the same folder as the firmware that you are trying to compile (ArduCopter, ArduMrover2 or ArduPlane).
  • find_tools.mk:
    – Change line 27 to
    TOOLPATH := <path to the avr/bin/ of 1)>
    This will help make find the right compilers
    Note that the backslashes need to be normal slashes!
  • board_avr.mk:
    – Comment out lines 77 – 85 by adding a # in front of each line to avoid some unnecessary error messages
    – Change lines 88 to 91 to
    MCU := atmega2560
    F_CPU := 16000000L
    HARDWARE_CORE := arduino
    UPLOAD_SPEED := 115200
    – Change line 109 to
    UPLOAD_PROTOCOL := wiring

Now you can import the package to Eclipse

  • Create a new project
  • Choose “C/C++ – Makefile Project with Existing Code”

    Create a new C/C++ project, "Makefile Project with Existing Code"

    Create a new C/C++ project, “Makefile Project with Existing Code”

  • Choose “<none>” as Toolchain

    Since we are going to use the customized WinAVR, chose "" as toolchain

    Since we are going to use the customized WinAVR, chose “” as toolchain

  • Create a new target called “apm2”
    Create a new target for the project...

    Create a new target for the project…

    Name the target "apm2"

    …and name it “apm2”

While building the firmware should already be working fine, the intellisense of Eclipse would still need a few infos to work correctly:

  • In the project properties, C/C++ General, Paths and Symbols, add the path to the “libraries” folder inside of 2) to the GNU C and GNU C++ settings
  • Same for the “avr/include” and “lib/gcc/avr/4.8.2/include” folders inside of 1)
Add some include paths for intellisense

Add some include paths for intellisense

There would still be some issues for the intellisense for the files
– ArduPlane.cpp
– GCS_Mavlink.cpp
– Plane.cpp
– Plane.h
– system.cpp
but the code would still compile fine.

Advertisements

About Michael Melchior

Husband, Father, computer scientist, commercial helicopter pilot. Full of ideas and open minded, I try to see challenges in what others call problems.
This entry was posted in Projects, UAV and tagged , , , , . Bookmark the permalink.

2 Responses to Building the ArduPilot APM2.x firmware with Eclipse on Windows (for real)

  1. Pavol Sestak says:

    Hi Michael,
    I tried your way to make APM2 AVR on my windows but have not success yet. Build process always gives me error, here is output from console window in eclipse:
    make apm1
    d:/APM/AntennaTracker-0.8.0/mk/environ.mk:22: your realpath function is not working
    d:/APM/AntennaTracker-0.8.0/mk/environ.mk:23: > setting SRCROOT to d:/APM/AntennaTracker-0.8.0/AntennaTracker
    cygwin warning:
    MS-DOS style path detected: d:/APM/AntennaTracker-0.8.0/AntennaTracker
    Preferred POSIX equivalent is: /cygdrive/d/APM/AntennaTracker-0.8.0/AntennaTracker
    CYGWIN environment variable option “nodosfilewarning” turns off this warning.
    Consult the user’s guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
    /cygdrive/c/cygwin/bin/rm: too few arguments
    Try `/cygdrive/c/cygwin/bin/rm –help’ for more information.
    make: *** [build/make.flags] Error 1

    **** Build Finished ****

    Guess make calls cygwin/rm for some purpose, but it is not supplied with correct arguments. Can’t find it in any mk file.
    What version of cygwin do you have?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s