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

How to set nrf51 Read Back Protection using OpenOCD?

Looking for the OpenOCD equivalent of ""nrfjprog --rbp all"

Looking at the commands for OpenOCD they have a "flash protect" command, but it doesn't appear that's quite the same thing (requests regions of flash).

Any assistance for a OpenOCD newbie would be appreciated!

  • Still not able to get us to a state of read back protected files.

    Using OpenOCD, one cannot write your hex file after SoftDevice and Program are written.

    Here is the command and output:

    D:\OpenOCD\bin>openocd.exe -f ../scripts/interface/stlink-v2.cfg -f "C:\Program Files\GNU ARM Eclipse\OpenOCD\0.10.0-201701241841\scripts\target\nrf51.cfg" -s ..\share\openocd\scripts -c "init" -c "halt" -c "nrf51 mass_erase 0" -c "program sd.hex verify" -c "program myprogram.hex verify" -c "program nrf51822_UICR_lock.hex verify" -c "reset" -c "exit"

    Open On-Chip Debugger 0.9.0 (2016-09-01) [https://github.com/sysprogs/openocd]

    Licensed under GNU GPL v2

    For bug reports, read

    openocd.org/.../bugs.html

    Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '.

    Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD

    adapter speed: 1000 kHz

    Info : Unable to match requested speed 1000 kHz, using 950 kHz

    Info : Unable to match requested speed 1000 kHz, using 950 kHz

    Info : clock speed 950 kHz

    Info : STLINK v2 JTAG v23 API v2 SWIM v4 VID 0x0483 PID 0x3748

    Info : using stlink api v2

    Info : Target voltage: 3.172668

    Info : nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints

    Info : nRF51822-QFAA(build code: E0) 256kB Flash

    nrf51.cpu: target state: halted

    target halted due to debug-request, current mode: Thread xPSR: 0xc1000000 pc: 0xfffffffe msp: 0xfffffffc

    ** Programming Started **

    auto erase enabled

    Info : Padding image section 0 with 2112 bytes

    Warn : using fast async flash loader. This is currently supported

    Warn : only with ST-Link and CMSIS-DAP. If you have issues, add

    Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg to disable it

    nrf51.cpu: target state: halted

    target halted due to breakpoint, current mode: Thread

    xPSR: 0x61000000 pc: 0x2000001e msp: 0xfffffffc

    wrote 93184 bytes from file sd.hex in 4.006389s (22.714 KiB/s)

    ** Programming Finished **

    ** Verify Started **

    nrf51.cpu: target state: halted

    target halted due to breakpoint, current mode: Thread

    xPSR: 0x61000000 pc: 0x2000002e msp: 0xfffffffc

    nrf51.cpu: target state: halted

    target halted due to breakpoint, current mode: Thread

    xPSR: 0x61000000 pc: 0x2000002e msp: 0xfffffffc

    verified 90328 bytes in 0.636024s (138.691 KiB/s)

    ** Verified OK **

    nrf51.cpu: target state: halted

    target halted due to debug-request, current mode: Thread

    xPSR: 0xc1000000 pc: 0x000006d0 msp: 0x000007c0

    ** Programming Started **

    auto erase enabled

    Warn : using fast async flash loader. This is currently supported

    Warn : only with ST-Link and CMSIS-DAP. If you have issues, add

    Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg to disable it

    nrf51.cpu: target state: halted

    target halted due to breakpoint, current mode: Thread

    xPSR: 0x61000000 pc: 0x2000001e msp: 0x000007c0

    Warn : Adding extra erase range, 00000000 to 0x00000013

    Warn : using fast async flash loader. This is currently supported

    Warn : only with ST-Link and CMSIS-DAP. If you have issues, add

    Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg to disable it

    nrf51.cpu: target state: halted

    target halted due to breakpoint, current mode: Thread

    xPSR: 0x61000000 pc: 0x2000001e msp: 0x000007c0

    wrote 14572 bytes from file myprogram.hex in 0.822974s (17.292 KiB/s)

    ** Programming Finished **

    ** Verify Started **

    nrf51.cpu: target state: halted

    target halted due to breakpoint, current mode: Thread

    xPSR: 0x61000000 pc: 0x2000002e msp: 0x000007c0

    verified 14252 bytes in 0.143640s (96.895 KiB/s)

    ** Verified OK **

    nrf51.cpu: target state: halted

    target halted due to debug-request, current mode: Thread

    xPSR: 0xc1000000 pc: 0x000006d0 msp: 0x000007c0

    ** Programming Started **

    auto erase enabled

    Error: The chip was not pre-programmed with SoftDevice stack and UICR cannot be erased separately. Please issue mass erase before trying to write to this region

    Error: failed erasing sectors 0 to 0

    embedded:startup.tcl:454: Error: ** Programming Failed **

    in procedure 'program'

    in procedure 'program_error' called at file "embedded:startup.tcl", line 510

    at file "embedded:startup.tcl", line 454

  • Hello Jerod,

    Indeed you cannot program that HEX file separately, programmer will complain that chip isn't erased. You need to do the same as with SoftDevice and Application: concatenate the thing into one blob and program it at once. I'm using PyOCD on Windows, will try to get some example tomorrow... but honestly, this is rather question to OpenOCD community (= how to flash three binaries at once or how to write particular flash byte/word after chip is programmed). You can also seak help at @hnhoan 's blog, he seems to be using ST-Link and OpenOCD on nRF5x chips routinely.

    Cheers Jan

  • You can use the IDAP-Link. It will do all that for without needing to do any concatenation of hex and multiboards in parallel

Related