官方推荐 Ubuntu 16.04 操作系统,经测试,Ubuntu 14.04 也可以编译运行成功。本文档是基于16.04 64位操作系统编译。
Git zephyr库
git clone https://github.com/zephyrproject-rtos/zephyr.git
更新操作系统
Sudo apt-get update
Sudo apt-get upgrade
安装所依赖的软件
sudo apt-get install –no-install-recommends git cmake ninja-build gperf \ ccache doxygen dfu-util device-tree-compiler \ python3-ply python3-pip python3-setuptools xz-utils file make gcc-multilib \ autoconf automake libtool
cd ~/zephyr # or to your directory where zephyr is cloned
pip3 install –user -r scripts/requirements.txt
Cmake的版本需求要在3.8.2或者之上,本文档使用的是3.8.2,如果你版本低于3.8.2
mkdir HOME/cmake && cd
HOME/cmake && cd
HOME/cmake
wget https://cmake.org/files/v3.8/cmake-3.8.2-Linux-x86_64.sh
yes | sh cmake-3.8.2-Linux-x86_64.sh | cat
echo “export PATH=
PWD/cmake−3.8.2−Linux−x8664/bin:$PATH">>
P
W
D
/
c
m
a
k
e
−
3.8.2
−
L
i
n
u
x
−
x
86
6
4
/
b
i
n
:
$
P
A
T
H
">>
HOME/.zephyrrc
source /zephyr-env.sh
cmake –version
二、 安装编译器
下载ESP32编译工具
https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
mkdir -p ~/esp
cd ~/esp
tar -xzf ~/Downloads/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
设置环境变量
export PATH=”
PATH:
P
A
T
H
:
HOME/esp/xtensa-esp32-elf/bin”
下载SDK
cd ~/esp
在https://github.com/espressif/esp-idf.git中下载最新版本,如果出错则在
https://github.com/espressif/esp-idf/releases中下载esp-idf-v3.0-rc1.zip版本(该版本名字不一样设置环境变量的时候要注意),下载完后解压
或者直接git clone –recursive https://github.com/espressif/esp-idf.git
设置环境变量
export ZEPHYR_TOOLCHAIN_VARIANT=”espressif”
export ESP_IDF_PATH=”/path/to/esp-idf”
export ESPRESSIF_TOOLCHAIN_PATH=”/path/to/xtensa-esp32-elf/”
/path/to/请根据PWD来填写
三、 编译hello_world
cd $ZEPHYR_BASE/samples/hello_world
mkdir build && cd build
cmake -GNinja -DBOARD=esp32 ..
ninja flash
进入zephyr里面找到zephyr.bin,下载到开发板中就OK了