jollen / blog

Jollen's Blog
http://www.jollen.org/blog
66 stars 4 forks source link

使用 ESP8266 做為 FreeRTOS 的學習與開發環境 #8

Closed jollen closed 8 years ago

jollen commented 8 years ago

本文介紹,如何將 ESP8266 的 firmware 更新為 FreeRTOS,將 ESP8266 做為 FreeRTOS 的學習平台。以下是使用 ESP8266 做為 FreeRTOS 學習或實驗平台的要點:

使用 FreeRTOS 在 ESP8266 平台上,打造 IoT 應用程式時,必須具備以下條件:

為滿足以上的條件,利用了開發 WoT.City 的機會,維護了 rtos-wot 專案,打造一個用於學習 FreeRTOS + IoT 的 FreeRTOS 特別版本(distribution)。

以下是開發環境的架設教學,教學內容以 Mac 環境為主。

安裝 ESP Open SDK

在 MacOS 系統建置 ESP8266 的編譯環境。首先,確認是否已安裝 Xcode command line tools:

$ xcode-select --install

再使用 homebrew 安裝所需的套件:

$ brew tap homebrew/dupes
$ brew install binutils coreutils autoconf automake wget gawk libtool gperf gnu-sed --with-default-names grep bison libvorbis
$ export PATH=/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/gperf/bin:$PATH

製作一個 "case-sensitive"(可區分大小寫檔名)的虛擬磁碟,大小是 8GB:

$ hdiutil create ./eos.dmg -volname "esp-open-sdk" -size 8g -fs "Case-sensitive HFS+"

將 ESP8266 Open SDK 下載至此虛擬磁碟:

$ hdiutil mount ./eos.dmg
$ cd /Volumes/esp-open-sdk
$ git clone --recursive https://github.com/pfalcon/esp-open-sdk.git
$ cd eps-open-sdk

編譯 "separated SDK":

$ make STANDALONE=n

編譯完成後的畫面:

Xtensa toolchain is built, to use it:

export PATH=/Volumes/esp-open-sdk/esp-open-sdk/xtensa-lx106-elf/bin:$PATH

Espressif ESP8266 SDK is installed. Toolchain contains only Open Source components
To link external proprietary libraries add:

xtensa-lx106-elf-gcc -I/Volumes/esp-open-sdk/esp-open-sdk/sdk/include -L/Volumes/esp-open-sdk/esp-open-sdk/sdk/lib

根據畫面提示,修改 PATH 環境變數:

$ export PATH=/Volumes/esp-open-sdk/esp-open-sdk/xtensa-lx106-elf/bin:$PATH

完成 ESP8266 Toolchain 的安裝,接下來就可以開始編譯 rtos-wot 了。

編譯 FreeRTOS Application Firmware

安裝 pyserial 套件:

$ git clone https://github.com/pyserial/pyserial.git
$ cd pyserial/
$ sudo python setup.py install

下載 rtos-wot 原始碼:

$ git clone https://github.com/wot-sdk/rtos-wot

編輯 include/ssid_config.h 檔案,設定 WiFi 的 SSID 與密碼

#define WIFI_SSID "<the-SSID>"
#define WIFI_PASS "<your-passworld>"

完成後,挑選一個 RTOS 應用程式,並進行 firmware 編譯:

$ cd examples/blink
$ make

編譯完成後,在目前的應用程式路徑下,得到以下二個檔案:

將以上二個檔案燒錄至 ESP8266 更新即可,指令如下:

$ make flash ESPPORT=/dev/cu.SLAB_USBtoUART 

在 Linux 環境編譯 NodeMCU firmware,請另行參考這篇文章(#1)說明。

使用 esptool 更新 ESP8266 Firmware

如果要使用 esptool.py 工具,手動更新 firmware 檔案的話,指令如下:

$ esptool.py --port /dev/cu.SLAB_USBtoUART write_flash -fm=dio -fs=32m 0x00000 bin/0x00000.bin 0x10000 bin/0x10000.bin

在 Mac 下使用 esptool.py 更新 NodeMCU firmware 時,需額外加上 -fm-fs 二個參數:

關於 RTOS WoT 計畫

本文使用的 RTOS WoT 版本,是專為 ESP8266 製作的 FreeRTOS 學習、教學與實驗平台。RTOS WoT 的目標是打造一個 Web of Things 的 RTOS SDK。

RTOS WoT 也在 RTOS Application Layer 做了一些增加,請參考以下文章:

jollen commented 8 years ago

2016-01-27 7 01 18

shindar90 commented 8 years ago

谢谢你的文章,cd eos-open-sdk 应该是 cd eps-open-sdk,虽然问题不大,还是提一下。

jollen commented 8 years ago

@shindar90 謝謝你的反饋,已修正。