Linux and the SiLabs C8051F02x + EC2

2009.02.07 in school

Note: Someone else has come up with revised instructions which work on more recent versions of Linux.

For LITEC, each group has a C8051F02x development board attached to a car (and later, to the RPI blimps). The course only includes instructions and support for people using the SiLabs IDE within Windows (it doesn't exist for Linux or OS X), which greatly disappointed Andrew and I when we started the class a few weeks ago.

Andrew spent a good bit of time fiddling with things in Linux before — a few days ago — he finally got it working! It turns out there are Linux drivers and support software for the SiLabs EC2 debug adapter which we use to download code to the chip (and run it, debug it, etc.)... and the Small Device C Compiler is even in APT! (sdcc-nf is the package including the non-free components which I believe we determined we need).

So... there's a brief set of instructions to get compilation and downloading working, after the jump!

  • Install SDCC from APT (sdcc-nf, etc.)
  • Install kernel headers
  • Checkout the EC2 driver for Linux:
svn co https://ec2drv.svn.sourceforge.net/svnroot/ec2drv/ec2drv/trunk ec2drv
  • There's a mistake in the EC2 driver build scripts (at least with Jaunty and whatever Andrew uses...); in the file libtool find ECHO="echo", and add a line echo="echo" below it.
  • Build and install the EC2 driver.
  • Compile your program with SDCC (thanks, again, Andrew!):
sdcc -mmcs51 --model-small --debug --code-loc 0x0000 --iram-size 0xFF --noinduction --nooverlay --nogcse PROJECT.C
  • Now you have a ton of messy files sitting around. Launch 'newcdb' (which got installed with the EC2 driver). I have to run it as root because I haven't figured out which device needs more liberal permissions, but you should probably figure that out...
  • To connect to the EC2 debug adapter:
set target SL51
set target port USB
set target connect
  • Then load your file: "file PROJECT" (notice the lack of extension). This will take a while while it downloads to the board.
  • The commands "run", then "continue" will run your program on the 8051! Yay!
I've crafted a small Makefile for our use which might be useful for others:

TARGETS = library_test

all: $(TARGETS)

clean: rm -f *~ *.adb *.asm *.cdb *.ihx *.lnk *.lst *.map *.mem *.rel *.rst *.sym rm -f $(TARGETS)

download: $(PROJ) sudo newcdb --command=download.cmd -ex="file $(PROJ)" -ex="quit"

run: sudo newcdb --command=run.cmd

.c: sdcc -mmcs51 --model-small --debug --code-loc 0x0000 --iram-size 0xFF --noinduction --nooverlay --nogcse $@.c
Where download.cmd is:
set target SL51
set target port USB
set target connect
And run.cmd is:
set target SL51
set target port USB
set target connect
run
continue
quit
You can download a particular project with:
PROJ="library_test" make download
and run it with:
make run
Pretty cool! We're also developing a very awesome library for use with the 8051 to make it much, much nicer, but I can't publish that because of it being for class and stuff. Maybe after the semester's over!

Have fun, and if anyone tries this and can't make it work, email me.