当前位置: 首页 > news >正文

【nRF52832】【环境搭建 1】【ubuntu下搭建nRF52832开发环境】

在这里插入图片描述

本文讲述如何在 ubuntu 22.04 下开发 nRF52832.

host 环境说明:

$ uname -a
Linux leo 6.8.0-60-generic #63~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 22 19:00:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

1. 安装软件

sudo apt install gcc-arm-none-eabisudo apt-get install build-essential checkinstall

2. nRF5 SDK

1. 下载 SDK

Nordic官方对nRF51、nRF52系列提供了SDK,SDK中提供了大量的BLE和ANT示例。

1. SDK 15.3 版本

下载 15.3版本

将其解压:

leo@leo:~/data_4t/nrf_project/nrf5sdk153059ac345/nRF5_SDK_15.3.0_59ac345$ tree -L 2
.
├── components
│   ├── 802_15_4
│   ├── ant
│   ├── ble
│   ├── boards
│   ├── drivers_ext
│   ├── drivers_nrf
│   ├── iot
│   ├── libraries
│   ├── nfc
│   ├── proprietary_rf
│   ├── sdk_validation.h
│   ├── serialization
│   ├── softdevice
│   └── toolchain
├── config
│   ├── nrf52810
│   ├── nrf52811
│   ├── nrf52832
│   └── nrf52840
├── documentation
│   ├── index.html
│   ├── licenses.html
│   ├── licenses.txt
│   ├── NordicS.jpg
│   ├── nRF5_Garmin_Canada_license.txt
│   ├── nRF5_Nordic_license.txt
│   ├── nRF5x_series_logo.png
│   └── release_notes.txt
├── examples
│   ├── 802_15_4
│   ├── ant
│   ├── ble_central
│   ├── ble_central_and_peripheral
│   ├── ble_peripheral
│   ├── connectivity
│   ├── crypto
│   ├── dfu
│   ├── dtm
│   ├── iot
│   ├── multiprotocol
│   ├── nfc
│   ├── peripheral
│   ├── proprietary_rf
│   ├── readme.txt
│   └── usb_drivers
├── external
│   ├── cifra_AES128-EAX
│   ├── cJSON
│   ├── fatfs
│   ├── fnmatch
│   ├── fprintf
│   ├── freertos
│   ├── infineon
│   ├── licenses_external.txt
│   ├── lwip
│   ├── mbedtls
│   ├── micro-ecc
│   ├── nano
│   ├── nano-pb
│   ├── nfc_adafruit_library
│   ├── nrf_cc310
│   ├── nrf_cc310_bl
│   ├── nrf_oberon
│   ├── nrf_tls
│   ├── protothreads
│   ├── segger_rtt
│   ├── thedotfactory_fonts
│   └── utf_converter
├── external_tools
│   └── cmsisconfig
├── integration
│   └── nrfx
├── license.txt
├── modules
│   └── nrfx
├── nRF5x_MDK_8_24_1_IAR_NordicLicense.msi
└── nRF5x_MDK_8_24_1_Keil4_NordicLicense.msi64 directories, 14 files

2. SDK 17.1.0 版本

现在官网上最新的是 17.1.0 版本:

  • 下载
nRF5_SDK_17.1.0_ddde560$ tree -L 2
.
├── components
│   ├── 802_15_4
│   ├── ant
│   ├── ble
│   ├── boards
│   ├── drivers_ext
│   ├── drivers_nrf
│   ├── libraries
│   ├── nfc
│   ├── proprietary_rf
│   ├── sdk_validation.h
│   ├── serialization
│   ├── softdevice
│   └── toolchain
├── config
│   ├── nrf52810
│   ├── nrf52811
│   ├── nrf52820
│   ├── nrf52832
│   ├── nrf52833
│   └── nrf52840
├── documentation
│   ├── index.html
│   ├── licenses.html
│   ├── licenses.txt
│   ├── NordicS.jpg
│   ├── nRF5_Garmin_Canada_license.txt
│   ├── nRF5_Nordic_license.txt
│   ├── nRF5x_series_logo.png
│   └── release_notes.txt
├── examples
│   ├── 802_15_4
│   ├── ant
│   ├── ble_central
│   ├── ble_central_and_peripheral
│   ├── ble_peripheral
│   ├── connectivity
│   ├── crypto
│   ├── dfu
│   ├── dtm
│   ├── multiprotocol
│   ├── nfc
│   ├── peripheral
│   ├── proprietary_rf
│   ├── readme.txt
│   └── usb_drivers
├── external
│   ├── cifra_AES128-EAX
│   ├── cJSON
│   ├── fatfs
│   ├── fnmatch
│   ├── fprintf
│   ├── freertos
│   ├── infineon
│   ├── licenses_external.txt
│   ├── lwip
│   ├── mbedtls
│   ├── micro-ecc
│   ├── nano
│   ├── nano-pb
│   ├── nfc_adafruit_library
│   ├── nrf_cc310
│   ├── nrf_cc310_bl
│   ├── nrf_oberon
│   ├── nrf_tls
│   ├── protothreads
│   ├── segger_rtt
│   ├── thedotfactory_fonts
│   ├── tile
│   └── utf_converter
├── external_tools
│   └── cmsisconfig
├── integration
│   └── nrfx
├── license.txt
├── modules
│   └── nrfx
└── nRF_MDK_8_40_3_IAR_BSDLicense.msi65 directories, 13 files

2. 配置编译环境

15.3 版本和 17.1.0 版本我都验证了步骤是一样的:

修改如下文件:

  • components/toolchain/gcc/Makefile.posix
// 15.3
GNU_INSTALL_ROOT ?= /usr/bin/
GNU_VERSION ?= 7.3.1
GNU_PREFIX ?= arm-none-eabi
// 17.1.0  components/toolchain/gcc/Makefile.posix
GNU_INSTALL_ROOT ?= /usr/bin/
GNU_VERSION ?= 9.3.1
GNU_PREFIX ?= arm-none-eabi
  • GNU_INSTALL_ROOT : 主要配置交叉工具 按照目录, 编译时可以从当前目录中找 gcc.

查看安装目录:

leo@leo:~$ which arm-none-eabi-gcc
/usr/bin/arm-none-eabi-gcc

3. 编译

这里拿 一个官方跑马灯的例子来验证。

  • pca10040 : 我手里板子,对应官网的 PCA10040 型号
examples/peripheral/blinky/pca10040/blank/armgcc$ tree
.
├── blinky_gcc_nrf52.ld
└── Makefile0 directories, 2 files

在当前目录 make


examples/peripheral/blinky/pca10040/blank/armgcc$ make
mkdir _build
cd _build && mkdir nrf52832_xxaa
Assembling file: gcc_startup_nrf52.S
Compiling file: nrf_log_frontend.c
Compiling file: nrf_log_str_formatter.c
Compiling file: boards.c
Compiling file: app_error.c
Compiling file: app_error_handler_gcc.c
Compiling file: app_error_weak.c
Compiling file: app_util_platform.c
Compiling file: nrf_assert.c
Compiling file: nrf_atomic.c
Compiling file: nrf_balloc.c
Compiling file: nrf_fprintf.c
Compiling file: nrf_fprintf_format.c
Compiling file: nrf_memobj.c
Compiling file: nrf_ringbuf.c
Compiling file: nrf_strerror.c
Compiling file: nrfx_atomic.c
Compiling file: main.c
Compiling file: system_nrf52.c
Linking target: _build/nrf52832_xxaa.outtext	   data	    bss	    dec	    hex	filename2760	    112	    172	   3044	    be4	_build/nrf52832_xxaa.out
Preparing: _build/nrf52832_xxaa.hex
Preparing: _build/nrf52832_xxaa.bin
DONE nrf52832_xxaa# 编译结束leo@leo:~/data_4t/nrf_project/nrf5sdk153059ac345/nRF5_SDK_15.3.0_59ac345/examples/peripheral/blinky/pca10040/blank/armgcc$ tree -L 2
.
├── blinky_gcc_nrf52.ld
├── _build
│   ├── nrf52832_xxaa
│   ├── nrf52832_xxaa.bin
│   ├── nrf52832_xxaa.hex # 他就是我们要烧录进板子的 文件
│   ├── nrf52832_xxaa.in
│   ├── nrf52832_xxaa.map
│   └── nrf52832_xxaa.out
└── Makefile2 directories, 7 files

同样在 17.1.0 下的操作

leo@leo:~/data_4t/nrf_project/nRF5_SDK_17.1.0_ddde560/examples/peripheral/blinky/pca10040/blank/armgcc/_build$ tree -L 1
.
├── nrf52832_xxaa
├── nrf52832_xxaa.bin
├── nrf52832_xxaa.hex
├── nrf52832_xxaa.in
├── nrf52832_xxaa.map
└── nrf52832_xxaa.out1 directory, 5 files

3. 烧录

1. 软件安装

下载 nRF-Command-Line-Tools_10_9_0_Linux-amd64
https://www.nordicsemi.com/Products/Development-tools/nrf-command-line-tools/download#infotabs

在这里插入图片描述

解压:


nrfcommandlinetools1090linuxamd64$ tree
.
├── JLink_Linux_V680a_x86_64.deb
├── JLink_Linux_V680a_x86_64.tgz
├── nRF-Command-Line-Tools_10_9_0_Linux-amd64.deb
├── nRF-Command-Line-Tools_10_9_0.tar
└── README.txt0 directories, 5 files

安装:


# 第一步
sudo dpkg -i JLink_Linux_V680a_x86_64.deb# 第二步
sudo dpkg -i nRF-Command-Line-Tools_10_9_0_Linux-amd64.deb
  • 注意安装先后顺序

查看安装后的版本:

$ nrfjprog -v
nrfjprog version: 10.9.0 
JLinkARM.dll version: 6.80a$ JLinkExe -v
SEGGER J-Link Commander V6.80a (Compiled May 29 2020 16:30:49)
DLL version V6.80a, compiled May 29 2020 16:30:38
  • 如果能看到上面的信息,表示下载环境已经ok 了。

2. 连接板子

1. 硬件接线:

我这里使用 Jlink-v9 仿真器 SWD 接口和板子进行连接:

在这里插入图片描述


2. 软件侧

执行如下命令 :

JLinkExe -device NRF52 -if SWD -speed 4000 -autoconnect 1

如果有如下输出信息:表示已经识别到板子了。

SEGGER J-Link Commander V6.80a (Compiled May 29 2020 16:30:49)
DLL version V6.80a, compiled May 29 2020 16:30:38Connecting to J-Link via USB...O.K.
Firmware: J-Link V9 compiled May  7 2021 16:26:12
Hardware version: V9.70
S/N: 69706099
License(s): RDI, FlashBP, FlashDL, JFlash, GDB
VTref=3.261V
Device "NRF52" selected.Connecting to target via SWD
InitTarget() start
InitTarget() end
Found SW-DP with ID 0x2BA01477
DPIDR: 0x2BA01477
Scanning AP map to find all available APs
AP[2]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
AP[1]: JTAG-AP (IDR: 0x02880000)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
Cortex-M4 identified.
J-Link>

3. 烧录

1. 方式1: 使用 Jlink 进行烧录

// 1. 首先输入上面的命令 连接板子:
JLinkExe -device NRF52 -if SWD -speed 4000 -autoconnect 1// 2. 擦除之前的程序
J-Link> erase
Erasing device...
Comparing flash   [100%] Done.
Erasing flash     [100%] Done.
J-Link: Flash download: Total time needed: 0.026s (Prepare: 0.015s, Compare: 0.000s, Erase: 0.007s, Program: 0.000s, Verify: 0.000s, Restore: 0.003s)
Erasing done.// 3. 烧录之前 编译的 跑马灯 程序
J-Link> loadfile nrf52832_xxaa.hex 
Downloading file [nrf52832_xxaa.hex]...
Comparing flash   [100%] Done.
Erasing flash     [100%] Done.
Programming flash [100%] Done.
J-Link: Flash download: Bank 0 @ 0x00000000: 1 range affected (4096 bytes)
J-Link: Flash download: Total: 0.092s (Prepare: 0.026s, Compare: 0.002s, Erase: 0.000s, Program & Verify: 0.052s, Restore: 0.011s)
J-Link: Flash download: Program & Verify speed: 76 KB/s
O.K.// 4. 退出, 此时 程序就开始执行了。
J-Link>exit

2. 方式2: nrfjprog 烧录

全片擦除 +下载+ 复位运行。

$ nrfjprog -f NRF52 --program ./IK-52832DK-V2-TEST.hex  --chiperase -rParsing hex file.
Erasing user available code and UICR flash areas.
Applying system reset.
Checking that the area to write is not protected.
Programming device.
Applying system reset.
Run.

4. nrfjprog 命令介绍

nrfjprog 是使用 J-Link 仿真器对 nRF5x 系列 SoC 进行编程的命令行工具。

1. 全片擦除

执行全片擦除后,会擦除片内所有 Flash 和掉电保持的寄存器。

// 擦除
$ nrfjprog -f NRF52 -eErasing user available code and UICR flash areas.
Applying system reset.

2. 下载

nrfjprog 的命令是可以组合的,对于程序下载,可以使用下面两种组合命令,注意他们
的区别。

1. 仅下载+复位运行:芯片必须是空的(擦除过的),否则下载会失败

$ nrfjprog -f NRF52 --program ./IK-52832DK-V2-TEST.hex Parsing hex file.
Reading flash area to program to guarantee it is erased.
Checking that the area to write is not protected.
Programming device.
  • 此时重新掉电启动即可

2.全片擦除 +下载+ 复位运行

$ nrfjprog -f NRF52 --program ./IK-52832DK-V2-TEST.hex  --chiperase -rParsing hex file.
Erasing user available code and UICR flash areas.
Applying system reset.
Checking that the area to write is not protected.
Programming device.
Applying system reset.
Run.
  • 我一般情况会使用这种方式烧录。

3.启用回读保护机制

nrfjprog -f NRF52 --rbp ALL

该命令执行后,无法使用仿真器通过 DEBUG 接口读出芯片的数据,当我们发布产品的
时候,可以通过启用回读保护防止别人读取芯片中烧写的固件,从而保护产品的权益不被侵犯。

3. 读出 SoftDevice 的 FWID

只有已经下载了 SoftDevice 的芯片才可以读出 FWID。

  • nRF51xx 系列命令:nrfjprog --family NRF51 --memrd 0x0000300C
  • nRF52xx 系列命令:nrfjprog --family NRF52 --memrd 0x0000300C
$ nrfjprog --family NRF52 --memrd 0x0000300C
0x0000300C: FFFF00AF    
  • 所示,读出的数据是:0xFFFF00AF,表示协议栈的 FWID 是 0xAF,根据 FWID 即可知道
    协议栈的版本(FWID 在固件更新 DFU 中会用到)

4. 恢复

恢复:全片擦除并禁用回读保护机制(如果启用)
命令:nrfjprog -f NRF52 -recover
该命令执行后,会擦除片内所有 Flash 和掉电保持的寄存器。

5. ps

本文档 所涉及的软件包我已经打包,请点击下载。

  • nRF52832-ubuntu-开关环境资源打包
nrf-52832-env-soft$ tree
.
├── IK-52832DK-V2-TEST.hex
├── nrf52832_xxaa.hex
├── nrf5sdk153059ac345.zip
└── nrfcommandlinetools1090linuxamd64.tar.gz
$ md5sum nrf-52832-env-soft.7z
b61a6911bab6684f9721648740448926  nrf-52832-env-soft.7z
http://www.lryc.cn/news/575293.html

相关文章:

  • 一篇文章了解XML
  • 20250625解决在Ubuntu20.04.6LTS下编译RK3588的Android14出现cfg80211.ko的overriding问题
  • 【DataWhale组队学习】AI办公实践与应用-数据分析
  • 《仿盒马》app开发技术分享-- 待发货兑换订单列表(76)
  • 使用EasyExcel处理动态表头数据导入
  • Aurora MySQL 3.05/3.06/3.07版本即将停用,全局数据库升级实战指南
  • 鸿蒙ArkUI---基础组件Tabs(Tabbar)
  • 日本生活:日语语言学校-日语作文-沟通无国界(5)-题目:我的一天
  • Boss:攻击
  • ChaCha20加密解密技术
  • 使用 Netty 实现 TCP 私有协议(解决粘包/拆包)
  • 三步实现B站缓存视频转MP4格式
  • WeakAuras Lua Script [ICC BOSS 12 - The Lich King]
  • 【笔记——李沐动手学深度学习】2.3 线性代数
  • PyTorch RNN实战:快速上手教程
  • MySQL之存储过程详解
  • IoT/HCIP实验-5/基于NB-IoT的智慧农业实验(平台侧开发+端侧编码+基础调试分析)
  • 重置 MySQL root 密码
  • python接口测试参数multipart/form-data格式不能有多余的空格或 tab 缩进
  • 计算机网络-----详解HTTPS协议
  • 可商用,可离线运行,可API接口调用的开源AI数字人项目Heygem,喂饭级安装教程
  • 专题:2025医疗AI应用研究报告|附200+份报告PDF汇总下载
  • Android14音频子系统 - 系统框架概述
  • 用户体验驱动的3D设计:从功能实现到情感共鸣的设计升级
  • Wpf的Binding
  • Deepoc大模型:精密制造智能化的“数字孪生引擎”
  • RabbitMq中使用自定义的线程池
  • 多个 Job 并发运行时共享配置文件导致上下文污染,固化 Jenkins Job 上下文
  • 联邦学习差分隐私系统的参与角色、密钥分发及攻击分析
  • 爽提配送:以专业守护校园,用匠心重塑安全