LPC2103 tutorials: toolchain


I use GNU toolchain. Because the amount of memory available is very low, I do not use any kind of C library (if you know what newlib is — no newlib).

Below I will describe how to compile on Linux host GNU cross-toolchain.

0. Requirements

Host compiler

Before you can do any compilation on your host computer, you need normal (not cross) toolchain installed. It is available for all Linux distributions but you may need to install it from the package. For Debian and Ubuntu the simplest way is to install “build-essential” package with the following command:

sudo aptitude install build-essential

if you have “sudo” installed and setted up; otherwise use

aptitude install build-essential

as a root user.

Libraries to compile GNU C

To compile GNU C, you will need also libgmp and mpfr installed; on Debian system install development packages with the command

sudo aptitude install libmpfr-dev libgmp3-dev

[Possible] optimization

According to GNU toolchain documentation, the compiler will be able to do optimizations better if you have libppl and cloog installed; I do not know if it affects ARM target but nevertheless:

sudo aptitude install libppl0.10-dev libcloog-ppl-dev

1. Installing binutils

We will start with compiling binutils: the set of utilities tightly related to compilation process. Most notable of those are the GNU linker (“ld”) and the GNU assembler (“as”).

Obtaining binutils

The GNU binutils home page is http://www.gnu.org/software/binutils. You can download the source code of the latest release here: http://ftp.gnu.org/gnu/binutils. Get .tar.bz2 archive of the latest version (at the moment the latest one is binutils-2.19.tar.bz2).

Create some directory where you will do the compilation: I use directory src in my home directory:

mkdir ~/src

Change to that directory and unarchive binutils:

cd ~/src && tar xvjf path/binutils-2.19.tar.bz2

Here path is the path to the archive you’ve downloaded.

Configuring binutils

Before you proceed, create some directory to install new toolchain to:

sudo mkdir -p /opt/LPC2103

Add directory where you will have binaries installed to your PATH:

export PATH=$PATH:/opt/LPC2103/bin

You may want to add this line to your .bash_profile file, so you will not need to enter it manually in the future.

Change to the directory when you have binutils sources and run “configure” script with the following parameters:

cd ~/src/binutils-2.19

./configure --prefix=/opt/LPC2103 --target=arm-elf

Here /opt/LPC2103 is the directory where you will install toolchain to, and --target=arm-elf is self-explanatory.

Compiling and installing binutils

To compile binutils, run


When the compilation is over (there should not be any errors), install the compiled software

sudo make install

Check that everything is fine:

arm-elf-as --version

You should see something like this:

GNU assembler (GNU Binutils) 2.19
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `arm-elf'.

2. Installing GNU C compiler

Obtaining GCC sources

The home page of GCC is http://gcc.gnu.org. You need to download th sources from one of the mirror sites (search home page for “Download”). Get the latest version of -core .tar.bz2 archive (you do not need other files). At the moment of writing, the lastest version is gcc-core-4.3.2.tar.bz2.

Go to your directory with the sources and unarchive gcc:

cd ~/src && tar xvjf path/gcc-core-4.3.2.tar.bz2

Here path is the path to the archive you’ve downloaded.

Patching GCC sources

You will need to do one small change in the sources. Go to directory gcc/config/arm

cd ~/src/gcc-4.3.2/gcc/config/arm

and edit t-arm-elf file using your favourite text editor. You need to find the following lines:

# MULTILIB_OPTIONS    += mno-thumb-interwork/mthumb-interwork
# MULTILIB_DIRNAMES   += normal interwork

and uncomment them:

MULTILIB_OPTIONS    += mno-thumb-interwork/mthumb-interwork
MULTILIB_DIRNAMES   += normal interwork

Configuring GCC

First you have to create separate directory to compile GCC in. You cannot compile GCC in it’s source directory.

mkdir ~/src/gcc-objdir

Change to this directory and configure GCC:

cd ~/src/gcc-objdir

../gcc-4.3.2/configure --srcdir=../gcc-4.3.2 --prefix=/opt/LPC2103 --target=arm-elf --with-cpu=arm7tdmi-s --with-float=soft --disable-threads --disable-libssp --enable-interwork --enable-thumb --enable-multilib --enable-languages=c

Most of the options are self-explanatory. LPC2103 has no FPU, so you need to specify --with-float=soft. Options --enable-thumb and --enable-interwork will turn on support for thumb instruction set and thumb interworking. Option --enable-multilib means that you will get four versions of GCC internal libraries compiled: ARM, ARM with interworking support, thumb, and thumb with interworking support. The only language you want is C, so --enable-languages=c.

Compiling and installation

Compile GCC with


(there should be no errors) and install with

sudo make install

Checking if C compiler works

Let's check if C cross-compiler works. Create somewhere file hello.c with one empty function:

int hello()
Compile it with the following command:

arm-elf-gcc -c -o hello.o hello.c

Now run file hello.o. You should see something like

hello.o: ELF 32-bit LSB relocatable, ARM, version 1, not stripped

Run arm-elf-objdump -d hello.o to see the disassemled code. It will look like this:

hello.o:     file format elf32-littlearm

Disassembly of section .text:

00000000 :
   0:	e1a0c00d 	mov	ip, sp
   4:	e92dd800 	push	{fp, ip, lr, pc}
   8:	e24cb004 	sub	fp, ip, #4	; 0x4
   c:	e24dd004 	sub	sp, sp, #4	; 0x4
  10:	e89da808 	ldm	sp, {r3, fp, sp, pc}

You can see ARM 32-bit assembly. Now let's test if thumb works. Compile the same hello.c with the command

arm-elf-gcc -c -mthumb -o hello-thumb.o hello.c

and dissassemble the result with arm-elf-objdump -d hello-thumb.o. Now you should see 16-bit thumb assembly:

hello-thumb.o:     file format elf32-littlearm

Disassembly of section .text:

00000000 :
   0:	b580      	push	{r7, lr}
   2:	b081      	sub	sp, #4
   4:	af00      	add	r7, sp, #0
   6:	46bd      	mov	sp, r7
   8:	b001      	add	sp, #4
   a:	bd80      	pop	{r7, pc}

You can repeat these two experiments adding to the compilation command --mthumb-interwork option; you will see that the code has changed.

Now you can compile something for your board. Next step is to be able to load it to the board.

Search this site


Creative Commons License
This work by Alexey Vyskubov is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.