Zephyr 官網
https://www.zephyrproject.org/
簡介
Zephyr 是一個爲了IoT設備使用的RTOS, 是 Linux Foundation 開發的。
看到有幾個好處:
1.架構和Linux非常相似,使用起來很順手
2.Apache license, 限制少,適合商用應用
SDK環境搭建
Follow 官方的文檔
https://www.zephyrproject.org/doc/getting_started/installation_linux.html
逐步安裝就可以,因爲交叉編譯器的原因,目前只能在64位電腦上安裝SDK。(32位上會安裝失敗)
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git make gcc g++ ncurses-dev doxygen dfu-util device-tree-compiler python3-ply python3-pip
wget https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases/download/0.9.1/zephyr-sdk-0.9.1-setup.run
chmod +x zephyr-sdk--setup.run
./zephyr-sdk--setup.run
需要選擇安裝目錄,選擇自己的用戶目錄即可
export ZEPHYR_GCC_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=/home/xxx/zephyr-sdk
;;需要在源代碼目錄下執行下面命令
pip3 install –user -r scripts/requirements.txt
源代碼
git clone https://github.com/zephyrproject-rtos/zephyr.gitzephyr-project
編譯
cd zephyr-project
source zephyr-env.sh
make BOARD=xxx
測試
我拿了一塊 STM32L471 單片機板子,雖然默認沒有L471的board,
不過選擇 L475/L476/L496來跑一些最基本功能都應該可以。
board nucleo_l476rg 和我的板子設置比較接近,所以我選擇這個來編譯
LED Blinky
cd samples/basic/blinky
make BOARD=nucleo_l476rg
LED 對應的GPIO只要在 boards/arm/disco_l475_iot1/board.h
設置一下就可以了。
編譯完成後,會生成 outdir/nucleo_l476rg/zephyr.bin
用 j-link 燒錄到板子上,就可以看到LED閃爍
Shell
cd samples/subsys/shell/shell
make BOARD=nucleo_l476rg
燒到板子上,可以看到一個簡單的console shell
Latency measure
cd tests/benchmarks/latency_measure
make BOARD=nucleo_l476rg
***** BOOTING ZEPHYR OS v1.9.0-rc2 - BUILD: Sep 18 2017 03:23:18 *****
|-----------------------------------------------------------------------------|
| Latency Benchmark |
|-----------------------------------------------------------------------------|
| tcs = timer clock cycles: 1 tcs is 12 nsec |
|-----------------------------------------------------------------------------|
| 1 - Measure time to switch from ISR back to interrupted thread |
| switching time is 226 tcs = 2825 nsec |
|-----------------------------------------------------------------------------|
| 2 - Measure time from ISR to executing a different thread (rescheduled) |
| switch time is 372 tcs = 4650 nsec |
|-----------------------------------------------------------------------------|
| 3 - Measure average time to signal a sema then test that sema |
| Average semaphore signal time 51 tcs = 638 nsec |
| Average semaphore test time 33 tcs = 413 nsec |
|-----------------------------------------------------------------------------|
| 4- Measure average time to lock a mutex then unlock that mutex |
| Average time to lock the mutex 107 tcs = 1339 nsec |
| Average time to unlock the mutex 90 tcs = 1127 nsec |
|-----------------------------------------------------------------------------|
| 5 - Measure average context switch time between threads using (k_yield) |
| Average thread context switch using yield 208 tcs = 2608 nsec |
|-----------------------------------------------------------------------------|
| 6 - Measure average context switch time between threads (coop) |
| Average context switch time is 213 tcs = 2668 nsec |
|-----------------------------------------------------------------------------|
===================================================================
PROJECT EXECUTION SUCCESSFUL
boot time
tests/benchmarks/boot_time
starting test - Boot Time Measurement
Boot Result: Clock Frequency: 80 MHz
__start : 0 cycles, 0 us
_start->main(): 2372 cycles, 29 us
_start->task : 2434 cycles, 30 us
_start->idle : 2891 cycles, 36 us
Boot Time Measurement finished
PASS - main.