Zephyr简单使用

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.

你可能感兴趣的:(Zephyr)