说明:
本学笔记基于zephyr 工程版本 2.2.99,主机环境为ubuntu18.04
详细内容参考:https://docs.zephyrproject.org/latest/getting_started/index.html
主要记录学习中遇到的问题
1 ubuntu配置
1.1 ubuntu需求
ubuntu需要使用18.04及以上版本,当时用其他低版本时会出现各种各样的问题。主要表现在安装的一些开发工具版本过低。如pip3工具包,zephyr工程的west工具等。本人曾尝试使用16.04版本搭建开发环境,即使更新源(apt update,apt upgrade)后依然无法安装最新版的工具。比如west工具在ubuntu16.04中安装的最新版本是0.62,安装后在zephyr2.2.99中使用时会出现各样的问题。而在ubuntu18.04中则不会出现问题。在zephyr文档中,也强调需要使用18.04及以后的版本。希望其他童鞋不要走弯路。
1.2 准备ubuntu
1.2.1.安装ubuntu18.04
1.2.2.更新ubuntu
sudo apt update
sudo apt upgrade
1.2.3 安装工具包
sudo apt install --no-install-recommends git cmake ninja-build gperf
ccache dfu-util device-tree-compiler wget \ python3-pip
python3-setuptools python3-tk python3-wheel xz-utils file \ make gcc
gcc-multilib g+±multilib libsdl2-dev
1.2.4 检查cmake版本
a.检查安装的版本是3.13.1或更高
cmake --version
b.如果不符合版本要求需要手动安装
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
1.2.5 安装west工具
pip3 install --user -U west echo ‘export PATH=~/.local/bin:"$PATH"’ >>
~/.bashrc source ~/.bashrc
2 zephyr工程安装
2.1 下载zephyrproject源码
cd ~
west init zephyrproject
cd zephyrproject
west update
注意:整个过程非常慢,资源从github下载的,如果能有梯子,建议使用梯子,否则整个过程大概3个小时。
2.2 导出cmake包
west zephyr-export
2.3 使用pip3安装其他依赖的工具包
pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt
2.4 安装zephyr的开发工具链
下载zephyr-sdk-0.11.2-setup.run到home目录
cd ~ wget
https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.2/zephyr-sdk-0.11.2-setup.run
注意:这个下载非常慢,我尝试很多次都失败了。可以将
https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.2/zephyr-sdk-0.11.2-setup.run链接复制到迅雷,通过迅雷下载非常快。下载好zephyr-sdk-0.11.2-setup.run后,拷贝到你的ubuntu的home目录中。
2.5 安装zephyr-sdk-0.11.2-setup.run
chmod +x zephyr-sdk-0.11.2-setup.run ./zephyr-sdk-0.11.2-setup.run –
-d ~/zephyr-sdk-0.11.2
2.6 添加变量到.bashrc中
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr export
ZEPHYR_SDK_INSTALL_DIR=~/zephyr-sdk-0.11.2
2.7 安装udev规则文件
sudo cp
${ZEPHYR_SDK_INSTALL_DIR}/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules
/etc/udev/rules.d sudo udevadm control --reload
3 编译工程
3.1 编译源码(我用的是nrf52840DK开发板)
注意:命令执行需要在 zephyrproject/zephyr/ 目录下,而不是zephyrproject或其他*
west build -p auto -b nrf52840dk_nrf52840 samples/basic/blinky
3.2 编译完成功,显示如下内容
[120/125] Linking C executable zephyr/zephyr_prebuilt.elf Memory
region Used Size Region Size %age Used
FLASH: 13120 B 1 MB 1.25%
SRAM: 5224 B 256 KB 1.99%
IDT_LIST: 56 B 2 KB 2.73% [125/125] Linking C executable zephyr/zephyr.elf
3.3 编译后生成的文件包含在 zephyrproject/zephyr/build/zephyr/ 目录下:
3.4 烧写程序到开发板
3.4.1 可以将zephyr.hex拷贝到windows下,通过nRF Connect的Programmer软件烧写。
3.4.2 通过ubuntu下的wset工具命令烧写
west flash
注意:使用这个命令需要在ubuntu下安装nRF-Command-Line-Tools和j-link驱动,否则报错
4 安装nRF-Command-Line-Tools
4.1 下载nRF-Command-Line-Tools(下载后文件:nRFCommandLineTools1070Linuxamd64.tar.gz)
https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Command-Line-Tools/Download#infotabs
4.2 解压nRFCommandLineTools1070Linuxamd64.tar.gz,包括如下文件:
nRF-Command-Line-Tools_10_7_0_Linux-amd64.deb
JLink_Linux_V662b_x86_64.deb
4.3 通过ubuntu的文件浏览器安装找到上面两个文件,双击安装
4.4 执行nrfjprog -v命令,如显示版本号代表安装成功
4.5 连接j-link到ubuntu
1.虚拟机->可移动设备->SEGGER j-link->连接
2.执行lsusb命令如果现实SEGGER字样设备,代表j-link已经连接到ubuntu
4.5 在zephyrproject/zephyr下执行west flash命令烧写程序,显示如下代表烧写成功,LED开始闪烁:
结束
如有错误欢迎留言