Skip to content
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

boards/nRF52xx: correctly set JLINK_DEVICE #20599

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

crasbe
Copy link
Contributor

@crasbe crasbe commented Apr 19, 2024

Contribution description

Since a version update of JLinkExe about four years ago, it performs a check of the Flash memory range, which depends on the JLINK_DEVICE selected. Currently, the JLINK_DEVICE variable is set in the boards/common/nrf52/Makefile.include file, which sets it to "NRF52". This seems to default to the nRF52832 chip, which is incorrect for all boards not using this chip.
The issue is described in #14576 and it seems to trigger (mostly? only?) when flashing images that are close to the maximum flash size of the nRF52832 or when specifying explicit memory addresses. Therefore the bug has been mostly unnoticed in normal operation and is triggered when trying to flash a bootloader to the nRF52840 chip.

This PR removes the JLINK_DEVICE variable from the common Makefile.include, because the boards including this file have various Nordic nRF52 processors. The declaration of the JLINK_DEVICE variable is therefore moved to the various Makefile.include files of the relevant targets which actually use the JLink programmer (or do not have a built in programmer in which case RIOT assumes a JLink will be used).

Testing procedure

Run the following command with an arbitrary nRF52 development board connected and observe the console output:

BOARD=nrf52dk make -C tests/riotboot/ riotboot/flash-slot1

You should be able to see the right processor being selected for the BOARD specified in the command. The relevant line is 'Device "NRF52832_XXAA" selected.'
You can skip the programming process when JLinkExe asks you to unsecure the device (we don't actually want to program incorrect code into the microcontroller 👀 )

chris@ThinkPias:~/flashdev-riot/RIOT$ BOARD=nrf52dk make -C tests/riotboot/ riotboot/flash-slot1
make: Verzeichnis „/home/chris/flashdev-riot/RIOT/tests/riotboot“ wird betreten
compiling /home/chris/flashdev-riot/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
make -C ...
creating /home/chris/flashdev-riot/RIOT/tests/riotboot/bin/nrf52dk/riotboot_files/slot1.1713533231.bin...
/home/chris/flashdev-riot/RIOT/dist/tools/jlink/jlink.sh flash /home/chris/flashdev-riot/RIOT/tests/riotboot/bin/nrf52dk/riotboot_files/slot1.1713533231.bin
### Flashing Target ###
### Flashing bin file at base address 0x0 with offset 0x41000 ###
SEGGER J-Link Commander V7.96e (Compiled Apr 17 2024 16:28:22)
DLL version V7.96e, compiled Apr 17 2024 16:27:56

J-Link Commander will now exit on Error

J-Link Command File read successfully.
Processing script file...
J-Link>loadbin /home/chris/flashdev-riot/RIOT/tests/riotboot/bin/nrf52dk/riotboot_files/slot1.1713533231.bin 0x00041000
J-Link connection not established yet but required for command.
Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-nRF5340-NordicSemi compiled Apr 11 2024 17:44:26
Hardware version: V1.00
J-Link uptime (since boot): 0d 00h 00m 05s
S/N: 1050208458
License(s): RDI, FlashBP, FlashDL, JFlash, GDB
USB speed mode: Full speed (12 MBit/s)
VTref=3.300V
Target connection not established yet but required for command.
Device "NRF52832_XXAA" selected.


Connecting to target via SWD
InitTarget() start
Skipping unsecure.
InitTarget() end - Took 7.61s
Connect failed. Resetting via Reset pin and trying again.
InitTarget() start
Skipping unsecure.
InitTarget() end - Took 1.17s
Error occurred: Could not connect to the target device.
For troubleshooting steps visit: https://wiki.segger.com/J-Link_Troubleshooting

Script processing completed.

make: *** [/home/chris/flashdev-riot/RIOT/makefiles/boot/riotboot.mk:148: riotboot/flash-slot1] Fehler 1
make: Verzeichnis „/home/chris/flashdev-riot/RIOT/tests/riotboot“ wird verlassen

Repeat for the following targets:

  • nrf52dk
  • nrf52840dk
  • ruuvitag
  • waveshare-nrf52840-eval-kit
  • acd52832 (although it is obsolete now)
  • dwm1001
  • e104-bt50xxa-tb
    • e104-bt5010a-tb with nRF52810 (now obsolete)
    • e104-bt5011a-tb with nRF52811 (now obsolete)

Issues/PRs references

This PR fixes #14576.

@crasbe crasbe requested a review from aabadie as a code owner April 19, 2024 13:41
@github-actions github-actions bot added the Area: boards Area: Board ports label Apr 19, 2024
Copy link
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for spotting and fixing this!

I've tested it successfully with a nrf52840dk and had a look at the changeset, but haven't double-checked the list of nrf52-based boards with jlink debugger.

Therefore just a soft-ACK from my side.

@github-actions github-actions bot added Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: cpu Area: CPU/MCU ports labels Apr 19, 2024
cpu/nrf52/Makefile.include Outdated Show resolved Hide resolved
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 22, 2024
@maribu maribu enabled auto-merge April 22, 2024 09:34
@riot-ci
Copy link

riot-ci commented Apr 22, 2024

Murdock results

✔️ PASSED

6f0e81f boards/nRF52xx: correctly set JLINK_DEVICE

Success Failures Total Runtime
10065 0 10066 14m:27s

Artifacts

@maribu maribu added this pull request to the merge queue Apr 22, 2024
Merged via the queue into RIOT-OS:master with commit a8ffb34 Apr 22, 2024
27 checks passed
@crasbe
Copy link
Contributor Author

crasbe commented Apr 22, 2024

Thank you all for helping on this one. The fix is really elegant :)

@crasbe crasbe deleted the pr/nrf52840_jlink branch April 22, 2024 18:52
@mguetschow mguetschow added this to the Release 2024.07 milestone Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

riotboot/nrf52840dk: flashing slot1 with JLINK fails
6 participants