April 2008

Open-Source development on the Atmel AT91SAM7X256

Hi all…

Lately I’ve been busy with university stuff. In particular, my final year project, which is investigating Controller Area Networks, in the context of the Atmel AT91SAM7X256 MCU.  These microcontrollers are a low-cost system-on-chip based around the ARM7TMDI core.  This particular one includes 64KB RAM, 256KB flash, RS-232, device-side USB 2.0, 10/100Mbps ethernet, and of course, a CAN interface.

When I first started looking into this project, I was thinking about using Linux and SocketCAN… well, needless to say the moment I saw the specs on the exact board I was using (the AT91SAM7X-EK), I soon realised Linux was simply out of the question.  That doesn’t mean however, that one is stuck to using proprietary kernels and toolchains.  The following, are some notes on how to code for these things… and where I’m at.

Kernel

You don’t have to use a kernel of course, you can code bare-iron, but I decided to go with a multitasking kernel to make my life easier — I can code each thread to do something basic, and let the kernel manage the IPC and task switching for me, hooking them together.  There are a few options out there, but so far the option I’m liking the most, is the FreeRTOS kernel.  This kernel is free software under the GNU GPL, and supports many platforms, including ARM7.

Toolchain

There are a few compiler toolchains you can use for this board.  The DVD that comes with the board, includes a version of IAR Embedded Workbench, which isn’t too bad, but unless you pay for a license, your code size is limited to 32KB.  The GNU toolchain however, is very mature for the ARM7 platform… and getting a toolchain up and running isn’t too difficult.

FreeRTOS can be built using IAR, and indeed to get me started, that’s what I did.  Once I was comfortable with the system though, I turned my attention to getting a GNU toolchain running on my laptop.  The toolchain needs to be built, targetting the arm-elf platform, using the newlib C library.  Thumb mode, multilib, and interworking support need to be included in this toolchain to build FreeRTOS.  There are numerous prebuilt toolchains, and guides on how to do them from source… but I wound up going my own way…

In my devspace, you’ll find a compressed Makefile.  Download this into an empty directory, decompress it, then rename it to Makefile.  Gentoo users, may find it helpful to symlink their distfiles directory (/usr/portage/distfiles for most people) to ‘src’ — the Makefile uses the same toolchain sources as Gentoo.  Edit Makefile to point to your local Gentoo mirror (I use these mirrors because they’ve got all the sources in one place), then run make.  With luck, it’ll build everything and install it for you.  It runs as a user, then uses sudo to copy the files to /usr/local where they are to be installed.

At the end, you’ll be left with a full arm-elf toolchain, based on GCC 4.2.3, binutils 2.18 and newlib 1.15.0.

Building the FreeRTOS kernel

FreeRTOS comes with numerous demos which can be used as starting points for your own projects.  The best one for the AT91SAM7X using GCC, is the lwIP_Rowley_ARM7 demo.  This demo does three things:

  1. Runs a webserver displaying some task statistics
  2. Flashes the onboard LEDs to indicate it’s working
  3. Emulates a CDC-ACM device, writing characters to it at 115200 baud 8N1.

To start, go into the Demos/lwIP_Rowley_ARM7 directory, and rename ‘makefile’ to ‘Makefile’.  To set the IP configuration, edit EMAC/SAM7_EMAC.h and change the IP address settings as appropriate (line 69 onwards).  Save this, then type make.  It should go ahead and build an rtosdemo.bin file, which is your executable to be flashed.

Flashing the project

This is where my usage of free software came unstuck.  There are a few projects that theoretically allow you to flash these devices.  The kit comes with a SAM-ICE J-Tag, which is equivalent to the J-Link device developed by Segger.  These, to my knowledge, do not work using J-Tag tools available under Linux.  You could use one of the Wiggler-style J-Tag cables, but I don’t have one of those at my disposal.

The AT91SAM7X has a trick up its sleeve though.  If you power the board up for a few seconds with the ERASE jumper enabled, power it down, then power it back up with the ERASE jumper removed, it’ll revert back to using SAM-BA firmware.  SAM-BA allows for the board to be flashed either via the DBGU serial port, or, via a CDC-ACM USB device.  Tools such as Sam_I_Am, then connect to the /dev/ttyACM0 device created.  For this to work, a small patch needs to be applied to the cdc-acm driver in the Linux kernel (This same patch also adds support for the FreeRTOS CDC device created by the above demo).

For me, this has been the most promising, but hasn’t quite gotten things going… I’m able to flash the device, but for some reason, it sees it as an AT91SAM7S256… and the thing won’t boot.  If anyone has some pointers as to what could be going wrong, I’m all ears.

At the moment, I’m using the SAM-BA flashing utility available from Atmel’s website free of charge.  This is a Windows NT utility requiring administrator privileges, which is suboptimal, but so be it, it works, I just boot my desktop PC into Windows 2000, and access the output binary via SMB.  This works, and isn’t too painful.  It may also work in a VM, I haven’t tried yet.

I’ll keep tinkering with the Linux utilities, because I feel it’s almost there… I’ve thrown this post up so that others who may be looking for this information, have somewhere to work from.  Apart from the little issues I’ve had, I’ve found this board quite enjoyable to work with.  I can use mostly my own tools to work with the files, and the C compiler is both stable (unlike the GNU toolchain for Altera Nios II) and fully ANSI C compliant (unlike the Z-World compiler used on Rabbit Semiconductor devices) — a nice change indeed. 😉

Gentoo/MIPS: A note about the PlayStation, PS2 and PSP

Hi all…

There seems to be a little confusion as to whether the PS2 is supported by Gentoo. To clarify, it isn’t. There was never any effort to officially support the PS2. Some unofficial work did begin some years ago, however that work ceased fairly early on, and there has been no interest in continuing it.

There are a number of technical reasons why the PS2 is not supported.

First and foremost, the CPU is a real bastardised piece of work. It implements a custom instruction set, which is a hodge podge of MIPS I, MIPS II, MIPS III and MIPS IV, with some special instructions thrown in. It doesn’t fully implement any of the aforementioned instruction sets. So binaries such as my mipsel1 stages, will not work — you’ll hit illegal instruction errors fairly early on.

Secondly, the patches necessary for the kernel, and toolchain, are based on a really ancient set of packages. The kernel released with the PlayStation II Linux kit (2.2.1), was a year old when the first PS2 hit the shelves. Not so bad then, but the kernel was never properly maintained. Even today, unofficial efforts have only gotten as far as 2.4.3x-series. The toolchain is still quite ancient, at best, gcc-3.3 from what I recall, is the best they’ve got. Maybe they’ve got as far as 3.4… who knows…

Thirdly, the memory on the PS2 is restricted to 32MB. This is soldered on-board, can’t be upgraded. Gentoo/MIPS will not build most packages with 32MB RAM. Once upon a time, I could just build stages with 64MB on my Qube2, if I shut down things like MySQL — not anymore, I need 128MB to do this today. uClibc could be feasible, but you’d still have problems with the “special” CPU. Virtual memory doesn’t help — even if you had 2YB of swap, it wouldn’t stop builds dying.

Other MIPS-based consoles, such as the original PlayStation (MIPS R3000-based) and the PlayStation Pocket (MMU-less MIPS32r2) are also not supported for similar reasons.  And we (MIPS team) don’t support the PlayStation 3 either — for that, you should talk to the PowerPC team.

Now… I have no complaints about answering questions about what we support/don’t support… but a few points… (this is where my rant starts by the way)

  1. Write properly when in the IRC channel. If it’s one thing that’ll quickly get my back up, it’s SMS-like chat on IRC. I’m tolerant of spelling errors and grammatical mistakes, but I won’t tolerate laziness. If a word has vowels in it, include them! It’s not like it’s significantly more effort to press an additional button on a keyboard. If you’re using morse to drive the computer, or have a physical disability that makes typing difficult, fine, declare this up front, and all will be okay, but otherwise, there’s no excuse.
  2. Read the documentation! It tells you what we support, and what we don’t. It’s likely your question is answered there already.
  3. If we can’t help you with some non-supported platform, we mean it… don’t pester us about it, we’re not going to start supporting a new platform in 5 minutes flat.

Teahouse of the August Moon

The following arrived via email via the Department of Defence… figured you might appreciate it — clearly the Chinese are really keen — this road isn’t my cup of tea! 😉

Try a mountain trail stroll in China …

First, let’s take the cable car up to the start of the trail

Teahouse trail start

Now follow the path

The path

Be sure to hold on to the railing

The railing

Keep an eye on the person in front of you

The person in front

Be very careful when passing someone going in the opposite direction

Passing

Now just up a few steps (they are on the left in the picture)

A few steps

It gets a little steeper here – so put your toes in the holes

Holes in the path

A few more steps to go

More steps

Finally in sight, the Teahouse!

The teahouse at last!

I’d go almost anywhere for a Beer but a cup of tea?