Journal

Porting TinyOS to CC2430 Microcontroller on Windows Platform

2009·04·23

Machine-translated from Chinese.  ·  Read original

Note: If you are not familiar with CC2430 and TinyOS, please skip this article.

This article was originally published on PSYcHic

The original address is: http://www.darlingtree.com/wordpress/archives/187. If you need to repost, please keep this URL. Thank you!

Nowadays, more and more people in China are doing research on WSN. In terms of hardware, we don’t have as many development platforms to choose from as foreigners do. Moreover, the professional development platform of Crossbow is very expensive. However, with more and more companies starting to pay attention to WSN and Zigbee, we can still build our own wireless sensor development system for less than 1,000 yuan.

CC2430 is a relatively ideal hardware platform. In China, most people use IAR combined with the z-stack protocol stack (or a variant of xx Long Edition) for development. The z-stack protocol stack is relatively easy to develop and suitable for beginners. However, if you are doing academic research and need to delve into network formation and related algorithm development, then UC Berkeley’s TinyOS is the best choice. (I believe smart people won’t get involved in the muddy water of z-stack’s OSAL…)

Many people have successfully ported TinyOS to CC2430. However, currently, there seems to be no detailed operation steps on the internet. So, I’ll popularize it for everyone :)

Introduction:

First, we need to port TinyOS 2.x to CC2430. If your English is good, you can directly go to the following link to view the relevant materials: http://tinyos8051wg.sourceforge.net/

TinyOS 2.x for 8051 currently supports three compilers: Keil, IAR, and sdcc. We use the Keil compiler, which is relatively familiar to everyone. TinyOS 2.x must work on the Linux platform, while Keil is a Windows-based software, so we need to install a software that simulates Linux on Windows - Cygwin.

Before porting, we need to prepare the following things:

Hardware: CC2430 node, simulator

Software: Cygwin, Keil, TinyOS 2.x, some related environment setting packages, SmartRF04 Flash Programmer

The hardware is the same as the original CC2430 development hardware used under IAR (regardless of whether it’s from Wireless Dragon, Hua Fan, or Micro Bone).

As for the software, I need to explain:

TinyOS 2.x: Please download the latest version from http://tinyos8051wg.sourceforge.net/download (this article is based on the TinyOS8051wg-0.1pre4.tgz version of October 26, 2008)

Keil: Please install it and remember to install the version without the 2K limit.

Now, let’s start installing the software:

  1. Install Keil - Keil is a necessary software for single-chip machine development, and there are many online resources. You can install it yourself.

  2. Install Java 1.5 JDK

Download address: http://java.sun.com

If you are doing Java development and have installed it before, you can skip this step.

  1. Install Cygwin

Please install the version recommended by TinyOS. Many people encounter strange problems later on because of incorrect Cygwin installation or missing necessary components.

You can download this version of Cygwin from: http://cone.informatik.uni-freiburg.de/people/aslam/cygwin-files.zip

If the link is invalid, please go to the TinyOS official wiki to find the recommended Cygwin version: http://docs.tinyos.net/index.php/Installing_TinyOS_2.0.2#Manual_installation_on_your_host_OS_with_RPMs

The installation process is simple, just click “next” all the way through. However, please remember the installation location. This article assumes that it is installed in the C drive.

  1. Download the necessary installation packages for TinyOS development (a total of 4)

NesC compilation tool: nesc-1.3.0-1.cygwin.i386.rpm

TinyOS-related tools:

tinyos-deputy-1.1-1.cygwin.i386.rpm

tinyos-tools-1.3.0-1.cygwin.i386.rpm

tinyos-2.1.0-2.cygwin.noarch.rpm

  1. Start Cygwin and install the downloaded rpm packages in Cygwin

Double-click the icon to start Cygwin. After normal startup, you should see the ”$” symbol and cursor.

We need to install the rpm packages, so we need to switch to the directory where the rpm packages are stored. If you are familiar with Linux, you can install it yourself. If not, follow my steps:

  1. First, find the directory where you installed Cygwin. If it’s the default installation, it’s C:\Cygwin.

  2. Enter the directory and find the /bin, /var, /etc, /opt, and /home folders. The Linux system root directory looks like this.

We double-click the home folder and find another folder with the user name you set during installation. Let’s assume your username is “quake” (please replace it with your own username). Now, enter C:\Cygwin\home\quake.

Alright, when we start Cygwin, the program’s terminal window defaults to /home/quake. Next, we need to copy the four rpm packages we just downloaded to the C:\Cygwin\home\quake folder.

Then, in the Cygwin terminal, input

> ls

After pressing Enter, you will see the names of the rpm packages you just copied displayed in the terminal window. (For more Linux bash commands, please refer to Linux resources)

Next, we need to install them one by one. Input

> rpm -ivh nesc-1.3.0-1.cygwin.i386.rpm
> rpm -ivh tinyos-tools-1.3.0-1.cygwin.i386.rpm
> rpm -ivh tinyos-deputy-1.1-1.cygwin.i386.rpm
> rpm -ivh tinyos-2.1.0-1.cygwin.noarch.rpm

Each time you input a line, press Enter, and we will have installed the corresponding rpm package. After installing all four rpm packages, we can proceed to the next step.

  1. Installing TinyOS 2.x

Unzip the TinyOS 2.x installation package you downloaded (such as TinyOS8051wg-0.1pre4.tgz) using WinRAR.

Copy the unzipped tinyos-2.x-contrib folder to C:\Cygwin\opt.

Done. We have basically set up the TinyOS development environment.

Next, let’s actually compile a program!

First, in Cygwin, input

> cd /opt
> ls

You will see the tinyos-2.x-contrib folder you just copied in the opt directory. Continue to input

> cd tinyos-2.x-contrib/

Let’s see what’s in this directory

> ls

We find a diku folder. Next, input

> source diku/env

Note: There is an env configuration file in the diku folder. We load it using the source command, so that the compiler knows what configuration to use for compilation later. We will introduce the contents of the env configuration file later. We use Keil to compile, and keep its default state.

After that, we can compile. All examples are in tinyos-2.x-contrib/diku/common/apps/. Let’s take BlinkNoTimerTask as an example

> cd /diku/common/apps/BlinkNoTimerTask
> make cc2430em

If everything is normal, you will see:

> GENERATING INTEL HEX FILE: app.hex
compiled BlinkNoTimerTaskAppC to a cc2430em binary
Code size of app.o
MODULE INFORMATION:   STATIC OVERLAYABLE
CODE SIZE        =    635    -
CONSTANT SIZE    =   -    -
XDATA SIZE       =      4       9
PDATA SIZE       =   -    -
DATA SIZE        =   -    -
IDATA SIZE       =   -    -
BIT SIZE         =   -    -
Total sizes
Program Size: data=9.0 xdata=10 const=0 code=694

This indicates that you have succeeded!

Next, let’s see what TinyOS has generated.

In the directory C:\cygwin\opt\tinyos-2.x-contrib\diku\common\apps\BlinkNoTimerTask\build\cc2430em

we find the app.hex file generated by compilation. Now, we just need to burn this file into the microcontroller, and we’re done!

Burning

We install the SmartRF04 Flash Programmer software. This software is usually included in the CD that comes with the emulator. If you don’t have it, you can search for it online or ask me for it.

After installing the emulator, open the SmartRF04 Flash Programmer software. In the system-on-chip option tab, select the hex file we just compiled, and then select “Perform actions” to burn it successfully.

Done. If everything is normal, congratulations, you have successfully ported TinyOS to CC2430! We have escaped the trouble of IAR’s constant upgrades and Z-stack, and entered the world of TinyOS.

Welcome to continue discussing TinyOS-related issues with me. My email is zzzlog#sogou.com

留 · 言