星通智聯TB01 W600芯片 RT-Thread在蘋果MacOS+GCC環境下的編譯與固件刷寫

簡介

到手了一塊W600芯片的星通智聯TB01,與ESP8266相似,自帶wifi,但卻芯片內置1M 的存儲,並且可以使用RT-Thread系統,於是上手耍起來。
在這裏插入圖片描述在這裏插入圖片描述

剛拿到板子,發現真的非常小巧,呈星型排布的藍色LED非常有特色。板子上只有個MicroUSB,上電與刷寫固件均使用這個口,可以說是非常簡潔了。兩邊共放置了24個排針插孔,贈送插針沒有焊,整體看着非常舒爽。

下載官方的SDK(從QQ羣中獲取,github上也有),展開後,非常簡潔

➜  rt tree RT-Thread_W60X_SDK -L 1
RT-Thread_W60X_SDK
├── README.pdf
├── docs
├── drivers
├── examples
├── libraries
├── rt-thread
└── tools

6 directories, 1 file

相關的文檔也非常齊全,看着內心無比愉悅,趕緊上手搞起來!

環境

我使用的環境是MacOS+GCC

點燈

上手一塊板子,點燈可以說是第一課了。這裏官方提供的examples可以說是非常完整了:

➜  rt tree RT-Thread_W60X_SDK/examples -L 1
RT-Thread_W60X_SDK/examples
├── 01_basic_led_blink
├── 02_basic_key
├── 03_basic_rgb_led
├── 04_basic_beep
├── 05_basic_ir
├── 06_driver_lcd
├── 07_driver_temp_humi
├── 08_driver_als_ps
├── 09_component_fs_tf_card
├── 10_component_fal
├── 11_component_kv
├── 12_component_fs_flash
├── 13_component_ulog
├── 14_component_adbd
├── 15_component_micropython
├── 16_iot_wifi_manager
├── 17_iot_web_config_wifi
├── 18_iot_airkiss
├── 20_iot_at_server
├── 21_iot_mqtt
├── 22_iot_http_client
├── 23_iot_web_server
├── 24_iot_websocket
├── 25_iot_cjson
├── 26_iot_mbedtls
├── 27_iot_hw_crypto
├── 28_iot_ota_ymodem
├── 29_iot_ota_http
├── 30_iot_netutils
├── 31_iot_cloud_rtt
├── 32_iot_cloud_onenet
├── 33_iot_cloud_ali_iotkit
├── 34_iot_cloud_ms_azure
├── 35_iot_cloud_tencent
└── 36_iot_board_demo

35 directories, 0 files

我們首先使用第一個 01_basic_led_blink 進行學習和上手。

➜  rt tree RT-Thread_W60X_SDK/examples/01_basic_led_blink -L 1 
RT-Thread_W60X_SDK/examples/01_basic_led_blink
├── Bin
├── Kconfig
├── README.md
├── ROM.ini
├── SConscript
├── SConstruct
├── applications
├── build
├── cconfig.h
├── makeimg.bat
├── makeimg.py
├── project.ewp
├── project.eww
├── project.uvoptx
├── project.uvprojx
├── rtconfig.h
├── rtconfig.py
├── rtconfig.pyc
├── rtthread-w60x.map
├── rtthread.bin
├── rtthread.elf
├── template.ewp
├── template.uvoptx
└── template.uvprojx

3 directories, 21 files

這裏默認有Keil的工程文件,是針對使用Windows+keil的開發者使用的。而我是Mac用戶,習慣使用GCC,這裏就忽略那些工程文件了。

修改源碼

直接打開 examples/01_basic_led_blink/applications 就可以看到main.c,根據相關文檔,我們這裏只把led燈的引腳改爲TB01的一個LED即可,不過我這裏做了一點點小修改:

#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"

#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

/* 配置 LED 燈引腳 */
#define LED_PIN     PIN_LED_R
int pins[5] = {19, 20, 21, 22, 23};
int main(void)
{
    unsigned int count = 1;
    unsigned int i = 0;
    for (i = 0; i < 5; i++) {
        /* 設置 LED 引腳爲輸出模式 */
        rt_pin_mode(pins[i], PIN_MODE_OUTPUT);
    }
    while (count > 0)
    {
        for (i = 0; i < 5; i++) {
            /* LED 燈亮 */
            rt_pin_write(pins[i], PIN_LOW);
            LOG_D("led on, count: %d;pins[%d]", count, pins[i]);
            rt_thread_mdelay(500);
        }
        for (i = 0; i < 5; i++) {
            /* LED 燈滅 */
            rt_pin_write(pins[i], PIN_HIGH);
            LOG_D("led off");
            rt_thread_mdelay(500);
        }
        count++;
    }
    return 0;
}

不過根據文檔,還需要修改examples/01_basic_led_blink/rtconfig.h

/* W60x Device config */
#define SOC_W600_A8xx
// #define SOC_W601_A8xx

編譯

scons

編譯環境這個地方,需要修改配置文件:examples/01_basic_led_blink/rtconfig.py

EXEC_PATH   = '/Users/lee/rt/gcc-arm-none-eabi-6-2017-q1-update/bin'

這裏我採用的是gcc-arm-none-eabi-6-2017-q1-update版本,因爲最新版本編譯時,會有問題。(這裏先佔位,後續再寫篇文章詳細描述。)

固件生成

適配蘋果MacOS系統環境

SDK默認支持Windows 和 Linux 兩種系統,但是MacOS雖然與Linux同源,但仍有些區別,恰好,

tools/ota_packager/rt_ota_packaging_tool_cli
libraries/WM_Libraries/Tools/makeimg
libraries/WM_Libraries/Tools/makeimg_all
tools/update_fls

這幾個重要文件都沒有辦法在MacOS上使用:

➜  RT-Thread_W60X_SDK file libraries/WM_Libraries/Tools/makeimg 
libraries/WM_Libraries/Tools/makeimg: ELF 64-bit LSB pie executable x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=77563dbbf392d9903c683a52939eeaf7f152d10f, not stripped


在羣裏尋求幫助,但可惜沒有比較合適的辦法,只好自己編譯這幾個文件了。其實這幾個文件,除了rt_ota_packaging_tool_cli 之外,都在SDK中帶了源碼,編譯就好了。

➜  RT-Thread_W60X_SDK gcc libraries/WM_Libraries/Tools/makeimgsource/makeimg.c -o libraries/WM_Libraries/Tools/makeimg
➜  RT-Thread_W60X_SDK gcc libraries/WM_Libraries/Tools/makeimgsource/makeimg_all.c -o libraries/WM_Libraries/Tools/makeimg_all

 

就這麼簡單,makeimgmakeimg_all 就編譯成功了。運行一下:

➜  RT-Thread_W60X_SDK ./libraries/WM_Libraries/Tools/makeimg                                                                  

param cnt error
參數0:  exe
參數1:  輸入bin文件 ,原始文件或者壓縮檔文件
參數2 : 輸出文件
參數3:  輸入IMAGE類型,0:user image,1:reserved,2:secboot
參數4:  輸入壓縮類型標誌,0:非壓縮,1:壓縮
參數5:  版本號文件
參數6: 輸入image存放位置
參數7: 輸入image運行位置
參數8: 輸入原始image文件
➜  RT-Thread_W60X_SDK ./libraries/WM_Libraries/Tools/makeimg_all

param cnt error
參數0:  exe
參數1:  輸入secboot.img文件
參數2:  輸入image文件
參數3 : 輸出文件
➜  RT-Thread_W60X_SDK 
 
 

非常順利。

接下來就是 update_fls

➜  RT-Thread_W60X_SDK gcc tools/make_fal/crc32.c tools/make_fal/make_fal.c -Itools/make_fal/ -o tools/update_fls          
➜  RT-Thread_W60X_SDK file tools/update_fls
tools/update_fls: Mach-O 64-bit executable x86_64
➜  RT-Thread_W60X_SDK tools/update_fls 
param cnt error!
param 0: .
param 1: input FLS file
param 2: input FAL file
param 3: output FLS file
➜  RT-Thread_W60X_SDK 
 
 

同樣順利。

編譯生成固件

剩下就是標準步驟了:

➜  RT-Thread_W60X_SDK cd examples/01_basic_led_blink 
➜  01_basic_led_blink python makeimg.py 
makeimg rtthread.rbl ...
/bin/sh: /Users/lee/rt/RT-Thread_W60X_SDK/tools/ota_packager/rt_ota_packaging_tool_cli: cannot execute binary file
makeimg 1M Flash...
makeimg 2M Flash...
end
➜  01_basic_led_blink ls -t Bin
rtthread_layout_16M.FLS  rtthread_layout_1M.FLS   version.txt           
 
  
     

這樣,我們的固件就生成了。

刷寫固件

但是,另一個問題來了,怎麼下載到板子上呢?官方提供的刷寫都是在Windows下,使用自家開發的串口工具進行下載的,雖然非常方便,但是對於我這個工作環境不適用啊?

參考文檔

本來這個問題讓我挺頭大的,但是,其實解決起來確實非常簡單。

在官方提供的文檔中libraries/WM_Libraries/Doc/WM_W60X_固件升級指導_V1.2.pdf

中,明確指出,可以使用secureCRT工具進行刷寫固件。

恰巧,我的MacOS系統也安裝了這個secureCRT工具。

刷寫方法

文檔中已經寫的非常詳細了,我這邊簡單寫一下就是:TB01開發板,只需要按住key鍵,再按一下Reset鍵,鬆開兩個按鍵,即可進入刷機模式,然後拖拽固件rtthread_layout_1M.FLS 到窗口中,使用Xmodem選項下載,等待下載完成,再次按下Reset即可。就是這麼簡單。

總結

至此,終於可以愉快的在星通智聯TB01 W600芯片 上使用RT-Thread了。

縱觀整個過程,我也有過很多迷茫,中間求助羣友,被冷嘲熱諷了一下,但是經過不懈的學習,查閱資料,終於解決了自己的問題,內心還是很有成就感的。

至於我使用什麼樣的環境,也許並不跟我的信仰、道德、人品掛鉤。並且,豐富開發環境,讓開發者能夠更簡單的使用,降低上手門檻,讓更多不同平臺的開發者都可以參與其中,這不跟星通智聯TB01的設計理念相通嗎?

這也提醒着我,今後如果碰到別的羣友遇到了他們解決不了的問題,不要站在道德或知識的至高點去打擊他們,而是鼓勵、幫助他們解決問題,這才能成爲一個 更好的自己

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章