Contiki-CC2538

InstantContiki3.0 for CC2538dk

2013InstantContiki2.6 for cc2530dk,再写个关于cc2538dk的。

环境

  1. 下载安装预装有Contiki的 InstantContiki3.0 Ubuntu虚拟机
  1. 安装驱动,一般插上板子后会自动安装(无非cp210x、pl2303、ft232、ch341),可以通过以下命令查看:
    1
    $ lsusb

一般会得到:

1
2
3
4
5
6
7
user@instant-contiki:~/contiki$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 014: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 002 Device 013: ID 0e0f:0008 VMware, Inc.
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

cc2538demo

官方原网址:
https://github.com/contiki-os/contiki/blob/master/platform/cc2538dk/README.md

1
2
cd ~/contiki/examples/cc2538dk
make

下载烧录 cc2538-demo.bin

所用工具

可以在window下通过smartRF Flash programmer 2来下载border-router.bin文件到cc2538中

也可以在Linux下通过串口bootloader安装border-router.elf,其中波特率要设置为115200,8N1。
如果想通过串口直接下载,需要手动的设置使能 bootloader,然后使用:

1
$ makecc2538-demo.upload

对于官方demo板的方法:按住select键,并复位板子。

另外,通过make cc2538-demo.lst 可以看到编译的信息,有助于调试代码。

串口打印

由于linux中换行以 \n 结尾(用minicom的可忽略)。而windows以 \r\n 结尾,在Windows中调试例程需要修改串口调试工具中的设置。

例如 putty 中,[ \n 转换为 \r\n ]修改设置见下图:

当然,还有最爱 SecureCRT 设置如下:

rpl-border-router 边界路由器

编译

1
2
cd ~/contiki/examples/ipv6/rpl-border-router
make TARGET=cc2538dk

##3 2.节点IEEE/RIME/IPv6地址

节点一般会根据它们的IEEE地址(MAC地址)来确定它们的IPV6地址,这个IEEE地址可能直接从cc2538的info页读取到,也可以通过硬编码得到,用户可以在编译的时候定义一个2字节的的值,这个值将用于IEEE地址的两个最低有效位。

设置IEEE地址来源——info页或者硬编码,可以通过定义 ~/contiki/platform/cc2538dk/contiki-conf.h 中的 IEEE_ADDR_CONF_HARDCODED 设定
如果为0 ——从info页中得到;
如果为1 ——从硬编码中得到,即从IEEE_ADDR_CONF_ADDRESS得到。

当然,也可以重新定义IEEE的最低两位地址,通过:

1
$ make NODEID=0x8888

此外,还可以设置使不同的节点具有不同的IEEE地址。IPv6中MAC地址不可以重复

测试ipv6 border router

(1)修改border-router.c

将#define DEBUG DEBUG_NONE 改为 #define DEBUG DEBUG_PRINT

(2)在project-conf.h中定义了UIP的最大缓冲值(UIP_CONF_BUFFER_SIZE),可以将它改为更大或删除这句话,从而允许更多的的值。

(3)编译:make TARGET=cc2538dk因为不是在cc2538的工程中编译,所以需要加上目标平台

(4)下载烧录,参考上面。

(5)编译tunslip6,测试

1
2
3
cd ~/contiki/tools/
make tunslip6
sudo ./tunslip6 aaaa::1/64 -s /dev/ttyUSB0

执行后,不出意外的话看到router的IPV6地址:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
user@instant-contiki:~/contiki/tools$ sudo ./tunslip6 aaaa::1/64 -s /dev/ttyUSB0
[sudo] password for user:
********SLIP started on ``/dev/ttyUSB0''
opened tun device ``/dev/tun0''
ifconfig tun0 inet `hostname` mtu 1500 up
ifconfig tun0 add aaaa::1/64
ifconfig tun0 add fe80::0:0:0:1/64
ifconfig tun0
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:127.0.1.1 P-t-P:127.0.1.1 Mask:255.255.255.255
inet6 addr: fe80::1/64 Scope:Link
inet6 addr: aaaa::1/64 Scope:Global
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
*** Address:aaaa::1 => aaaa:0000:0000:0000
Got configuration message of type P
Setting prefix aaaa::
created a new RPL dag
Server IPv6 addresses:
aaaa::212:4b00:5af:84e0
fe80::212:4b00:5af:84e0

(6)通信测试

Ping6 测试

ping6 aaaa::212:4b00:5af:84e0

1
2
3
4
5
user@instant-contiki:~/6lbr/examples/cc2538dk$ ping6 aaaa::212:4b00:5af:84e0
PING aaaa::212:4b00:5af:84e0(aaaa::212:4b00:5af:84e0) 56 data bytes
64 bytes from aaaa::212:4b00:5af:84e0: icmp_seq=1 ttl=64 time=21.1 ms
64 bytes from aaaa::212:4b00:5af:84e0: icmp_seq=2 ttl=64 time=21.5 ms
64 bytes from aaaa::212:4b00:5af:84e0: icmp_seq=3 ttl=64 time=21.1 ms

打开浏览器,地址栏输入 http://[aaaa::212:4b00:5af:84e0]/ 网页访问测试:

节点联网

(1)编译,下载烧录

1
2
cd ~/contiki/examples/webserver-ipv6
make TARGET=cc2538dk NODEID=<value>

(2)查看

打开浏览器,地址栏输入 http://[aaaa::212:4b00:5af:84e0]/ 查看节点:

Neighbors
fe80::212:4b00:5af:8444
Routes
aaaa::212:4b00:5af:8444 /128 (via fe80::212:4b00:5af:8444) 1792s

(3)ping6测

1
2
3
4
5
6
7
8
9
10
11
12
user@instant-contiki:~/6lbr/examples/cc2538dk$ ping6 aaaa::212:4b00:5af:8444
PING aaaa::212:4b00:5af:8444(aaaa::212:4b00:5af:8444) 56 data bytes
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=2 ttl=63 time=95.9 ms
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=3 ttl=63 time=340 ms
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=4 ttl=63 time=91.2 ms
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=5 ttl=63 time=90.9 ms
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=6 ttl=63 time=86.7 ms
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=7 ttl=63 time=82.2 ms
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=8 ttl=63 time=82.3 ms
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=9 ttl=63 time=82.0 ms
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=10 ttl=63 time=77.3 ms
64 bytes from aaaa::212:4b00:5af:8444: icmp_seq=11 ttl=63 time=77.4 ms

(4)也可 curl

1
2
3
4
5
user@instant-contiki:~/6lbr/examples/cc2538dk$ curl -g http://[aaaa::212:4b00:5af:84e0]/
<html><head><title>ContikiRPL</title></head><body>
Neighbors<pre>fe80::212:4b00:5af:8444
</pre>Routes<pre>
aaaa::212:4b00:5af:8444/128 (via fe80::212:4b00:5af:8444) 1773s

(5)wget 下载 index.html

1
2
3
4
5
6
7
8
9
10
user@instant-contiki:~/6lbr/examples/cc2538dk$ wget http://[aaaa::212:4b00:5af:84e0]/
--2016-11-09 07:27:24-- http://[aaaa::212:4b00:5af:84e0]/
Connecting to [aaaa::212:4b00:5af:84e0]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’
[ <=> ] 192 --.-K/s in 0.1s
2016-11-09 07:27:24 (1.59 KB/s) - ‘index.html’ saved [192]

(6)半导体芯片越做越小,性能越强悍;系统协议越精减,越精简优化。webserver跑在单芯片上也就不稀奇了!



文章目录
  1. 1. InstantContiki3.0 for CC2538dk
  2. 2. 环境
  3. 3. cc2538demo
  4. 4. 下载烧录 cc2538-demo.bin
  5. 5. 串口打印
  6. 6. rpl-border-router 边界路由器
    1. 6.1. 编译
    2. 6.2. 测试ipv6 border router
    3. 6.3. 节点联网
// Add comment count