前言

nRF Connect SDK 包括 libs 和 app demo,该 SDK + DEMO 是基于 ZephyrOS 实现的(因此,环境搭建会稍微麻烦亿点点)!

该 SDK 支持 nRF52, nRF53, and nRF91 系列芯片。

接下来会一步步介绍如何在 Arch Linux 上搭建该 SDK 的开发环境:

  • Zephyr requirements and GNU ARM Embedded Toolchain
  • nRF Connect SDK
  • SEGGER Embedded Studio

1、概述

首先下载 nRF Connect for Desktop,linux上是个绿色版本,直接启动即可:

然后根据 Getting Started Assistant 指导进行安装。

更详细的指导在(推荐用更详细的指导,因为上面的指导受GUI限制,不能放很详细的说明,新手手动安装,容易出现问题):

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_installing.html#build-environment-cli

2、安装工具

安装:git、wget、cmake、make、dtc、tk

注: 输入 cmake --version 校验 cmake 的版本,nRF Connect SDK 需要 cmake 的版本 ≥ 3.13.1。

安装 ninja-build:

Ninja is a small build system with a focus on speed. It differs from other build systems in two major respects: it is designed to have its input files generated by a higher-level build system, and it is designed to run builds as fast as possible.

sudo pacman -S ninja

安装 GPerf:

GNU gperf is a perfect hash function generator. For a given list of strings, it produces a hash function and hash table, in form of C or C++ code, for looking up a value depending on the input string. The hash function is perfect, which means that the hash table has no collisions, and the hash table lookup needs a single string comparison only.

sudo pacman -S gperf

安装 ccache:

Ccache (or “ccache”) is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Ccache is free software, released under the GNU General Public License version 3 or later. See also the license page.

sudo pacman -S ccache

安装 dfu-util:

dfu-util is a host side implementation of the DFU 1.0 and DFU 1.1 specifications of the USB forum.

sudo pacman -S dfu-util

安装 python-pip (3):

sudo pacman -S  python-pip

安装 python-setuptools(3):

sudo pacman -S python-setuptools

安装 python 轮子工具 python-wheel (3):

sudo pacman -S python-wheel

安装压缩工具 xz-utils:

sudo pacman -S xz

安装 file (linux 的 file 命令):

sudo pacman -S file

安装 west:

west 是 ZephyrOS 用来做 CI 的工具。

west 不能pip直接安装,因为安装的版本太老了,0.8.0的,而我们这里需要用最新的版本(0.11.1),因此要拉取源码,自己安装:

git clone git@github.com:zephyrproject-rtos/west.git
cd west
git checkout v0.11.1
sudo pip install . #一定要sudo

3、获取 nRF Connect SDK 源码

nRF Connect SDK 包含 4 个 GitHub 仓库,设置 nRF Connect SDK,需要将这些仓库都拉取下来,并且安装必要的 python modules。

mkdir ncs
cd ncs
west init -m https://github.com/nrfconnect/sdk-nrf --mr master
west update #clone the project repositories, long time
west zephyr-export

操作完之后,NCS 的目录结构如下:

ncs
|___ .west
|___ bootloader
|___ modules
|___ nrf
|___ nrfxlib
|___ zephyr
|___ ...

4、安装 Python modules

cd <sourcecode_root>/ncs
pip3 install --user -r zephyr/scripts/requirements.txt
pip3 install --user -r nrf/scripts/requirements.txt
pip3 install --user -r bootloader/mcuboot/scripts/requirements.txt

5、安装 toolchain

为了实现交叉编译应用程序,我们需要下载安装 GNU Arm Embedded Toolchain。

注意:一定要注意选择的 Toolchain 的版本一定要 ≥ 9-2019-q4-major 版本要求。

设置 toolchain 一般需要如下步骤:

  • 下载
  • 解压到 ~/gnuarmemb 下(推荐)
  • 加入环境变量
#Install the GNU Arm Embedded Toolchain
#https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.07/gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2
tar xvf gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2
mv gcc-arm-none-eabi-10.3-2021.07 gnuarmemb
mv gnuarmemb ~/ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
export GNUARMEMB_TOOLCHAIN_PATH="~/gnuarmemb"

6、下载 nRF Command Line Tools

The nRF Command Line Tools is used for development, programming and debugging of Nordic Semiconductor's nRF51, nRF52, nRF53 and nRF91 Series devices.

主要功能:

  • nrfjprog executable - tool for programming through SEGGER J-LINK programmers and debuggers
  • mergehex executable - enables you to combine up to three .HEX files into one single file
  • nrfjprog DLL - a DLL that exports functions for programming and controlling nRF51, nRF52, nRF53 and nRF91 Series devices and lets developers create their own development tools using the DLLs API
  • SEGGER J-Link software and documentation pack

我们主要用其 nrfjprog 烧写固件。

https://www.nordicsemi.com/Products/Development-tools/nRF-Command-Line-Tools/Download#infotabs

nordic 将其工具弄个俄罗斯套娃,大家直接看命令:

#Install nRF-command-Line-Tools
wget https://www.nordicsemi.com/-/media/Software-and-other-downloads/Desktop-software/nRF-command-line-tools/sw/Versions-10-x-x/10-13-0/nRF-Command-Line-Tools_10_13_0_Linux64.zip
unzip nRF-Command-Line-Tools_10_13_0_Linux64.zip
cd nRF-Command-Line-Tools_10_13_0_Linux64
tar -xzf nRF-Command-Line-Tools_10_13_0_Linux-amd64.tar.gz
tar xvf nRF-Command-Line-Tools_10_13_0.tar
mv nrfjprog ~/
export PATH=${HOME}/nrfjprog:"$PATH"

注:可能会报下面的错误:

-- west flash: using runner nrfjprog

ERROR: JLinkARM DLL is invalid. Please reinstall latest JLinkARM DLL.

FATAL ERROR: command exited with status 31: nrfjprog --ids

make[3]: *** [zephyr/cmake/flash/CMakeFiles/flash.dir/build.make:72: zephyr/cmake/flash/CMakeFiles/flash] Error 31

make[2]: *** [CMakeFiles/Makefile2:4072: zephyr/cmake/flash/CMakeFiles/flash.dir/all] Error 2

make[1]: *** [CMakeFiles/Makefile2:4079: zephyr/cmake/flash/CMakeFiles/flash.dir/rule] Error 2

make: *** [Makefile:878: flash] Error 2

需要安装 Jlink:yaourt -S jlink (网速要好!!!)

make flash 时报错

-- runners.nrfjprog: Flashing file: /home/btfz/Desktop/apple/ncs/nrf/samples/bluetooth/peripheral_bms/build/zephyr/zephyr.hex

ERROR: JLinkARM DLL reported an error. Try again. If error condition

ERROR: persists, run the same command again with argument --log, contact Nordic

ERROR: Semiconductor and provide the generated log.log file to them.

FATAL ERROR: command exited with status 33: nrfjprog --program /home/btfz/Desktop/apple/ncs/nrf/samples/bluetooth/peripheral_bms/build/zephyr/zephyr.hex --sectoranduicrerase -f NRF52 --snr 682428062

make[3]: *** [zephyr/cmake/flash/CMakeFiles/flash.dir/build.make:72: zephyr/cmake/flash/CMakeFiles/flash] Error 33

make[2]: *** [CMakeFiles/Makefile2:4072: zephyr/cmake/flash/CMakeFiles/flash.dir/all] Error 2

make[1]: *** [CMakeFiles/Makefile2:4079: zephyr/cmake/flash/CMakeFiles/flash.dir/rule] Error 2

make: *** [Makefile:878: flash] Error 2

需要用 sudo 权限运行 nrfjprog --program /home/btfz/Desktop/apple/ncs/nrf/samples/bluetooth/peripheral_bms/build/zephyr/zephyr.hex --sectoranduicrerase -f NRF52 --snr 682428062

7、编译运行

➜  ncs cd nrf/samples/bluetooth/peripheral_bms/
➜ peripheral_bms git:(master) source ../../../../zephyr/zephyr-env.sh
➜ peripheral_bms git:(master) rm -rf build && mkdir build && cd build && cmake -DBOARD=nrf52dk_nrf52832 .. && make ... [ 94%] Building C object modules/segger/CMakeFiles/modules__segger.dir/home/btfz/Desktop/apple/ncs/modules/debug/segger/SEGGER/SEGGER_RTT.c.obj
[ 94%] Building C object modules/segger/CMakeFiles/modules__segger.dir/SEGGER_RTT_zephyr.c.obj
[ 95%] Linking C static library libmodules__segger.a
[ 95%] Built target modules__segger
[ 95%] Building C object zephyr/CMakeFiles/zephyr_prebuilt.dir/misc/empty_file.c.obj
[ 96%] Linking C executable zephyr_prebuilt.elf
Logical command for additional byproducts on target: zephyr_prebuilt [ 96%] Built target zephyr_prebuilt
Scanning dependencies of target linker_zephyr_final_script_target
[ 96%] Generating linker.cmd
[ 96%] Built target linker_zephyr_final_script_target
[ 96%] Generating isr_tables.c, isrList.bin
[ 97%] Generating dev_handles.c
[ 97%] Building C object zephyr/CMakeFiles/zephyr_final.dir/misc/empty_file.c.obj
[ 98%] Building C object zephyr/CMakeFiles/zephyr_final.dir/isr_tables.c.obj
[ 98%] Building C object zephyr/CMakeFiles/zephyr_final.dir/dev_handles.c.obj
[100%] Linking C executable zephyr.elf
Memory region Used Size Region Size %age Used
FLASH: 168248 B 512 KB 32.09%
SRAM: 29325 B 64 KB 44.75%
IDT_LIST: 0 GB 2 KB 0.00%
Generating files from zephyr.elf for board: nrf52dk_nrf52832
[100%] Built target zephyr_final

8、烧写

烧写直接用 sudo make flash,注意一定要用 sudo,此外,在安装 west 的时候也一定要用 sudo,否则会报如下错误:

/usr/bin/python3.9: No module named west
make[3]: *** [zephyr/cmake/flash/CMakeFiles/flash.dir/build.make:72: zephyr/cmake/flash/CMakeFiles/flash] Error 1
make[2]: *** [CMakeFiles/Makefile2:4072: zephyr/cmake/flash/CMakeFiles/flash.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:4079: zephyr/cmake/flash/CMakeFiles/flash.dir/rule] Error 2
make: *** [Makefile:878: flash] Error 2

9、全自动环境构建脚本

以我的风格,必须要写一个自动化构建环境脚本:(运行该脚本时,务必保证网速到位!!!)

#!/bin/bash
#https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_installing.html#id10 CUR_PATH=$(cd `dirname $0`; pwd)
TOOLS_PATH=$CUR_PATH/tools
NCS_PATH=$CUR_PATH/ncs mkdir $TOOLS_PATH
#Install the required tools
sudo pacman -S git cmake ninja gperf ccache dfu-util dtc wget \
python-pip python-setuptools python-wheel tk xz file make cmake cmake --version
dtc --version
python3 --version #To install the GN tool, complete the following steps:
mkdir $TOOLS_PATH/gn && cd $TOOLS_PATH/gn
wget -O gn.zip https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest
unzip gn.zip
rm gn.zip export PATH=$TOOLS_PATH/gn:"$PATH" #Install west
mkdir $TOOLS_PATH/west && cd $TOOLS_PATH/west
git clone git@github.com:zephyrproject-rtos/west.git
cd west
git checkout v0.11.1
sudo pip install . ###mast sudo #Install the GNU Arm Embedded Toolchain
#https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
cd $TOOLS_PATH
wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.07/gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2
tar xvf gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2
mv gcc-arm-none-eabi-10.3-2021.07 gnuarmemb export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
export GNUARMEMB_TOOLCHAIN_PATH=$TOOLS_PATH/gnuarmemb #Install nRF-command-Line-Tools
cd $TOOLS_PATH
wget https://www.nordicsemi.com/-/media/Software-and-other-downloads/Desktop-software/nRF-command-line-tools/sw/Versions-10-x-x/10-13-0/nRF-Command-Line-Tools_10_13_0_Linux64.zip
unzip nRF-Command-Line-Tools_10_13_0_Linux64.zip
cd nRF-Command-Line-Tools_10_13_0_Linux64
tar -xzf nRF-Command-Line-Tools_10_13_0_Linux-amd64.tar.gz
tar xvf nRF-Command-Line-Tools_10_13_0.tar
mv nrfjprog ../ export PATH=$TOOLS_PATH/nrfjprog:"$PATH" #Install JLink
tar zxvf JLink_Linux_V750a_x86_64.tgz
mv JLink_Linux_V750a_x86_64 ../JLink
export PATH=$TOOLS_PATH/JLink:"$PATH" cd ..
rm -rf nRF-Command-Line-Tools_10_13_0_Linux64 #Get the nRF Connect SDK code
mkdir $NCS_PATH && cd $NCS_PATH
west init -m https://github.com/nrfconnect/sdk-nrf --mr master
west update
west zephyr-export tree -L 1 #Install additional Python dependencies
pip3 install --user -r zephyr/scripts/requirements.txt
pip3 install --user -r nrf/scripts/requirements.txt
pip3 install --user -r bootloader/mcuboot/scripts/requirements.txt

链接


: ** 我做了一系列全自动构建编译环境的工程,目前可以覆盖:51单片机、stm8、esp8266、esp32、nrf51822、nrf52832、android,欢迎到我的 nbtool github 下交流:https://github.com/nbtool **

[编译] 9、在Linux下搭建 nordic 最新基于 zephyr 的开发烧写环境的更多相关文章

  1. [编译] 3、在Linux下搭建51单片机的开发烧写环境(makefile版)

    星期二, 10. 七月 2018 01:01上午 - beautifulzzzz 一.SDCC(Small Device C Compiler)编译环境搭建 SDCC是一个小型设备的C语言编译器,该编 ...

  2. [编译] 7、在Linux下搭建安卓APP的开发烧写环境(makefile版-gradle版)—— 在Linux上用命令行+VIM开发安卓APP

    April 18, 2020 6:54 AM - BEAUTIFULZZZZ 目录 0 前言 1 gradle 安装配置 1.1 卸载系统默认装的gradle 1.2 下载对应版本的二进制文件 1.3 ...

  3. [编译] 8、在Linux下搭建 stm8 单片机的开发烧写环境(makefile版)

    目录 一.SDCC(Small Device C Compiler)编译环境搭建 1.1.下载 1.2.编译 1.3.测试 二.Hex2Bin+命令行烧写工具配置使用 2.1.下载工具安装配置 2.2 ...

  4. [编译] 4、在Linux下搭建nRF51822的开发烧写环境(makefile版)

    星期日, 09. 九月 2018 07:51下午 - beautifulzzzz 1.安装步骤 1) 从GNU Arm Embedded Toolchain官网下载最新的gcc-arm工具链,写文章时 ...

  5. 单片机成长之路(51基础篇) - 006 在Linux下搭建51单片机的开发烧写环境

    在Linux下没有像keli那样好用的IDE来开发51单片机,开发环境只能自己搭建了. 第一步:安装交叉编译工具 a) 安装SDCC sudo apt-get install sdcc b)测试SDC ...

  6. [编译] 5、在Linux下搭建安卓APP的开发烧写环境(makefile版)—— 在Linux上用命令行+VIM开发安卓APP

    星期三, 19. 九月 2018 02:19上午 - BEAUTIFULZZZZ 0)前言 本文不讨论用IDE和文本编辑器开发的优劣,是基于以下两点考虑去尝试用命令行编译安卓APP的: 了解安卓APP ...

  7. 在Linux下搭建nRF51822的开发烧写环境(makefile版)

    http://www.qingpingshan.com/m/view.php?aid=394836

  8. Linux下搭建 Cocos2d-x-2.1.4 编译环境

    [tonyfield 2013.09.04 ] 参考 Linux下搭建 Cocos2d-x-2.1.4 编译环境 导入 HelloCpp 例程 1. Java 入口 HelloCpp.java Hel ...

  9. Linux下搭建tomcat集群全记录(转)

    本文将讲述如何在Linux下搭建tomcat集群,以及搭建过程中可能的遇到的问题和解决方法.为简单起见,本文演示搭建的集群只有两个tomact节点外加一个apache组成,三者将安装在同一机器上:ap ...

随机推荐

  1. Maven中dependencies和dependencyManagement的区别

    Maven项目中,为了保持引用依赖的一致性,一般会抽出一个parent层,用来管理子项目的maven依赖,对于依赖的管理有两种方式,分别是dependencies以及dependencyManagem ...

  2. 剑指offer 37-42

    37. 输入一棵二叉树,判断该二叉树是否是平衡二叉树. 思路: 1.平衡二叉树的定义为,当为空树或左右子树高度小于等于1,同时左右子树都要为平衡二叉树. 2.先分别求出左右子树的高度,比较高度差,如果 ...

  3. STM32笔记二

    1.STM32编程通常有两种方法:一种是寄存器编程,另外一种是固件库编程.寄存器编程是基础,而固件库是寄存器编程的基础上升级而来的编程方法,是需要重点掌握的编程方法. 2.STM32F103采用的是C ...

  4. Hadoop知识总结

    ------------恢复内容开始------------ Hadoop知识点 Hadoop知识点什么是HadoopHadoop和Spark差异Hadoop常见版本,有哪些特点,一般是如何进行选择H ...

  5. C语言:文本文件和二进制文件

    学习了 fopen() 函数后,我们知道它的第二个参数是一个字符串,用来表示文件打开方式.如果字符串中出现b,则表示以二进制方式打开文件:如果字符串中出现t,或者两者都不出现,则表示以文本方式打开文件 ...

  6. Command 'ifconfig' not found, but can be installed with: sudo apt install net-tools VM Ubuntu 解决方案

    VMware下安装的Ubuntu 一开始由于Firefox连不上网,然后通过看了https://www.bbsmax.com/A/VGzlEGYJbq/这个文章之后,自己也测了一下,确实好用 但是if ...

  7. 【动画消消乐】HTML+CSS 自定义加载动画:清新折叠方块效果 063(附源码及原理详解)

    前言 Hello!小伙伴! 非常感谢您阅读海轰的文章,倘若文中有错误的地方,欢迎您指出- 自我介绍ଘ(੭ˊᵕˋ)੭ 昵称:海轰 标签:程序猿|C++选手|学生 简介:因C语言结识编程,随后转入计算机专 ...

  8. 两万字Vue.js基础学习笔记

    Vue.js学习笔记 目录 Vue.js学习笔记 ES6语法 1.不一样的变量声明:const和let 2.模板字符串 3.箭头函数(Arrow Functions) 4. 函数的参数默认值 5.Sp ...

  9. 《手把手教你》系列技巧篇(十)-java+ selenium自动化测试-元素定位大法之By class name(详细教程)

    1.简介 按宏哥计划,本文继续介绍WebDriver关于元素定位大法,这篇介绍By ClassName.看到ID,NAME这些方法的讲解,小伙伴们和童鞋们应该知道,要做好Web自动化测试,最好是需要了 ...

  10. odoo12学习之javascript

    本文来源:https://www.jianshu.com/p/1a47fac01077 Odoo12 Javascript 参考指南   本文介绍了odoo javascript框架.从代码行的角度来 ...