This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Having trouble using openocd with the nrf52 on OSX

Hi all,

I'm running into trouble using openocd to flash code onto the nrf52840 and then step through it. I'm running High Sierra (although I doubt that's important), and using a jlink (from segger) as my debug tool. My config file is very simple, and is shown below.

source [find interface/jlink.cfg]

transport select swd

source [find target/nrf52.cfg]

I know that this works on a Linux machine, but whenever I run it on mine it seems to arbitrarily exit with no error code. The full command is

openocd -f ./openocd.cfg -c "init; \
reset halt; \
sleep 500; \
flash write_image erase build/nrf52840_xxaa.hex; \
reset run; \
shutdown"

(excuse the backslashes - it's from a Makefile). The return that I get is

Open On-Chip Debugger 0.10.0-dev-g90071eb (2017-03-13-12:28)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
adapter speed: 10000 kHz
cortex_m reset_config sysresetreq
Info : No device selected, using first device.
Info : J-Link V10 compiled Apr 20 2018 16:47:09
Info : Hardware version: 10.10
Info : VTarget = 0.000 V
Info : clock speed 10000 kHz
in procedure 'init' 
in procedure 'ocd_bouncer'

I've found the same error elsewhere on this site, but it was related to a memory protection bit that needed to be overwritten, and I don't think that's the case here as I tried running nrfjprog --recover and that had no effect, and also it's working fine on linux. Any help would be appreciated. Thank you!

UPDATE 7/12

So it turns out that I was running into a very simple problem; I was using the jlink whereas it was working on the linux machine over the usb plug into the nrf52 devkit, hence the difference in results. However, when I run openocd on my mac with the usb connected to the devkit, I get the output below, with an "invalid subcommand" error on my flash write_image erase. It seems like my install of openocd is missing a few things maybe? 

openocd -f ./openocd.cfg -c \
	"init; \
	reset halt; \
	sleep 500; \
	flash write_image erase build/nrf52840_xxaa.hex; \
	reset run; \
	shutdown"
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 10000 kHz
cortex_m reset_config sysresetreq
Info : No device selected, using first device.
Info : J-Link OB-SAM3U128-V2-NordicSemi compiled Jan 12 2018 16:05:20
Info : Hardware version: 1.00
Info : VTarget = 3.300 V
Info : Reduced speed from 10000 kHz to 1000 kHz (maximum).
Info : Reduced speed from 10000 kHz to 1000 kHz (maximum).
Info : clock speed 10000 kHz
Info : SWD DPIDR 0x2ba01477
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000002e0 msp: 0x20010000
invalid subcommand "write_image erase build/nrf52840_xxaa.hex"
in procedure 'flash'

  • So I never found a way to make the above work, but I found that calling openocd as a bare command worked just fine, after which I could jump into the connection with a telnet session and use gdb to do the debugging that I want to do.

  • I know this is an old question, but I had the same "invalid subcommand" problem when flashing so I figured I'd write something.

    The short answer is the solution is to use the latest commit on the OpenOCD repo (as of writing this the latest release is v0.10.0 but it doesn't have full support for the nRF52). When you asked the question 2 years ago, ubicore's OpenOCD patch would've probably solved this issue.

    The long answer is that nrf52.cfg is missing the "flash bank" command, which you need to run before running some subcommands like "write_image". If you look at nrf51.cfg, you will find these lines:

    flash bank $_CHIPNAME.flash nrf51 0x00000000 0 1 1 $_TARGETNAME
    flash bank $_CHIPNAME.uicr nrf51 0x10001000 0 1 1 $_TARGETNAME

    Note that one of the parameters is "nrf51" - this is the name of the flash driver. Flash drivers can be found in the repo under src/flash/nor (at least in the latest OpenOCD versions), where you will find C source files that define "flash_driver" structures with a "name" member variable identifying the driver. Unfortunately, in version 0.10.0 and earlier there is no driver for the nRF52 (the "nrf51" driver might work with some limitations, I haven't tested it). The latest commit has the "nrf5" driver which works with the nRF52.

Related