Porting TinyOS to CC2430 Microcontroller on Windows Platform
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 URL is: http://www.darlingtree.com/wordpress/archives/187. If you need to reprint, 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, Crossbow’s professional development platform is very expensive. However, with more and more companies paying 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 bother with the muddy waters of z-stack’s OSAL…)
Many people have successfully ported TinyOS to CC2430. However, it seems that there are no detailed operation steps available online. So, I’ll give you a brief introduction:
Introduction:
First, we need to port TinyOS 2.x to CC2430. If you’re proficient in English, you can directly visit the following website to view the relevant materials: http://tinyos8051wg.sourceforge.net/
TinyOS 2.x for 8051 currently supports three compilers: Keil, IAR, and sdcc. We’ll be using Keil, which is a familiar compiler for most people. TinyOS 2.x can only work on Linux platforms, while Keil is a Windows-based software, so we need to install a Linux simulator on Windows - Cygwin.
Preparations before porting:
Hardware: CC2430 node, emulator
Software: Cygwin, Keil, TinyOS 2.x, some related environment setting packages, SmartRF04 Flash Programmer
The hardware is the same as the CC2430 development hardware used in 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, dated October 26, 2008)
Keil: Please install it and remember to install the version without the 2K limitation.
Installing software:
-
Install Keil - Keil is a necessary software for single-chip machine development, and there are many online resources available. You can install it yourself.
-
Install Java 1.5 JDK
Download from http://java.sun.com
If you’ve done Java development before and have already installed it, you can skip this step.
- Install Cygwin
Please install the version recommended by TinyOS. Many people encounter strange problems later on because they didn’t install Cygwin correctly or missed some 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 visit 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 Cygwin is installed on the C drive.
- Download the necessary installation packages for TinyOS development (four packages in total)
NesC compiler: 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
- Start Cygwin and install the downloaded rpm packages
Double-click the icon to start Cygwin. After a normal startup, you should see a ”$” symbol and a cursor.
We need to install the rpm packages, so we first need to switch to the directory where the packages are stored. If you’re familiar with Linux, you can install them yourself. If not, follow my steps:
-
Find the directory where you installed Cygwin. If it’s the default installation, it should be C:\Cygwin.
-
Enter the directory and find the following folders: /bin, /var, /etc, /opt, /home, etc. This is what the Linux system’s root directory looks like.
We double-click the “home” folder and find another folder with the username you set during installation (let’s assume it’s “quake” - please replace it with your own username). Now, enter C:\Cygwin\home\quake.
好了,当我们一启动Cygwin,程序的终端窗口默认也是停留在 /home/quake 下面。下面我们需要把刚刚下载的4个rpm包拷贝到 C:\Cygwin\home\quake 这个文件夹下面。
之后在Cygwin终端下输入
ls
按回车后,你会发现终端的窗口里显示了你刚刚拷过去的rpm包的名字。(更多Linux bash命令请参考Linux资料)
下面需要一个一个安装
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
每输入一行,按一次回车,我们就把对应的rpm包给安装好啦。把4个rpm包都安装好后就可以进行下一步了。
5、安装TinyOS 2.x
将下载好的TinyOS 2.x的安装包给解压缩(如TinyOS8051wg-0.1pre4.tgz),解压缩用winrar就可以。
将解压好的tinyos-2.x-contrib这个文件夹拷贝到 C:\Cygwin\opt 下
好了。我们已经把TinyOS的开发环境基本搭建好了。
下面我们实际编译个程序吧!
首先在Cygwin下面输入
cd /opt
ls
你可以看到opt目录下有你刚刚拷贝过去的tinyos-2.x-contrib文件夹,继续输入
cd tinyos-2.x-contrib/
我们查看下该目录下面有什么
ls
发现有个diku文件夹
下面输入
source diku/env
说明:diku文件夹下面有个env配置文件,我们通过source命令加载下,这样后面编译的时候编译器就知道我们要使用什么样的配置去编译了。关于env配置文件的具体内容稍后介绍。我们用Keil编译,保持其默认状态就可以了。
之后我们就可以编译了,所有的例子在tinyos-2.x-contrib/diku/common/apps/下面,我们以BlinkNoTimerTask为例
cd /diku/common/apps/BlinkNoTimerTask
make cc2430em
如果一切正常的话,你会看到:
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
这段话,这表明你已经成功了!~
好了,下面我们看看TinyOS生成了什么吧~
在
C:\cygwin\opt\tinyos-2.x-contrib\diku\common\apps\BlinkNoTimerTask\build\cc2430em
这个目录下面
我们发现了其编译生成的app.hex文件。现在只要把这个文件烧录进单片机,我们就大功告成了!
烧录
我们安装下SmartRF04 Flash Programmer这个软件,这个软件一般购买仿真器的话都会在附送的光盘里面赠送,如果没有的话网上搜索下吧,实在没有给我发信索取下。
之后我们插好仿真器,打开SmartRF04 Flash Programmer这个软件,在system-on-chip的选项卡下
将hex文件选择为我们刚刚编译好的那个,之后选择“Perform actions”就可以顺利烧写了:)
好了,如果一切正常,那么恭喜你已经将TinyOS成功移植到了CC2430上了。我们成功摆脱了IAR不断升级的困扰和Z-stack,已经进入到了TinyOS的世界了。
欢迎大家继续和我讨论关于TinyOS的相关问题 我的邮箱<zzzlog#sogou.com>
还没有人留言,在下面说两句吧。