This is a sequel to my previous article Getting Started with the Olimex SAM7-P256. Flashing lights are all very well but I want to add a C library so I can use functions like printf().
There is a streamlined version of the standard C library available for embedded systems called newlib which you can download from the files section at http://www.gnuarm.com/. Here’s how you build it to fit in with the toolchain in my previous article:
First you need to have makeinfo. On Ubuntu, install it like this:
sudo apt-get install texinfo
Now we can build and install the library:
tar xzvf newlib-1.14.0.tar.gz mkdir build-newlib cd build-newlib ../newlib-1.14.0/configure --target=arm-elf --prefix=/usr/local/arm7 sudo make all install info
Documentation for newlib can be found at http://sourceware.org/newlib/.
Now we have a C library, how about writing Hello World! That was not as easy as it sounds, mainly because I wanted printf() to send its output to the serial port. It took me a lot of documentation-reading and hair-pulling to work out how to do that.
To redirect STDOUT, you need to override the syscalls.o module which is part of libc. Copy the syscalls.c and swi.h files from the newlib source into your project directory and modify the _write() function to send its data to the serial port.
I’ve got some example code to demonstrate this. You can download it by clicking the link here:
I’ve tried to keep the code as simple and readable as possible. I’ve also included a couple of shell scripts to make it easier to download and run the code. Here is how you would compile and run it:
tar jxvf ArmHelloWorld.tar.bz2 cd HelloWorld make ./startarm
Next you need to connect a serial cable and start up a serial terminal on your PC at 9600,n,8,1. Once that is running, launch the example code by typing this:
If all goes well, you should see “Hello World.” appear on your serial terminal.
If not, well then happy debugging !
UPDATE: Dan Ashbrook kindly pointed out that my port assignments for the 2nd serial port are incorrect in Board.h. I have now corrected the file, you can download it here: ArmHelloWorld.tar.bz2
UPDATE: I recently tried to do this on Ubuntu 8.04 and it didn’t work until I applied this patch to the newlib configure script.