Contiki, 6loWPAN on TI CC253x hardware

It works!

You need these two patches on Debian to make SDCC work with it:

04_makefile_mcs51 to enable 8051 (that’s the micro controller core in the CC2530/2531)
05_incl.mk_model_huge to enable the necessary models for contiki on the CC253x.

If the long compile time annoys you, then you could modify the first patch to disable some unnecessary architectures.

Start with getting the source package and its build-dependencies:

apt-get source sdcc
apt-get build-dep sdcc

Add the patches (assuming the package is still called sdcc-3.4.0+dfsg) :

cd sdcc-3.4.0+dfsg/debian/patches/
wget http://blog.ruecker.fi/wp-content/uploads/2015/02/04_makefile_mcs51
wget http://blog.ruecker.fi/wp-content/uploads/2015/02/05_incl.mk_model_huge
echo $'04_makefile_mcs51\n05_incl.mk_model_huge' >> series
cd ../..

And now build the custom packages:

dpkg-buildpackage -b

A message “dpkg-buildpackage: error: failed to sign .changes file” is normal, if you didn’t update the changelog and didn’t supply own signing keys.

Once it’s built, switch one level up in the directory structure, switch to root or sudo and install (a bit simplified, but will usually work):

cd ..
dpkg -i sdcc*.deb

Done, now you should be able to build contiki on your machine. When I did this, the latest contiki git checkout built, but once flashed the modules didn’t seem to work properly. I do not recommend this, but you could fall back to George’s old development tree, that built and worked out of the box. Not recommended, because Contiki has seen lots of development since then.

If during compiling Contiki you get output like this and the compile fails, then you still don’t have the correctly patched and compiled SDCC installed or it got overwritten by a Debian update:

First Link
===============
LD client.ihx
?ASlink-Warning-Couldn't find library 'libsdcc.lib'
?ASlink-Warning-Couldn't find library 'mcs51'
?ASlink-Warning-Couldn't find library 'libsdcc'
?ASlink-Warning-Couldn't find library 'libint'
?ASlink-Warning-Couldn't find library 'liblong'
?ASlink-Warning-Couldn't find library 'libfloat'
?ASlink-Warning-Undefined Global '__divuint' referenced by module 'rpl_dag'
?ASlink-Warning-Undefined Global '__divuint' referenced by module 'rpl_icmp6'
[…]
?ASlink-Warning-Undefined Global '__divsint' referenced by module 'rpl_dag'
?ASlink-Warning-Undefined Global '__divsint' referenced by module 'nbr_table'
?ASlink-Warning-Undefined Global '__divsint' referenced by module 'cc2530_rf'
?ASlink-Warning-Undefined Global '__divsint' referenced by module 'rpl_icmp6'
../../../cpu/cc253x/Makefile.customrules-cc253x:37: recipe for target 'client.ihx' failed
make: *** [client.ihx] Error 1
rm client.ihx obj_cc2530dk/client.app.rel

Just delete the sdcc sources and start at the beginning of this blog post!