-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu/nrf52: OpenOCD not working with newer Revision Silicon and nRF52840 J-Link #20968
Comments
Thanks so much for digging into this! I have the following setup:
After flashing once with J-Link (where the Debug Port Protection gets presumably disabled), flashing with openOCD works just fine:
I'm not sure how openOCD selects the J-Link version it uses, so that could be the difference here. After reconnecting the board and without an initial flash via J-Link, flashing with openOCD is indeed impossible due to access port protection:
They all sound sensible to me. Maybe we could have the POST_INIT fix even before the libjaylink changes so that flashing at least works in your case 2. |
Thank you for your quick feedback. Other than that the behavior is expected. As long as the device is not reset/power cycled, it stays unlocked. Therefore you can program it with OpenOCD after programming it with J-Link. I will probably incorporate the POST_INIT_CMD into the reset PR. In the meantime I found out how to set the UICR register with OpenOCD, so the reset fix can be applied to OpenOCD as well. |
Great! |
The author of libjaylink, Marc Schinkel, added the Product ID to the lib and will create a new revision soon. OpenOCD will not use libjaylink as a submodule in the next release but will use libjaylink as a shared library installed from the package sources. The first two tasks are therefore completed, I'll just have to add a remark to the documentation to use the correct OpenOCD and libjaylink releases for the nRF52840DK. |
I added the remark to the #20592 issue, so this one can be closed. Thank you @mguetschow for working with me on this :) |
Description
In the PR #20965 @mguetschow raised the question whether the fix could be implemented for OpenOCD as well and I discovered that using OpenOCD with RIOT on the nRF52 platform seems to have two issues:
To get some more debug information, you can add change line 340 of
dist/tools/openocd/openocd.sh
:This yields the following:
The latest libjaylink recognizes the following Product IDs (https://gitlab.zapb.de/libjaylink/libjaylink/-/blob/master/libjaylink/discovery_usb.c?ref_type=heads#L50-L71 https://gitlab.zapb.de/libjaylink/libjaylink/-/blob/master/contrib/60-libjaylink.rules?ref_type=heads#L23-L45), and Segger J-Link firmware from "2024 Oct 9 11:01" uses 1060:
I will write Mark Schink, who is the (only?) developer of libjaylink an E-Mail and ask him to add the nRF52840DK product ID to the library. HOWEVER only when OpenOCD adopts the new libjaylink and pushes a new release this issue will be fixed.
So we'll probably have to add a remark to the documentation that the nRF52840 DK is not supported by OpenOCD for the time being.
Using a different programmer than the builtin J-Link (such as an J-Link EDU, which is supported by libjaylink v0.2.0) does work, but it brings us to the next issue:
On newer revisions, the chip is always protected after a reset or power cycle after programming and can not be read out or written to. The only way to write to the chip is to unprotect it, which the current OpenOCD script does not do.
OpenOCD provides a command for it, called
nrf52_recover
... HOWEVER it has to be called after the initialization and before any other commands trying to access it. Looking at the script indist/tools/openocd/openocd.sh
L339ff, we would have to define a new variable:# flash device sh -c "${OPENOCD} \ ${OPENOCD_ADAPTER_INIT} \ -f '${OPENOCD_CONFIG}' \ ${OPENOCD_EXTRA_INIT} \ ${OPENOCD_EXTRA_RESET_INIT} \ -c 'tcl_port 0' \ -c 'telnet_port 0' \ -c 'gdb_port 0' \ -c 'init' \ + ${OPENOCD_POST_INIT_CMDS} \ -c 'targets' \ ${OPENOCD_CMD_RESET_HALT} \ ${OPENOCD_PRE_FLASH_CMDS} \ -c 'flash write_image erase \"${IMAGE_FILE}\" ${IMAGE_OFFSET} ${IMAGE_TYPE}' \ ${OPENOCD_PRE_VERIFY_CMDS} \ ${OPENOCD_VERIFY} \ -c 'reset run' \ -c 'shutdown'" &&
And the
boards/common/nrf52/Makefile.include
would get the following entry:OPENOCD_EXTRA_INIT
andOPENOCD_EXTRA_RESET_INIT
are not exported inmakefiles/tools/openocd.inc.mk
and therefore ignored when you try to use them in a Makefile.Apparently at the moment nobody does that, so nobody noticed it.
Versions
OpenOCD v0.1.1
libjaylink v0.2.0
Tasks
Add an information in the documentation why the nRF52840 DK is not currently supported by OpenOCD.Currently I can't really tell how high of a priority this is for me and apparently nobody else uses OpenOCD to program nRF52 chips (because if someone did, it would've surfaced this issue 😅 )
I'd like to hear some feedback about the proposed fixes.
The text was updated successfully, but these errors were encountered: