cpu/nRF52: Always recover Device before Flashing#20970
Merged
mguetschow merged 2 commits intoRIOT-OS:masterfrom Nov 11, 2024
Merged
cpu/nRF52: Always recover Device before Flashing#20970mguetschow merged 2 commits intoRIOT-OS:masterfrom
mguetschow merged 2 commits intoRIOT-OS:masterfrom
Conversation
mguetschow
requested changes
Nov 8, 2024
Contributor
mguetschow
left a comment
There was a problem hiding this comment.
Thanks, looks good! Just a minor comment below.
mguetschow
approved these changes
Nov 8, 2024
Contributor
mguetschow
left a comment
There was a problem hiding this comment.
Confirmed to work locally with a nRF52840dk, revision PCA10056. Thanks a bunch!
Contributor
Author
|
I'm not sure how this PR broke the 'tests/sys/xtimer_usleep_short' test on native64? 🤔😅 |
Contributor
|
Probably an unrelated spurious failure, let's retry :) |
Contributor
Author
Awesome, thank you :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_recovercommand for it which has to be called after theinitcommand and before any other command.This necessitated the introduction of another OpenOCD variable, which is between the
initand the followingtargetcommand in the flash procedure, calledOPENOCD_POST_INIT_CMDS.This variable is defined in the shared
boards/common/nrf52/Makefile.includeand 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_recovercommand 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).