Zephyr编译环境切换到Windows
本文说明如何在Windows10下编译Zephyr和相关环境设置.
由于Ubuntu在ThinkPad上风扇的管理不太好,无论CPU稳定多少风扇都一直转。平时做开发调试还好,但要做一些长时间的文字工作,风扇的声音就有点不能忍受了,所以还是切回到windows 10下面,但还是想同时能编译Zephyr,因此就又在windows 10下搭建了Zephyr的环境。注意 本文所使用的方法是在WSL下编译Zephyr,这并不是官方推荐的
Due to issues finding executables, the Zephyr Project doesn’t currently support application flashing using the Windows Subsystem for Linux (WSL) (WSL).
Therefore, we don’t recommend using WSL when getting started.
在实际使用过程中,可以正常编译出zephyr,烧写的问题是由于我的使用的板子带有DAPLink支持MSC,因此烧写image可以直接向虚拟U盘内推拽完成。
WSL安装 链接到标题
参考WSL体验一文,最后选择ubuntu 18.04安装即可。 注意:使用WSL,不推荐使用WSL2,因为WSL2文件I/O非常慢,会导致编译Zephyr慢,实际测试编译相同的代码WSL比WSL2快4倍。这是由于 Windows 和 Linux 两种文件系统的兼容性尚未被很好的处理。 详细的讨论可参见https://github.com/microsoft/WSL/issues/4197和https://github.com/microsoft/WSL/issues/4739这两个 issue。
Zephyr 链接到标题
启动WSL后进入Ubuntu18.04,Zephyr的安装直接按照官方文档的Ubuntu步骤进行
环境安装 链接到标题
更新安装包 链接到标题
sudo apt update
sudo apt upgrade
安装依赖 链接到标题
sudo apt install --no-install-recommends git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev
确认Cmake版本
cmake --version
如果cmake版本低于3.13.1,使用下面方法安装
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
sudo apt update
sudo apt install cmake
获取Zephyr并安装python依赖 链接到标题
安装west
pip3 install --user -U west
echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
source ~/.bashrc
下载zephyr代码
west init ~/zephyrproject
cd ~/zephyrproject
west update
导出cmake包
west zephyr-export
安装zephyr需要的依赖
pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt
安装toolchain 链接到标题
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.3/zephyr-sdk-0.11.3-setup.run
chmod +x zephyr-sdk-0.11.3-setup.run
./zephyr-sdk-0.11.3-setup.run -- -d ~/zephyr-sdk-0.11.3
编译代码 链接到标题
cd ~/zephyrproject/zephyr
west build -p auto -b swiftio_mm samples/basic/blinky
编译问题解决 链接到标题
dtc版本过低
echo "export PATH=$ZEPHYR_SDK_INSTALL_DIR/sysroots/x86_64-pokysdk-linux/usr/bin:\$PATH" >> $HOME/.zephyrrc
echo ". ~/.zephyrrc" >> $HOME/.bashrc
zephyr目录以外无法用west编译 设置ZEPHYR_BASE
export ZEPHYR_BASE=/mnt/e/westz/zephyrproject/zephyr
参考 链接到标题
https://docs.zephyrproject.org/latest/getting_started/index.html