使用 Openocd 烧录 nrf52 芯片时出现问题

问题描述 投票:0回答:4

我的 PCB 上有一个定制的 nrf52 芯片,SWD 引脚暴露在外。我已经从https://github.com/ntfreak/openocd克隆并安装了最新的openocd。最新版本包括 nrf52 芯片的所有最新路径,因此无需按照许多旧在线指南中的建议进行任何其他更改。我可以使用 ST-LinkV2 连接到芯片。连接后,我可以使用 mdw 和 mdb 读取和写入内存位置。我还可以运行一些基本的 openocd 命令,例如 dump_image 等,这证实了设置良好。但停止和编程命令总是会导致错误,例如:

JTAG failure -4
JTAG failure -4
JTAG failure -4
JTAG failure -4
JTAG failure -4
JTAG failure -4
target halted due to debug-request, current mode: Thread 
xPSR: 00000000 pc: 00000000 msp: 00000000
jtag status contains invalid mode value - communication failure
Polling target nrf52.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
Previous state query failed, trying to reconnect
jtag status contains invalid mode value - communication failure
Polling target nrf52.cpu failed, trying to reexamine

如果我尝试使用 flash image_write 我收到错误,

JTAG failure
Error setting register
error starting target flash write algorithm
Failed to enable read-only operation
Failed to write to nrf52 flash
error writing to flash at address 0x00000000 at offset 0x00000000
in procedure 'dap'
jtag status contains invalid mode value - communication failure
Polling target nrf52.cpu failed, trying to reexamine

我已经在线阅读了不同的指南,其中一种可能的解决方案涉及 APPPROTECT 寄存器,必须禁用该寄存器才能启用对闪存的任何写入。 APP_PROTECT,但是dap命令应该帮助我们访问这个位,

dap apreg 1 0x04 0x01

返回错误:

invalid subcommand apreg 1 0x04 0x01

请问,我想知道是否有人成功地使用 stlink-v2 编程了一个新的空 nrf52 芯片以及必要的步骤,或者是否有人遇到了类似的问题。谢谢。

这是我的配置文件:

#nRF52832 Target
source [find interface/stlink.cfg]

transport select hla_swd

source [find target/nrf52.cfg]

#reset_config srst_nogate connect_assert_srst
microcontroller gdbserver openocd nrf51 nrf52
4个回答
4
投票

我正在修改这个答案以涵盖 nRF52 芯片的更高版本。 从构建代码 Gxx 及更高版本开始,每次重置后芯片保护默认开启。

https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/working-with-the-nrf52-series-improved-approtect 需要在程序中添加额外的代码以防止这种情况发生。

但是,如果您只想对芯片进行编程(而不是通过 OpenOCD 进行调试),那么您可以使用以下步骤。 (需要 openocd V0.11.0——二进制文件可从 https://github.com/xpack-dev-tools/openocd-xpack/releases/tag/v0.11.0-1/

bin\openocd -f interface/cmsis-dap.cfg -f target/nrf52.cfg -c "telnet_port pipe;tcl_port disabled;gdb_port disabled;log_output 
reset init
nrf52_recover
flash write_image s132_nrf52_2.0.1_softdevice.hex
flash write_image lp.hex
reset

这将使用 openOCD nrf52.cfg 中提供的 nrf52_recover 方法将当前 cmd 窗口输入传送到 openOCD 并删除芯片保护,并写入软设备,然后写入编译后的程序(在本例中为 lp.hex)。

(Nordic有一个合并实用程序,可以将软设备和程序合并到一个.hex文件中)

对于那些使用 Arduino 的人,我的 极低功耗 BLE <20uA 项目会在 Arduino 草图上传中自动执行此过程。

该项目还包含基于 Raspberry Pi Pico RP2040 的简单 CMSIS-DAP 程序员的说明


2
投票

尽管 openOCD

dap
列出了
help
命令,但它并未实现您必须与 ST-Link 一起使用的传输
hla_swd

如果ST-Link是来自中国的通用类型,可以升级到CMSIS-DAP,它使用

swd
传输并支持
nrf52.dap apreg 1 0x04 0x01
命令来禁用读回保护和擦除闪存。您需要另一个 ST-Link 来完成此操作,或者您也可以在通用 STM32F103C8T6 板上安装 CMSIS-DAP

之后,您可以使用 ST-Link 对 nRF52 进行编程,也可以继续使用 CMSIS-DAP,它也可用于对 STM32 MCU 进行编程。

Nucleo 板嵌入式 ST-Link 也可以升级到 J-Link,允许使用 nRFgo Studio 中的“恢复”选项来擦除闪存,它还应该与“nrfjtool --recover”或 OpenOCD 配合使用。


1
投票

如果有人遇到这个问题,我通过获取原始的 Jlink-Edu 解决了该问题。我还必须将微控制器的复位引脚拉高才能使 jlink 工作。


0
投票

有很多 JTAG 消息。

我想你可能错过了

transport select hla_swd

您(板)cfg 文件中的行。 NRF5x 芯片只能与 SWD 配合使用,ST-Link 使用

hla_swd
变体。

© www.soinside.com 2019 - 2024. All rights reserved.