Getting Started with the Olimex SAM7-P256
I recently bought a SAM7-P256 microcontroller kit from Olimex. It’s a nice little board but it was quite a challenge to get something running on it. All the information I could find was either a) for experienced ARM programmers, b) for completely different ARM variants or c) for Windows users.
I am an experienced C programmer but I have no ARM experience. What I really wanted was a fairly straightforward step-by-step guide to getting something simple running for this particular board using a cross-compiler on Linux. I guess I’ll have to write it myself.
So here is my simple step-by-step to get you up and running with a simple blinking LED program using free tools.
Summary
Here is what we’ll be doing:
- Build a toolchain (assembler, C compiler and linker) on a Linux PC.
- Obtain header files specific to the Atmel chip and Olimex board.
- Create the C runtime environment so we can run a C program.
- Create a simple C program and compile it.
- Download the compiled code via USB into the board’s RAM and run it.
Note that I will not be covering how to load a program into flash memory or how to load an operating system onto the ARM.
STEP 1 - Create the GCC toolchain
We’ll be using GCC as our cross-compiler. I found a good step-by-step on setting up GCC for ARM here which I will now summarise.
First you need to visit http://www.gnuarm.com/, go to the files section and download the latest source code for gcc and binutils. I am using binutils-2.17 and gcc-4.1.1 for my example.
Unpack and compile binutils first using the following commands:
tar jxvf binutils-2.17.tar.bz2 mkdir build-binutils cd build-binutils ../binutils-2.17/configure --target=arm-elf --prefix=/usr/local/arm7 sudo make all install
Next set the path to include the new binutils.
export PATH=$PATH:/usr/local/arm7/bin
I also put this line into my ~/.bashrc so the tools are always available. Now we can unpack and compile:
tar jxvf gcc-4.1.1.tar.bz2 mkdir build-gcc cd build-gcc ../gcc-4.1.1/configure --target=arm-elf --prefix=/usr/local/arm7 --enable-languages=c --with-newlib sudo make all-gcc install-gcc
If all that worked, you will now have the following useful programs installed in /usr/local/arm7/bin:
| arm-elf-as | - Assembler |
| arm-elf-gcc | - C compiler |
| arm-elf-ld | - Linker |
| arm-elf-objcopy | - Utility to convert ELF binary into a raw binary or HEX image |
STEP 2 - Download example files
Download and unpack my example files ARMBlinkExample.tar.bz2, you will see the following files:
| AT91SAM7S256.h | - Definition of the ARM chip and on-chip peripherals. |
| SAM7-P256.h | - Definition of additional peripherals on the Olimex board. |
| Makefile | - Makefile used to compile and link blink.c |
| ram-ln.cmd | - Linker options. Defines the memory areas we can use. |
| ram-crt.s | - C runtime code written in assembly language. |
| blink.c | - The blinking LED example program written in C. |
Please take some time to read through these files or you will not learn anything! The best place to start reading is the Makefile.
I have tried to make this code as simple and easy to follow as I can.
STEP 3 - Connect the board
Now it is time to plug the board into your USB port. Once plugged in, you will need to establish communication with it. There is an excellent free program called Sam_I_Am which provides a good front end. You can download it from http://claymore.engineer.gvsu.edu/~steriana/Software/.
Once unpacked, install it with the following command:
sudo python setup.py install
You will also need a configuration file. I have included one in my example files. Copy it to your home directory:
cp <path_to_example_files>/.samiamrc ~/
Now we need to set up the USB port. Type this command:
sudo modprobe usbserial vendor=0x3eb product=0x6124
Cryptic, you bet. But you need to do this to get Linux to detect the Olimex board. If this is successful, the board will be mapped to device /dev/ttyUSB0 (unless you have other USB serial devices in which case it will have a different number and you will need to modify ~/.samiamrc appropriately).
You should now be able to run Sam_I_Am and test it by typing the version command as in this example:
$ Sam_I_Am >version v1.4 Nov 10 2004 14:49:33
NOTE: If your SAM-BA is not working because you have overwritten it by trying to download to the Flash memory, there are some instructions for restoring it here.
STEP 4 - Compile and download the example program
The blink example is intended to be loaded into RAM (not Flash memory). The SAM-BA bootloader has already set up the chip for us so my crt.s code is much simpler than you would find in a production application. There is also no operating system or even a C library! This is real basic stuff.
So now we can compile the example code:
make
This will spit out a file called blink.hex which is in the Intel HEX format that Sam_I_Am requires. Next we can use Sam_I_Am to download it to the board and run it. Use the send command to download the HEX file to RAM and then use the go command to run it as in this example session:
$ Sam_I_Am v1.4 Nov 10 2004 14:49:33 >send blink.hex 0x00202000-0x00202147: 328 bytes Start Address: 0x202000 >go 202000 >exit
You should now have some blinking LEDs, woohoo!
There is no function in this simple example to exit back to SAM-BA. You will need to press the board’s reset button. I found that when you do this, Linux will re-map the serial port to /dev/ttyUSB1 which was a bit confusing the first time. The trick is to wait a second or so and then press reset again. It will re-map back to /dev/ttyUSB0.
I hope this tutorial has been useful to you and that the example code provided can make a good starting point for your own embedded applications. If you have any comments, please post them below.
UPDATE
I now have a step-by-step on how to add on a standard C library. Click here.

CodeSourcery provides free ARM toolchains at http://www.codesourcery.com/gnu_toolchains/arm. You may want to try those out instead.
Excellent work!
I have one of these boards coming some time this week, and was wondering what to do about getting started with my Linux box (I knew about gnuarm, didn’t know about the SAM-BA for Linux).
Have you tried anything with the JTAG yet?
Ricardo: I tried that toolchain. It builds my example code just fine. Plus it includes a C-library which might be useful when my programs get more sophisticated.
Steve: I don’t have a JTAG interface device so SAM-BA is my best option right now.
Hi Adam– when I tried to install the gnuarm gcc compiler, I got a whole bunch of errors (looks like this has something to do with cross compiling, but I have no idea what’s going on…) I was able to install the binutils, just not the gcc… do you know what I might do to fix this?
Thanks,
Steve
[...] This is an addition to my previous article Getting Started with the Olimex SAM7-P256. I want to add a C library so I can use functions like printf. [...]
Oops, sorry Steve, I didn’t notice your post there. Sorry for the delay in responding.
It is important to run the make install commands with root privileges. I use the sudo command for this. If that doesn’t work for you, try “sudo -s” or “su” to elevate your authority.
Another possible problem might be forgetting to set your PATH so that the binutils are available to the gcc build scripts. You can test this is set correctly by typing arm-elf-as –version. If it says “Command not found”, you probably have a PATH problem.
Hallo,
thank you for your tutorial. I was trying to complie the files using gnu under eclipse Environement in windows, the project compiles fine and I got a hex file. But unfortunately, it did not work ! Do you have any information which you may provide about using exlipse environment for the project.
sincerely,
peter
If you got a HEX file, I’d say that compile and link stages are probably working. Perhaps you are not correctly downloading the HEX file into the ARM. Have a look at the manual for whatever utility you are using for that.
I’ve never used Eclipse so I can’t really help there. Try reading Jim Lynch’s tutorial which walks through the process of developing for ARM in Eclipse under Windows. You can download it from the Atmel website here:
http://www.atmel.com/dyn/resources/prod_documents/atmel_tutorial_source.zip
Hi!
We are using philips lpc2148 in school, and it’s all working fine under windows, but i want to use it in linux, ofcourse :)
The first parts of your guide are just what i’ve been loking for (great guide btw!). My problem is with “sam”.
The “sudo modprobe usbserial vendor=0×3eb product=0×6124″ command will probably be different for my board, am i right? It is connected with a usb -> com connector, at USB0.
Do you know if i could use the same numbers as you, and if not, the correct numbers for my lpc2148, or where i could find them?
Sincerely
Pinky
You will not need to bother with the modprobe or vendor and product IDs if you are using a USB->RS232 adapter, Linux should sort it out for you as long as it is a supported adapter. Try using the lsusb command to verify that your USB device is connected. If so, it should be accessible via /dev/ttyUSB0.
The “SAM” utilities will not work on the LPC2148. They are specific to the AT91SAM range of chips. You will need to find some other utility which supports your chip.
I did a Google search and found a utility called lpc21isp which sounds like what you want. See this link:
http://pygmy.utoh.org/riscy/bootloader.html
Good luck with your project.
I had given up for a while on this, I couldn’t get the precompiled binaries to work, and was having trouble compiling the gnuarm toolchain. My old windows laptop bit the dust a while back and I was on the verge of quitting windows for good at that point, so I didn’t even bother with the windows toolchains. I finally decided to sit down and give it a try again today, and it turns out I was able to get it to work by doing the whole process as root (I just did su instead of sudo).
Now I have blinking lights and I can finally get around to figuring out some stuff about this ARM, which I have put off for far too long.
Nice tutorial for sure!
Thanks a lot for this tutorial — I’m working the smaller version of this Olimex board, but your instructions were invaluable in giving me a clear outline of the issues.
The “Click Here” link under “Update” is broken, tho.
Thanks for the great step by step approach for getting started in atmel based board, i have just got hold of AT91SAM9 based board from http://www.oasistechsol.com
since this is Atmel ARM9 i guess the steps you have mentioned will also be applicable for me
-praful
I had to do this on my Ubuntu 08.04 box to get this to work:
add to the bottom of your .bashrc file this line:
alias sudo=”sudo env PATH=$PATH”
Otherwise the PATH variable inside the sudo command didn’t include /usr/local/arm7/bin, so when making arm-elf-gcc it was bombing out being unable to find arm-elf-ar, among other things. Perhaps there is a more elegant way to preserve environment variables than doing the alias line above, but if so I don’t know it. I read a pretty fiery debate among the Ubuntu crowd about this, with the parting shots seeming to imply that you need to do the alias above in order to inherit environment variables from the user account when running in sudo. But again perhaps I’m missing a simpler solution.