Getting started with the CC2530 and Contiki

Submitted by sjs205 on Sun, 10/18/2015 - 19:52

​So, I've been meaning to have a play with Contiki, "The Open Source OS for the Internet of Things", for some time now. The main issue I've had is the cost and availability of suitable modules and a development platform. The problem with some platforms is that the modules they provide are either too expensive, or are not suitable for deployment, either due to price or construction. I have seen many solutions on the market that cost around £50+ per module, but this seems a bit to steep for me, especially if I plan to experiment and actually deploy a number modules for testing purposes.

WaveShare

After some time researching - basically scanning the Contiki hardware list followed by ebay and Amazon searches for the cheapest alternatives - I finally stumbled upon a cheap supplier for Texas Instruments' CC2530 platform, basically, an 8051 SoC with an integrated IEEE 802.15.4 radio. A company called WaveShare manufacture a range of ready to go CC2530 modules along with two types of development board, the ZB502 and ZB600.

Both of the development boards are very similar, with the ZB600 providing more pin headers/interfaces than the ZB502, such as an ADC and UART port. That said, both provide access to all 21 of the CC2530's GPIO pins. Both boards also provide 5 controllable LEDs and 2 push-button switches, the ZB600 even includes a push-button joystick. The CC2530 modules are programmed using the 10-pin debug interface, for this we can use either the CC-debugger device available from TI, or a clone, available on ebay/Amazon - I've seen these go for as little as £6 including postage. The boards also include a CP2102 chip, providing a bridge between the CC2530's UART and USB, thus allowing UART communication over USB. Finally, each of the boards can be powered via the USB interface, or using 2 AAA batteries.

Along with the two types of development board, WaveShare also offer two types of CC2530 module, the Core2530 as seen in the picture above, and the XCore2530, which provides greater communication range than the Core2530 - capable of Stable communication at upto 1.3 km compared to 250 m. Both modules include the CC2530F256 device, which features the maximum amount of flash memory available, 256 kb. Both modules are reasonable priced and can normally be delivered for less than £10-12 each.

Getting started with the Contiki stack

With the development platforms and a number of modules in my hand, I can now turn my attention to testing the Contiki stack. There is quite a bit of documentation around that details various aspects of the setup, however, much of the information I found was outdated.

Toolchain

First things first, we need a cross-compiler. For this we do not have much choice: we need to use the SDCC - Small Device C Compiler. However, this needs to be built from source since the binaries do not include all of the required libraries. We also need to ensure we stay away from a range of SDCC revisions due to a bug that doesn't support banked firmware, that is, revisions 7102 through to 8719. The recommended revision is 9092, however, I was unable to build this on Fedora 21, but I was able to build revision 9356. Further information on building the toolchain can be found here: Build your toolchain.

One point worth keeping in mind, unless the SDCC toolchain's binary directory is in the PATH, it will need to be exported with:

$ export PATH=$PATH:/media/devel/sdcc-contiki/bin

Hello World build target

The Contiki OS provides a number of example make targets for use with the CC2530, this includes a hello-world target that simply sends "Hello World" down the UART - along with some other information. This is the perfect target to test our new cross-compiler. The steps required to get this binary onto the hardware follow. Firstly, we'll need to clone the contiki source, we can then build our target using Make as follows:

Notice that we are actually building examples for the CC2530DK - CC2530 development kit from Texas Instruments, my understanding is that the boards from WaveShare are pin compatible with the TI boards, although they provide fewer built-in interfaces, ports, etc.. Running make should lead to the following output telling us the memory footprint of our compiled binary. Note, there will be a number of warning displayed as the build takes place, these can be ignored.

Programming the CC2530

Once the build has completed successfully, we can then program the device. using a CC-debugger or similar programmer. On Linux, we need to use cc-tool to program the device. This needs to be downloaded and built from source. We can then program the device with the following command:

Providing the programming was successful, the device should now be loaded with the Contiki hello-world application. Provided the USB cable is connected to the board, we should be able to view the output from the device using a serial terminal program, such as minicom, configured with 115200 baud, 8N1. When using minicom the following option is needed, "Add Carriage Ret...U", since there are no carriage returns in the output and all of the characters are printed in in a column on the left of the page. The hello-world application should lead to something similar to the following output:

And that is it. Taking this one stage further, there are a number of other examples provided with Contiki, however, many of these do not work, At the time of writing, I've been able to get radio working using the 'udp-ipv6' build target, but not communication - that is, I can see that packets using a sniffer, but the devices do not communicate. To resolve this issue we need to use the Contiki-sensinode folk, more on this later...