Building a Stellaris GCC Toolchain on Linux using crosstool-ng

I’m currently working with the Stellaris EKI-LM3S9B90 board from TI which is based on a Cortex M3 Core from ARM.This means you can use standard tools like GCC instead of the buggy IAR IDE.This also means you are not longer bound to Windows and can use Linux and your favourite editor or IDE.

In this blog I’ll explain how to build your own GCC toolchain to cross-compile your application for the LM3S9B90 target.We will build the toolchain using crosstoll-ng, which is really easy and use OpenOCD (Open On-Chip Debugger) to flash and debug our device.

The following instructions are for Gentoo Linux, but it should be easy to apply these instructions also for othe Linux distributions. However Gentoo has all developer tools pre-installed because Gentoo itself is build from source. On other distributions you will most likely need to install a lot of devel packages first. See this TI Article for more information.I wrote this blog based on this information.

Now lets start …

# enter your working directory (change this to whatever path you like)
cd ~/work
#######################
# install crosstool-ng
#######################
wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.9.3.tar.bz2
tar -xvjf crosstool-ng-1.9.3.tar.bz2
cd crosstool-ng-1.9.3
./configure
make
sudo make install
###########################
# creating the toolchain
###########################
cd ~/work/arm-eabi
# copy sample configuration file from crosstool-ng
cp ~/work/crosstool-ng-1.9.3/samples/arm-bare_newlib_cortex_m3_nommu-eabi/crosstool.config .config
# (optional) adapt config using menuconfig: I increase the number of parallel jobs to 8
# because I'm running on a Intel Core i7
# With this setting I was able to build the toolchain in 4min 19s ;-)
ct-ng menuconfig
# now build the toolchain
ct-ng build
# you can find the built toolchain  in ~/x-tools/arm-bare_newlib_cortex_m3_nommu-eabi/bin

#################################
# install OpenOCD using portage.
#################################
# The package is still masked so we must unmask it first.
echo "dev-embedded/openocd ~amd64" > /etc/portage/package.keywords/openocd
echo "dev-lang/jimtcl ~amd64" >> /etc/portage/package.keywords/openocd
# We configure it to use FTDI
echo "dev-embedded/openocd ftdi" > /etc/portage/package.use/openocd
# now install it using emerge
emerge openocd -av

#########################################
# Prepare the ARM toolchain environment.
#########################################
# I don't want to add the settings to my ~/.bashrc,
# because I'm working with different toolchains. I prefer creating an own script which easily allows me to configure
# each shell with a different toolchain by sourcing this script.
# So lets create this script:
echo "export PATH=/home/$USER/x-tools/arm-bare_newlib_cortex_m3_nommu-eabi/bin:$PATH" > ~/arm-env.sh
echo "export LD_LIBRARY_PATH=" >> ~/arm-env.sh

# Now lets load these settings
. ~/arm-env.sh

###############################################################
# Building the StellarisWare Software using the new toolchain.
###############################################################
# The installation CD from TI only contains a Windows setup SW-EK-LM3S9B90-6288.exe
# but this is mainly a self-extractiong ZIP file, so unpacking on Linux works fine.
cd ~/works
mkdir StellarisWare
cd StellarisWare
cp /media/TI_SOFTWARE_DOC/Tools/StellarisWare/SW-EK-LM3S9B90-6288.exe .
unzip SW-EK-LM3S9B90-6288.exe
rm SW-EK-LM3S9B90-6288.exe
# edit Makedefs and change the PREFIX in line 54 to
PREFIX=arm-bare_newlib_cortex_m3_nommu-eabi
# now build it
make clean all

#####################
# The StellarisWare contains some nice examples. So lets try to flash one using OpenOCD.
# The examples are in the subfolder boards/ek-lm3s9b90
# The build process creates the subfolder gcc for each project which contains the binary.
# Lets try to load the qs-adventure example.
# I copy the binary to /tmp so that I don't have to type so long paths later on.
cp ~/work/StellarisWare/SW-EK-LM3S9B90-6288/boards/ek-lm3s9b90/qs-adventure/gcc/qs-adventure.bin /tmp

#####################
# Starting OpenOCD
# again I create a script which simplifies starting OpenOCD later on
mkdir ~/Stellaris
cd ~/Stellaris
echo "#!/bin/bash" > openocd.sh
echo "sudo openocd -f /usr/share/openocd/scripts/interface/luminary-icdi.cfg -f /usr/share/openocd/scripts/target/stellaris.cfg" >> openocd.sh
chmod 700 openocd.sh
# now lets start it
./openocd.sh

#####################
# Now start another terminal and connect to OpenOCD using telnet
telnet localhost 4444
> halt
> flash write_image erase /tmp/ qs-adventure.bin 0x0000
> reset
> exit

# Now have fun with your adventure game ;-)
Advertisements

1 Response to “Building a Stellaris GCC Toolchain on Linux using crosstool-ng”


  1. 1 Cyril November 23, 2012 at 3:19 pm

    Hi Gerhard,

    Thank you very much for this brief howto to get up and running with cortex-m3s.
    I have one small issue with Cortex-M4 support in the stellaris-ware.

    When I ‘make all’ within my stellaris dir, I get an error saying:
    adc.c:1: error: bad value (cortex-m4) for -mcpu= switch
    adc.c:1: error: invalid floating point option: -mfpu=fpv4-sp-d16

    Of course I can just comment out the m4 part in each library’s Makefile. Because I don’t need cm4 support as of now.
    Would I have to build another ct-ng (with hardware floatingpoint support) tuned for cm4f to be able to build the cm4 examples?
    How did you fix this?

    I greatly appreciate your answer.
    Best regards,
    Cyril


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: