Getting Started with the Olimex SAM7-P256

sam7-p64-smaller.jpg 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:

  1. Build a toolchain (assembler, C compiler and linker) on a Linux PC.
  2. Obtain header files specific to the Atmel chip and Olimex board.
  3. Create the C runtime environment so we can run a C program.
  4. Create a simple C program and compile it.
  5. 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 --disable-werror --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 -s
make all-gcc install-gcc
exit

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.

24 thoughts on “Getting Started with the Olimex SAM7-P256

  1. 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?

  2. 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.

  3. 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

  4. 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.

  5. 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

  6. 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

  7. 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=0x3eb 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

  8. 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.

  9. 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!

  10. 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.

  11. 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

  12. 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.

  13. I just tried to go through this procedure in the new Karmic Ubuntu 9.10. I had to add –disable-werror to the binutils build to make it work due to the stricter gcc compiler included with Ubuntu these days. I’ve just modified my original post to include this change, it should not affect compilation on older compilers.

  14. I am using an Olimex sam7s256 board. I tried to get it up and running in linux (Ubuntu). I was able to successfully install GCC and binutils. I installed SAM-BA for linux from the atmel site. I was able to get the USB port for connection as specified in the SAM-BA manual (.dev/ttyUSB0). But when I try to use the GUI and ‘connect’ there is no response. I though that there is a connection failure, so when I presses the reset button in the board, I get a message “Failed to initialize FLASH accesses”. No matter how long I wait before pressing the reset button, I am not getting any SAM-BA window as expected.
    can any you help me out in this? I did the ‘tst’ jumper set, reconnect the board for 10 s, disconnect and ‘tst’ jumper reset, reconnect before opening SAM-BA. Any help will be greatly appreciated. I am stuck. It is the same for both SAM-BA 2.9 and 2.7, 2.8.

  15. Hi krish, It could be that Linux has assigned the board to a different port. Try the following command to list all available ports:

    ls -1 /dev/ttyU*

    Maybe try that command with the board unplugged and then again after the board is plugged in to see which new port appears.

  16. Hi Adam,
    Actually I was trying to use the SAM-BA GUI for atmels sam7s256 EK board. I combined your procedures for installation of binaries and tool chain with flashing the kit using SAM-BA and confused ur explanation of SAM- boot assistant with the SAM-BA gui for linux. Some say that we need to install the SAM-BA gui and use the atmel board option and it automatically works for the Olimex board. I doubt it b’cos it dint for me.
    Anyway I downloaded the Sam_I_Am and was very happy to see it connect with the board in /dev/ttyUSB0.
    I tried to download ur led blink program from the link you have provided. I copied the .samiamrc file to my home folder. When I run the ‘make’ I get the following error,

    arm-thumb-elf-ld -v -Map blink.map -Tram-ln.cmd -o blink.elf crt.o blink.o
    GNU ld (GNU Binutils) 2.18
    arm-thumb-elf-ld: error: no memory region specified for loadable section `.text.1′
    make: *** [blink.elf] Error 1

    I have given the name arm-thumb-elf-ld for my linker so you can ignore it. I am not getting the source of the error. Actually I dont know what it means by ‘.text.1′ and where is that memory area located?
    Can you explain the problem. If the LED blinking works I can be kind of sure that my board is workable in Linux environment.
    Thanks a lot for your prompt reply the last time.

    Krish.

  17. Memory regions such as .text and .data are defined in the linker script. I’d guess this problem is because of a different version of GCC than the one I used originally. The GCC people are a real pain and like to change the rules and break everyone’s code with each new release.

    To solve it, either define a new segment called .text.1 in the linker script (that’s the file called ram-ln.cmd) or see if you can use an older version of gcc.

  18. I dont know how to add a region for .text.1 . I am totally new to this.
    Anyway as you told I downgraded my binutils to 2.17 and gcc to 4.1.1 and I am seeing BLINKING LEDS!!!!!
    thanks a lot for the help…
    If you know how to include a .text.1 please let me know.
    Anyway thanks a lot for ur help…
    Bye..

  19. Also when people try to install the bin-utils or GCC they might encounter an error when doen “make all install” b’cos of the error due to texinfo version number in the recent ubuntu installations texinfo installations.
    It can be solved by adding the patch for the binutils and GCC, which I am not sure how to do (involves recompilig and tarballing the original with the patch).
    I did the other way around after the ../configure… command open the ‘configure’ script in gedit or any editor and search for the sentence starting with this term
    “| egrep ‘texinfo[^0-9]”
    and you will find the line
    “| egrep ‘texinfo[^0-9]*([1-3][0-9]|4\.[4-9]|[5-9])’ >/dev/null 2>&1; then”
    change it to,
    “| egrep ‘texinfo[^0-9]*(4\.([6-9]|[1-9][0-9])|[5-9]|[1-9][0-9])’ >/dev/null 2>&1; then”
    and then run the installation.

    The solution can be found in this webpage,
    http://sourceware.org/ml/binutils/2007-09/msg00240.html

    bye.

  20. Hi Adam,
    Thank you for the inlighting example. However i tried but it didn’t work. I used the olimex blink.bin to verify my flash writing operation and it was ok. i kept digging in to it, i traced it and found that when you call main, it returns back directly. I set the sp (stack pointer) like 2K after the bss (in linker script) and added a command to load sp before calling. it is now working.
    Just though may be some one needed to know this.

    Thanks again,
    Bassem

  21. for the text.1 problem, i think you can it to the flash.
    find a line like this
    {
    *(.text)
    —-> add your new line here
    *(.text.*)
    .
    .

    this would solve all the .text.* problems

  22. Hi Adam,
    Thanks in advance, i followed ur instruction to install ARM cross compiler. I completed ma installation, but it will give a error while am compiling ma simple LPC2148 program. Error is

    /bin/sh: arm-elf-as: not found
    make: *** [crt.o] Error 127

    Please help to cross the error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Comments are closed.