由于github不是很稳定,按照zephyr官网的手册搭建开发环境,总是会在west update更新仓库时失败。所以参考了网络上的文章记录下可行的办法。
文章参考:https://www.devicemanger.cn/src/zephyr-doc/index.html
1.使用python3安装west并添加到环境变量
pip3 install --user -U west
echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
source ~/.bashrc
2.下载zephyr源码
这一步是关键,由于github不稳定,直接在github下载会失败。方法是使用gitee镜像替代
west init ~/zephyrproject -m https://gitee.com/zephyr-rots/zephyr --mr v2.3.0
3.下载zephyr外部模块
这一步也是需要更换源地址,进入zephyr目录,打开west.yaml,修改github地址为gitee地址。
修改完成后就可以执行命令下载模块代码
west update
4.安装zephyr的python3依赖
pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt
5.安装工具链
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.4/zephyr-sdk-0.11.4-setup.run
- 运行安装程序,将SDK安装在中
~/zephyr-sdk-0.11.4
chmod a+x zephyr-sdk-0.11.4-setup.run
./zephyr-sdk-0.11.4-setup.run -- -d ~/zephyr-sdk-0.11.4
- 安装udev规则,该规则允许您以常规用户身份刷新大多数Zephyr指令
sudo cp ~/zephyr-sdk-0.11.4/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload
6.设置完以上步骤后就可以执行编译,但是可能会报错,需要执行
chmod a+x zephyr-env.sh
source zephyr-env.sh