使用Openocd闪存nrf52芯片时出现问题



我在pcb上有一个定制的nrf52芯片,露出了swd引脚。我已经从中克隆并安装了最新的openocdhttps://github.com/ntfreak/openocd.最新版本包括了nrf52芯片的所有最新路径,因此不需要像许多旧的在线指南中建议的那样进行任何额外的更改。我可以使用ST-LinkV2连接到芯片。当连接时,我可以使用mdw和mdb读取和写入内存位置。我还可以运行一些基本的openocd命令,比如dump-image e.t.c,这可以确认设置是好的。但是暂停和程序命令总是会导致错误,比如:

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

我在Windows上使用Particle.io调试器以这种方式解决了"受保护的nRF52"芯片问题https://store.particle.io/products/particle-debugger设置为从Arduino编程nRF52芯片,如中所述https://www.forward.com.au/pfod/BLE/LowPower/index.html

注意:这里描述的恢复过程不需要安装Arduino

从下载OpenOCD-20181130.7z预编译的OpenOCD for windowshttp://gnutoolchains.com/arm-eabi/openocd/

上的最新版本的openocd-srchttps://github.com/ntfreak/openocd也应该工作,因为它包括target\arm_adi_v5.c 中的apreg cmd

解压缩,打开cmd提示符解压缩目录,输入cmd

binopenocd.exe -d2 -f interface/cmsis-dap.cfg -f target/nrf52.cfg 

响应

Info : auto-selecting first available session transport "swd". To override use '
transport select <transport>'.
adapter speed: 1000 kHz
cortex_m reset_config sysresetreq
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 1.10
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Error: Could not find MEM-AP to control the core
Info : Listening on port 3333 for gdb connections

打开telnet程序,例如teraTerm,并在端口4444上连接到localhost,即127.0.0.1 telnet端口4444

cmd窗口显示

Info : accepting 'telnet' connection on tcp/4444

在telnet(即teraTerm)类型中

nrf52.dap apreg 1 0x04

返回0<lt<芯片保护然后

nrf52.dap apreg 1 0x04 0x01

然后

nrf52.dap apreg 1 0x04

返回1<lt;芯片未受保护

然后电源循环板

现在可以使用arduino ide来闪存软设备并编码低功耗BLE

即使dap命令由openOCDhelp列出,但它并没有为必须与ST Link一起使用的传输hla_swd实现。

如果ST链路是来自中国的通用类型,则可以升级为CMSIS-DAP,它使用swd传输并支持nrf52.dap apreg 1 0x04 0x01命令来禁用读回保护并擦除闪存。您将需要另一个ST Link来完成此操作,或者您可以在通用STM32F103C8T6板上安装CMSIS-DAP。

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

Nucleo板嵌入式ST链接也可以升级到J-Link,这允许使用nRFgo Studio中的"恢复"选项来擦除闪存,它也应该与"nrfjtool--recover"或OpenOCD一起工作。

如果有人遇到这个问题,我会通过获得一个原始的Jlink Edu来解决这个问题。我还必须把微控制器的复位引脚拉高,才能让jlink工作。

有很多JTAG消息。

我想你可能错过了

transport select hla_swd

(板)cfg文件中的行。NRF5x芯片只能与SWD一起正常工作,ST-Link使用hla_swd变体。

最新更新