Monday, 1 October 2012

4pi tool chain

Attempting to get any code to compile for the 4pi has had a few issues.

So I will document what I've found to try and help out others.

You need a compiler, I wanted to use sourcery-codebench the web site is very confusing as they don't really want you to find or use the Lite version (well that's the impression I get)

You need to click on Download the EABI Release can be found under ARM processors on 
They want you to register, and will send the link to your e-mail address.

You end up with arm-2012.03-56-arm-none-eabi.bin or arm-2012.03-56-arm-none-eabi.exe depending if your using Linux or windows

Installing is straight forward, just run the file, it launches A GUI installer.

Next you need something to compile

Although it not finished yet, it does compile (after some issues are sorted) so I got sprinter for 4pi from

Kliment advises me this url is obsolete it should be 

Using the old version as a demo clone this git repository with you favourite git client, eg "git clone"

Make your way to 4pi-firmware/src and type make.

This should result in the arm binary being generated, I got the following error

tmp/ccVFQZtE.s: Assembler messages:
/tmp/ccVFQZtE.s:318: Error: registers may not be the same --
strexb r0,r0,[r1]'
/tmp/ccVFQZtE.s:333: Error: registers may not be the same -- strexh r0,r0,[r1]'

Googling this provided lots of false leads...  most people giving up and getting an older version of sourcery-codebench

I found one line in a conversation "Patch available at git://"   I took a look.

This provides a patch file.

This Patch fixes the issue.

You need to apply this patch to 4pi-firmware/external_libs/cmsis/core_cm3.c
There are only actually two characters that need changes

"=r" (result)  becomes "=&r" (result) on lines 721 and 738 
now make works correctly.

NB this issue only triggers if you use -O (optimization) flags while compiling, which is the default in the firmware make file.


If you use the most up to date version of the firmware from
It compiles without issues. The above patch is already in there (I found this out after writing this). So it is only needed if you trying to compile other demo arm programs such as a LED flasher, which provide the buggy version of the library.

The next tool you need is SAM-BA (not to be confused with emulating windows networking under Linux samba)

This is the tool that lets you upload binary’s via the boot loader into the ARM/4pi
SAM-BA is available here

With these tools I have now managed compile a demo LED flasher application for the 4pi and upload it. It works brilliantly (pun intended as the LEDS are very bright)

Which lead to the next issue, now you have new firmware in the 4pi you dont get to see the boot loader again (unlike the Arduino). There is a trick to this, you need to short the two Pads on the lower right hand side of the 4pi (labeled erase) and then reset. This restarts the boot loader.


  1. Hi,
    I also bought a 4pi, but it doesn't appear to come with any firmware loaded (even tho' I thought it had Sprinter).

    I've cloned the latest 4pi firmware from Github, and used your instructions to compile it using CodeBench (I had to guess at cs-make.exe rather than make...I think it's right as it produced "Sprinter-4pi-at91sam3u4-flash.bin" and "Sprinter-4pi-at91sam3u4-flash.elf" along with a folder called "obj" full of .o files.

    I then downloaded and installed SAM-BA, but have no idea how to actually upload the firmware. Could you possibly provide a bit more info on what I should be doing with SAM-BA? Thanks for your help this far, it's more than I could find anywhere else! Any further help would be greatly appreciated.


  2. I cant recall... Ill look again in a few days. In the mean time most have started to use another program to upload as its less confusing

    Take a look at this, may be more obvious for you.

  3. Thanks, I tried it - it's certainly less confusing. I think the firmware is being flashed, it's just not recognised as a device by Windows :(

  4. I have been hearing reports that Codesourcery have broken the latest version of their compiler... see if you can get the version I used arm-2012.03-56-arm-none-eabi which is known to work