-
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: Always recover Device before Flashing #20970
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good! Just a minor comment below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed to work locally with a nRF52840dk, revision PCA10056. Thanks a bunch!
I'm not sure how this PR broke the 'tests/sys/xtimer_usleep_short' test on native64? 🤔😅 |
Probably an unrelated spurious failure, let's retry :) |
Awesome, thank you :) |
Contribution description
With nRF52 silicon revision Fxx and newer, the behavior of the APPROTECT flash protection was changed. Previously it had to be activated manually and as long as it was not activated, the flash could be read from and written to without issues.
After the revision, the device is in a protected state after the first power cycle, making it impossible to read/write/modify the flash memory with an external debugger.
Furthermore, the device has to be unlocked (or in Nordic terms "recovered") explicitly. Unlike the term "recover" might suggest, the flash is erased during that "recovery".
The Segger J-Link does that recovery process implicitly, while OpenOCD has a dedicated
nrf52_recover
command for it which has to be called after theinit
command and before any other command.This necessitated the introduction of another OpenOCD variable, which is between the
init
and the followingtarget
command in the flash procedure, calledOPENOCD_POST_INIT_CMDS
.This variable is defined in the shared
boards/common/nrf52/Makefile.include
and is therefore set for all nRF52 devices. When not using OpenOCD, it does not have any effect and there should not be any adverse effects on other programmers.A side effect is that earlier silicon revisions might get their flash memory erased by the
nrf52_recover
command even though it is not necessary for them, but adding a distinction for the old chips is beyond the scope of the RIOT flashing scripts I think.Testing procedure
Programming any nRF52 board using an external programmer (J-Link or ST-LINK) in conjunction with OpenOCD with the newer silicon revisions should throw an OpenOCD error about the missing recovery command with the current master.
With this PR, it should just work. I tested it with a J-Link EDU (an unrelated issue prevents using the builtin J-Link with the latest firmware) and a Nordic Semiconductor nRF52840 DK (PCA10056 Revision 3.0.1 from 2023.6).
Issues/PRs references
This solves #20968 (at least the issues we can fix from RIOTs side).