Building C8051FXXXX applications on Linux

As part of my Masters we are doing a Mixed Signal Processing module where we are using the C8051F120 microcontroller to process basic mixed signal functions. In the labs we have been given the C8051F120DK development kit from Silicon Labs which includes the Silicon Labs IDE. Developing with this on Linux was a real pain since I had to run the IDE through a Windows XP VirtualBox install, and that wouldn't do!

The following details how I managed to build, program and debug Silicon Labs' C8051 micros natively in Linux.

Small Device C Compiler - sdcc

The first step was to get a build environment setup, this was simple since the sdcc compiler supports a number of Silicon Labs 8051s. Installation was extrememly simple too since it is included in the repos of most serious Linux distributions. In Fedora 19 - used throughout the rest of this article - sdcc was installed using YUM with the following command:

 $ sudo yum install sdcc

This installs a number of tools included with sdcc, such as, the assembler, a compiler, a linker, etc.. The compilation of a single source file can be carred out with the following command:

$ sdcc-sdcc ./control_test.c

If compiling multiple source files with one main file, the non-main files need to be compiled independently with the '-c' flag before compiling the main file, as follows:

$ sdcc-sdcc -c foo1.c
$ sdcc-sdcc -c foo2.c
$ sdcc-sdcc main.c foo1.rel foo2.rel

The sdcc-sdcc command creates a number of files, perhaps the most important is the .ihx file which is the Intel-hex binary.

NOTE: The sdcc command above is shown for Fedora, if using a different distro, such as ubuntu, you would replace 'sdcc-sdcc' with just 'sdcc'.

USB Debug Adapter

The C8051F120 development kit comes with Silicon Labs 'USB debug adapter' that provides a JTAG interface allowing the target to be programmed and debugged using a host. The final part of this article covers the basic installation and use of the new ec2drv to allow the debug adapter to be controlled natively in Linux.

ec2drv and ec2-new

ec2drv provides Linux support for the Silicon Laboratories EC2/EC3 JTAG debug adapters, however, it seems that development ceased in around 2008/9. This was then folked to the ec2-new which fixes a number of bugs and compile issues with the original.

Even with the new version, building the package was a little complicated due missing header #include statements in a number of files, however, once these were fixed, installation ran smoothly using the following commands:

$ make -f Makefile.cvs
$ autoreconf -fvi
$ ./configure
$ make
# make install

If, during the build, one has errors relating to "error: 'usleep' was not declared in this scope" please see this link for the patch I created.

ec2-new usage

One installed the device can be queried with the following command:

 $ sudo /usr/local/bin/ec2device --port USB
*********************************************************************
* WARNING: Auto detection of mode may cause initialisation sequence *
* to differ significantly from the SiLabs IDE.                      *
* In the case of problems specify --mode=C2 or --mode=JTAG          *
*********************************************************************
 
ec2_GetDbgInfo(0x10c4,0x8044)  1
ec2_reset C2
EC3 debugger firmware version = 0x22
Warning: this version is newer than the versions tested by the developers,
Please report success / failure and version via ec2drv.sf.net
Currently tested versions from 0x01 to 0x0e
NOT C2, Trying JTAG
ec2_GetDbgInfo(0x10c4,0x8044)  1
ec2_reset C2
Debug adaptor ver = 0x22
unique_id=0x48, rev=00
FOUND:
 
device  : C8051F120
mode    : JTAG
Flash size = 131072 bytes
Internal xram size = 8192 bytes
External bus = Yes
Read lock addr = 0x1fbff
Write lock addr = 0x1fbfe
Flash sector size = 1024 bytes
Flash reserved top = 0x1ffff
Flash reserved bottom = 0x1fc00
Has Scratchpad = Yes
Scratchpad start addr = 0x0000
Scratchpad length = 0x0100
Scratchpad sector size = 128 bytes
Has paged SFR = Yes
USB FIFO size = 0 bytes
 
Tested = Yes
 
If the above does not match your processor exactly, please contact us at :
http://sourceforge.net/tracker/?atid=775284&group_id=149627&func=browse
We need your help to discover if any sub device id's exsist in the silicon
exiting now
disconnect done

Writing flash to the device can be achieved with:

 $ sudo /usr/local/bin/ec2writeflash --port USB --hex ./control_test.ihx 
*********************************************************************
* WARNING: Auto detection of mode may cause initialisation sequence *
* to differ significantly from the SiLabs IDE.                      *
* In the case of problems specify --mode=C2 or --mode=JTAG          *
*********************************************************************
 
ec2_GetDbgInfo(0x10c4,0x8044)  1
ec2_reset C2
EC3 debugger firmware version = 0x22
Warning: this version is newer than the versions tested by the developers,
Please report success / failure and version via ec2drv.sf.net
Currently tested versions from 0x01 to 0x0e
NOT C2, Trying JTAG
ec2_GetDbgInfo(0x10c4,0x8044)  1
ec2_reset C2
Debug adaptor ver = 0x22
unique_id=0x48, rev=00
FOUND:
device  : C8051F120
mode    : JTAG
 
   Loaded 553 bytes between: 0000 to 0228
Writing to flash
start=0x00000, end=0x00228
done
Exiting now
Disconnect done

To enable the debugger to be controlled one needs to use the 'newcdb' application supplied with ec2-new. This basically initiates a gdb shell, and the command to start the shell and connect to the device is as follows:

$ sudo /usr/local/bin/newcdb -ex='set target SL51' -ex='set target port USB' -ex='set target connect'
 ====================== DbgSession Constructor =========================
constructor this=0x613a20
Executing command set target SL51
current target <none>
selecting target SL51
Executing command set target port USB
set port 'USB'
Executing command set target connect
*********************************************************************
* WARNING: Auto detection of mode may cause initialisation sequence *
* to differ significantly from the SiLabs IDE.                      *
* In the case of problems specify --mode=C2 or --mode=JTAG          *
*********************************************************************
 
ec2_GetDbgInfo(0x10c4,0x8044)  1
ec2_reset C2
EC3 debugger firmware version = 0x22
Warning: this version is newer than the versions tested by the developers,
Please report success / failure and version via ec2drv.sf.net
Currently tested versions from 0x01 to 0x0e
NOT C2, Trying JTAG
ec2_GetDbgInfo(0x10c4,0x8044)  1
ec2_reset C2
Debug adaptor ver = 0x22
unique_id=0x48, rev=00
newcdb, new ec2cdb based on c++ source code
(newcdb) 

And then the target can be run by typing 'run' in the shell, and 'ctrl-c' to stop. To enable the target to be programmed when using the newcdb shell, the target must first be disconnected using the 'set target disconnect' command in the shell, once programmed use the 'set target connect' command to reconnect.

For more information on the ec2 tools see the Quickstart guide on the main ec2drv website.

Tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
By submitting this form, you accept the Mollom privacy policy.