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

前言

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上是个绿色版本,直接启动即可:

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

然后根据 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
</sourcecode_root>

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、编译运行

&#x279C;  ncs cd nrf/samples/bluetooth/peripheral_bms/
&#x279C;  peripheral_bms git:(master) source ../../../../zephyr/zephyr-env.sh
&#x279C;  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 init -m https://github.com/nrfconnect/sdk-nrf
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 的开发烧写环境

Original: https://www.cnblogs.com/zjutlitao/p/15160967.html
Author: beautifulzzzz
Title: [编译] 9、在Linux下搭建 nordic 最新基于 zephyr 的开发烧写环境

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/585663/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 【FTK Imager篇】FTK Imager磁盘镜像的哈希报告翻译

    FTK Imager制作完镜像后,会生成镜像文件和哈希报告,来验证镜像文件的哈希值和驱动器哈希值在创建镜像后是否匹配,以用作基准来证明案例证据的完整性。—【suy】 磁…

    Linux 2023年6月13日
    082
  • 原码反码补码

    3.1 知识点补充 在计算机内部,所有信息都是用二进制数串的形式表示的。整数通常都有正负之分,计算机中的整数分为无符号的和带符号的。无符号的整数用来表示0和正整数,即自然数;带符号…

    Linux 2023年6月13日
    0105
  • bash shell相关知识

    shell与bash 什么是shell ——以上图片摘自《鸟哥的Linux私房菜》 系统核心不能随意地被操作,所以就设计出了壳程序shell,一方面保护了系统核心,另一方面提供了人…

    Linux 2023年6月7日
    0112
  • AndroidManifest.xml文件校验工具

    一、前言 前段时间总能碰见AndroidManifest固定字节被篡改的情况,每次都要拿着图一个个去对比那个固定字节处被篡改了,干脆直接写了个校验工具,这里分享给大家,工具没什么技…

    Linux 2023年6月8日
    0104
  • 部署无人值守安装系统

    主机名 操作系统 ip地址 无人值守系统 CentOS Linux release 7.9.2009 (Core) 192.168.71.128 客户端 未安装系统 –…

    Linux 2023年6月13日
    0125
  • MySQL slow log 慢日志

    sql慢日志用于记录执行时间超过指定阈值的SQL,对于系统性能和故障排错非常有帮助 1.如何开启sql慢日志 –&#x5F00;&#x542F;slow log …

    Linux 2023年6月6日
    076
  • macos 文件系统 git仓库 大小写敏感设置; git config core.ignorecase

    macos 的文件系统不区分文件名的大小写,这样会导致在一个文件夹,当修改一个文件名为大写的时候,git不能感知到。这样使用过程中会出现很多不必要的麻烦。之前设置过,最近使用,发现…

    Linux 2023年6月14日
    0113
  • Redis集群搭建的三种方式

    一、单节点实例 单节点实例还是比较简单的,平时做个测试,写个小程序如果需要用到缓存的话,启动一个 Redis 还是很轻松的,做为一个 key/value 数据库也是可以胜任的 二、…

    Linux 2023年5月28日
    064
  • 内存错误和服务器内存RAS功能-DELL篇-1

    简介 内存子系统错误是现代计算系统中最常见的一些错误类型。了解内存错误是如何发生的以及如何预防或避免它们可能是一个复杂的话题–在过去30年里,这个话题挑战了无数的行业研…

    Linux 2023年6月7日
    0131
  • zabbix4.0 本地安装详解及步骤

    安装前说明下,下面安装过程中涉及selinux部分仅供参考,可能会导致启动服务时产生各种报错,作者也是在折腾了无数日夜后报错不断而放弃治疗,直接永久关闭了selinux(啊,没有s…

    Linux 2023年6月8日
    099
  • RPA纳税申报机器人

    bash;gutter:true;1、机器人开始工作2、机器人打开企业内部税务平台,自动下载报税底表3、机器人自动登录地方税务局,填写报税数据手工报税10分钟/3个表 VS 机器人…

    Linux 2023年6月7日
    078
  • 挂载mount

    挂载mount 1.查看系统挂载的磁盘情况 df df -h 2.挂载:mount 将光驱挂在到/mnt目录: mount /dev/cdrom /mnt #mount 准备挂载的…

    Linux 2023年6月11日
    092
  • POJ1861(Network)-Kruskal

    题目在这 Sample Input 4 6 1 2 1 1 3 1 1 4 2 2 3 1 3 4 1 2 4 1 Sample Output 1 4 1 2 1 3 2 3 3 …

    Linux 2023年6月7日
    081
  • 进程相关指令

    pgrep 查找进程名 KILL 删除 执行中的进程和工作 free 打印系统情况和内存情况 free [-bkmgotsh] free -h total used free sh…

    Linux 2023年6月7日
    0107
  • vscode shellArgs.windows参数如何设置使得powershell终端字符集编码为UTF-8?

    网上的大部分是这个答案: “terminal.integrated.shellArgs.windows”: [“-NoExit”, “/c”, “chcp 65001”] 如果你觉…

    Linux 2023年6月13日
    096
  • [apue] linux 文件访问权限那些事儿

    说到 linux 上的文件权限,其实我们在说两个实体,一是文件,二是进程。一个进程能不能访问一个文件,其实由三部分内容决定: 下面先简单说明一下这些基本概念,最后再说明它们是如何相…

    Linux 2023年6月6日
    097
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球