Square Thoughts

an engineering student's blog

Setting up CodeSourcery GNU Toolchain for the ARM in Eclipse Helios on Mac OS X 10.7 Lion

I was introduced to the open source integrated development environment Eclipse  by my friend Shan. Since then, I have shifted all my development routines for Arduino, Python and now ARM onto Eclipse. It is the best IDE I have used so far which supports almost everything, all programming languages, hardwares and toolchains.

The post is a simple walkthrough to making your first ARM project on Eclipse Helios on a Mac running OS X 10.7(the walkthrough is also applicable to previous generation OS X).

I am using Helios. Yes, it is old. A new version is already out. But some of the plugins we need to use, which I shall be explaining later in this post, still run on Helios.

The Basics

Eclipse CDT is a C/C++ development IDE based on Eclipse (which defaults to Java development).

CodeSourcery Lite is GCC-based ARM toolchain which provides all the basic ingredients (compiler, assembler, archiver, linker, libraries, newlib, binutils, etc.) in console based executables. The best thing about CodeSourcery is that they also offer commercial solutions which result in quarterly updates to the Lite tool-chain also. This way you always stay inline with the latest GCC developments.

First let’s have a look at the pre-requisites. You will need the latest version of Apple Developer Tools which include Xcode, Interface Designer, Instruments etc. and can be download from the Mac App Store. It is needed for the initial building of the toolchain which requires gcc, binutils and make. If you do not want to install the Developer Tools package, you will have to download and install these components individually. Google will help you.

Let’s start now.

Step 1 – Install Eclipse

Download and install the Eclipse IDE from http://www.eclipse.org. Eclipse Helios. The download page would provide you with a variety of flavors for the IDE. All of them are useful sometime or the other and can be ported to different versions using plugins. So go for the “Eclipse IDE for C/C++ Developers”. It would have all the functionality needed to set up the toolchain.

Step 2 – Install Eclipse Plugins – Fueling up Eclipse

This step involves adding the necessary plugins to Eclipse which are needed to successfully compile an ARM application.

  • Eclipse CDT
  1. Go to Help > Install New Software.
  2. In the dialog which appears, type “http://download.eclipse.org/tools/cdt/releases/helios” in the Work With text area.
  3. Press enter.
  4. You will get a window as shown below. Select both the choices and click on Next. Accept the license agreement and continue with the installation.
  5. Once the installation is complete, restart Eclipse.
  • GNU ARM Eclipse Plugin
This plugin is the link between your Eclipse IDE and your CodeSourcery toolchain which we will install in the next step. The plugin works only on Helios as of now. Once the compatibility with Indigo is achieved, the same steps can be followed for setting up the toolchain on it.
  1. Go to Go to Help > Install New Software.
  2. In the dialog which appears, type “http://gnuarmeclipse.sourceforge.net/updates” in the Work With text area.
  3. Press enter.
  4. You will get a window as shown below. Select all choices and click on Next. Accept the license agreement and continue with the installation.
  5. You will get an unsigned plugin notification during install. Click OK to continue with the installations.
  6. Once the installation is complete, restart Eclipse.

Step 3 – Install CodeSourcery

This step can be put as the most time consuming and mind boggling of the entire process. It took me more than 10 hours to get it working correctly. Thanks to James Snyder I was able to get it up and running in less than 30 minutes.

  1. Ensure again, you have the Apple Developer Tools installed.
  2. Point your browser to Snyder’s github.com project page.
  3. Click on the top right “Downloads” button and download the .tar.gz archive. This is isn’t the toolchain, but a very important makefile written by Snyder that can be used to conveniently build everything from sources, by automating all steps from downloading, compiling and installing the binaries.
The rest of the step is pretty straightforward. Just enter the terminal commands in the exact same order. If, for some reason, the build process fails at any step, restart again by using “make clean”.
  1. mkdir -p $HOME/Work/ – directory for saving all the downloaded content. This won’t contain the installed toolchain. Just it’s .tar archive.
  2. cp $HOME/Downloads/jsnyder-arm-eabi-toolchain-*.tar.gz $HOME/Work/ – copy the downloaded archive.
  3. cd $HOME/Work/
  4. tar xzvf jsnyder-arm-eabi-toolchain-*.tar.gz – extract the downloaded/copied archive.
  5. cd $HOME/Work/jsnyder-arm-eabi-toolchain-*
  6. sudo port install mpfr gmp libmpc texinfo – this will download and build the GMP and MPFR packages. It will take a few minutes for this step to complete.
  7. sudo make install-deps
  8. mkdir -p $HOME/arm-cs-tools/pin – create destination folder for the toolchain.
  9. export PATH=$HOME/arm-cs-tools/bin:$PATH – add the destination folder to the PATH variable. Be sure not to skip this step and step 8, otherwise the procedure will fail.
  10. make clean
  11. sudo CC=clang make cross-binutils cross-gcc cross-g++ cross-newlib – builds the final toolchain. It will take about 30 minutes for complete installation. 
  12. sudo make cross-gdb – builds and installs the debugger.
  13. Close Terminal.
These steps will help you successfully build and install the CodeSourcery toolchain. However, one final step, which is very important, is to set the environment variables to help UNIX know as to where you have installed your toolchain and from where it should pick up the compiler for ARM compilation. This can be achieved by making some changes to .bash_profile script. To do that:
  1. Open Terminal.
  2. Type “open .bash_profile”
  3. In the TextEdit windows which appears, add to the bottom of the text contents – export PATH=$HOME/arm-cs-tools/bin:$PATH
  4. Close the window.
  5. Logout from the Terminal.
  6. Restart Terminal.
  7. Type echo $PATH and in the variables which appear, /Users/<username>/arm-cs-tools/bin should be present.
  8. Another way to ensure you have successfully installed the toolchain and added it to your SYSTEMPATH is to type “arm-none-eabi-gcc –version“. You should get something like this.
arm-none-eabi-gcc (GCC) 4.5.1
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you are not getting this message, you have missed out some steps above. Delete the folder arm-cs-tools in your HOME folder and repeat Step 3 again.

Step 4 – Firing up Eclipse

Now that the plugins have been installed and the toolchain set up, it is time to write our first ARM code. But before that, one thing to note is that Eclipse doesn’t pick up its PATH variables from the bash directly or rather there is a flaw in Eclipse for Mac. It took me a while to figure this out. So the way out is to edit the proprietary $HOME/.MacOSX/environment.plist file. But an easer way out, is to start Eclipse from the Terminal directly. This way, the PATH we created in our .bash_profile script will be automatically added to Eclipse’s PATH variables. To do that,

  1. Open Terminal.
  2. Go to the directory where Eclipse was installed or its archive unpacked. In my case it was in the Applications folder, so I had to type “cd /Applications”. 
  3. Type “cd eclipse”
  4. Type “open eclipse”

And you will be presented by the ever beautiful, Eclipse IDE. Yes, it is beautiful.

Step 5 – Writing your first ARM Application

  • Open your workspace.
  • Go to File < New < C Project
  • Insert a Project Name. Select “ARM Cross Target Application” and chose “ARM Mac OSX GCC (Sourcery G++ Lite).
  • Click on Finish.
  • Go to File < New < Source File. And name it main.c
  • In main.c, type in a simple program which prints “Hello World”. Need not worry about this program working on your micro-controller. It is just to check if the toolchain is working fine.
#include <stdio.h>
int main()
{
printf(“Hello World”);
return 0;
}
  • Save the project contents.
  • Go to Project < Properties.
  • Click on C/C++build item and set:
    1. Builder Type : External Builder
    2. Check Use defualt build command
    3. Check Generate Makefiles automatically
  • Now click on the small triangle near the C/C++ Build item to view the subitems and then select Settings and set:
    1. Target Processor > Processor : cortex-m3
    2. Additional Tools : Uncheck Create Flash Image
    3. ARM Sourcery Mac OSX GCC C Linker > General. Uncheck all the boxes
  • Click on Apply, and press OK to close the Project Properties window.
  • Go to Project > Build Configurations > Set Active and chose Debug.
  • Go to Project > Build Project. This should compile and build project files for debugging of your project.
  • Go to Project > Build Configurations > Set Active and chose Release.
  • Go to Project > Build Project. Eureka! This should compile your project and build the .hex and .elf files which can be then uploaded to your micro-controller. If build of these files fails, you have not installed the toolchain properly or your PATH variables are incorrect.
Hope this post helps you setup your own ARM toolchain. I took to writing this post because I couldn’t find any which instructs on how to set up an Open Source ARM toolchain on a Mac and specifically on OSX 10.7. It took me a total of 36 hours to get this toolchain working. Why not use KEIL instead? First reason, it is paid and my lab doesn’t allow me to use pirated software. Second, I cannot purchase it. It is $1500 for a single user license. Why pay such a price when you can get all those features for free. All Hail the Open-Source!
Do leave a comment if this post helped you.

Single Post Navigation

12 thoughts on “Setting up CodeSourcery GNU Toolchain for the ARM in Eclipse Helios on Mac OS X 10.7 Lion

  1. harshit jain on said:

    good work!

  2. Wow! Great information! Just need to try it out now!

  3. Pingback: FatFs Library Port for Stellaris EK-LM3S811 Evaluation Board « Square Thoughts

  4. digital_dreamer on said:

    Thanks for this install info for Lion!

    If anyone is/was having trouble with the sudo make install-deps command failing during the curl operation, I found that changing the URL in the makefile fixes the issue:

    Original:

    SOURCE_URL = https://sourcery.mentor.com/sgpp/lite/arm/portal/package8733/public/arm-none-eabi/$(LOCAL_SOURCE)
    BIN_URL = https://sourcery.mentor.com/sgpp/lite/arm/portal/package8734/public/arm-none-eabi/$(LOCAL_BIN)

    Change to:

    SOURCE_URL = https://sourcery.mentor.com/public/gnu_toolchain/arm-none-eabi/$(LOCAL_SOURCE)
    BIN_URL = https://sourcery.mentor.com/public/gnu_toolchain/arm-none-eabi/$(LOCAL_BIN)

    Speaking of which, I notice this sudo make install-deps command is not mentioned in the README file at GitHub. Is this an omission or no longer needed if one follows the README? I assume (now) that the README is the more updated version?

    Thanks for all your work!
    Although I’ve been bash scripter for years and come from the 8-bit micro days (z-80, 6502, 6809, etc. assembly and machine code), this C/C++ compiling stuff with IDEs is very new to me. Plus, I’m getting my feet wet with ARM MCUs. Fun! 🙂

    best of wishes,
    MAJ

  5. Now it only I can get this working on Ti Stellaris …

  6. Pingback: Setting up CodeSourcery GNU Toolchain for the ARM in Eclipse | Sayyed Mohsen Zahraee

  7. Yogendra on said:

    Thanks. Everyone may like to hear from you on setting up debugger as well 🙂

  8. Seasoned Google Plus pros would like your blogs. I will bookmark this website. I enjoyed reading this.

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

%d bloggers like this: