1. 程式人生 > >RIOT 基於CC2538cb套件學習2,編譯測試default和helloword

RIOT 基於CC2538cb套件學習2,編譯測試default和helloword

春節過後的第一次寫部落格,讓我繼續帶大家來看看身為菜鳥的我繼續RIOT的學習之旅;

上一篇已經初步介紹了 RIOT的啟動過程,這一次咱們不再多說直接make download測試下:

本次挑選兩個例程在RIOT/examples下的default和helloword實驗:

RIOT的API幫助首頁為http://www.riot-os.org/api/index.html,比Contiki好一點在於可以搜尋;

下面開始第一個例程helloword,應該算是最簡單的例程程式碼了;一如既往首先介紹

makefile

# name of your application
APPLICATION = 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 ?= 1

include $(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 # help
2015-09-16 16:57:17,725 - INFO # Command              Description
2015-09-16 16:57:17,726 - INFO # ---------------------------------------
2015-09-16 16:57:17,727 - INFO # reboot               Reboot the node
2015-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 interfaces
2015-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 (啟動測試)

也可以簡化成一條命令,或者只有第一條命令!