RIOT 基于CC2538cb套件学习2,编译测试default和helloword

来源:互联网 发布:js实现放大图片预览 编辑:程序博客网 时间:2024/05/19 13:45

春节过后的第一次写博客,让我继续带大家来看看身为菜鸟的我继续RIOT的学习之旅;

上一篇已经初步介绍了 RIOT的启动过程,这一次咱们不再多说直接make download测试下:

本次挑选两个例程在RIOT/examples下的default和helloword实验:


RIOT的API帮助首页为http://www.riot-os.org/api/index.html,比Contiki好一点在于可以搜索;

下面开始第一个例程helloword,应该算是最简单的例程代码了;一如既往首先介绍

makefile

# name of your applicationAPPLICATION = hello-world# If no BOARD is found in the environment, use this default:BOARD ?= native# This has to be the absolute path to the RIOT base directory:RIOTBASE ?= $(CURDIR)/../..# Comment this out to disable code in RIOT that does safety checking# which is not needed in a production environment but helps in the# development process:CFLAGS += -DDEVELHELP# Change this to 0 show compiler invocation lines by default:QUIET ?= 1include $(RIOTBASE)/Makefile.include

APPLICATION = hello-world  不多做介绍了,熟悉我写TinyOS或Contiki的文章的朋友应该熟悉了

BOARD ?= native                    类似TinyOS的platform,需要是环境变量,可以在bashrc文件添加,也可以编译之前export BOARD=cc2538cb,我这里用到的还是cc2538cb套件,在board中创建了cc2538cb的文件夹以及make相关文件 和驱动文件,export以后会覆盖native平台

RIOTBASE?=                          指定根路径,回忆TinyOS和Contiki都介绍过,主要是OS的Makefile.include路径,可以export,也可以自己修改根据你的源码的路径,网上级返回n个..,可以回忆contiki make

QUIET =                                   不多做介绍了,帮助文档都有

include $(RIOTBASE)/Makefile.include     回忆TinyOS和Contiki就清楚了


下面要说的是RIOT学习比较舒服,至少每个例程都有Readme.md这点和TinyOS如出一辙,Contiki确实应该加强文档工作


来看源码RIOT\examples\hello-world下main.c

#include <stdio.h>int main(void){    puts("Hello World!");    printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);    printf("This board features a(n) %s MCU.\n", RIOT_MCU);    return 0;}
呵呵,非常简单,不做介绍

下面来编译试试,进入该目录,

export BOARD=cc2538cb

make 

结果如下:



去目录底下查看可以看到hello_world.bin,如下图:


下载bin到cc2538cb节点,串口打印为下图:



hello_world介绍到此为止;下面进入default内容,makefile文件省略;这里我们将学习到RIOT的标准编译和测试流程;

hello_world相对简单一点,编译和测试就简单化了,default的功能在于一个串口的shell;可以自己查看支持的shell命令

我只是截取一部分:

2015-09-16 16:57:17,723 - INFO # help2015-09-16 16:57:17,725 - INFO # Command              Description2015-09-16 16:57:17,726 - INFO # ---------------------------------------2015-09-16 16:57:17,727 - INFO # reboot               Reboot the node2015-09-16 16:57:17,729 - INFO # ps                   Prints information about running threads.2015-09-16 16:57:17,731 - INFO # isl29020_init        Initializes the isl29020 sensor driver.2015-09-16 16:57:17,733 - INFO # isl29020_read        Prints data from the isl29020 sensor.2015-09-16 16:57:17,735 - INFO # lps331ap_init        Initializes the lps331ap sensor driver.2015-09-16 16:57:17,737 - INFO # lps331ap_read        Prints data from the lps331ap sensor.2015-09-16 16:57:17,739 - INFO # l3g4200d_init        Initializes the l3g4200d sensor driver.2015-09-16 16:57:17,740 - INFO # l3g4200d_read        Prints data from the l3g4200d sensor.2015-09-16 16:57:17,742 - INFO # lsm303dlhc_init      Initializes the lsm303dlhc sensor driver.2015-09-16 16:57:17,744 - INFO # lsm303dlhc_read      Prints data from the lsm303dlhc sensor.2015-09-16 16:57:17,746 - INFO # ifconfig             Configure network interfaces2015-09-16 16:57:17,747 - INFO # txtsnd               send raw data
需要说明的是除了export BOARD=cc2538cb需要指定 我们还需要指定ttyUSB,因为RIOT默认是ttyUSB1,但是我这边是ttyUSB0;

export  PORT=/dev/ttyUSB0即可:


源码不贴出来来了,看一下结果;

make编译:


到此已经生成了default.bin,咱们下载到cc2538cb中,这一步和helloword的测试一样;

下面咱们来测试一下:

输入命令:make flash或sudo make flash;


接下来我们输入make term 或sudo make term


查看Readme.md中支持的命令,怎么选择一个ps命令,查看进程;结果如下



总结:到此我们已经进入了RIOT的殿堂,注意BOARD RIOTBASE PORT这三个重要的环境变量,RIOT的编译步骤

make (得出bin文件)

make flash(得出native的调试文件)

make term (启动测试)

也可以简化成一条命令,或者只有第一条命令!

0 0