Issues with using Jlink on Xiao nRF with PlatformIO

This is not strictly speaking an issue with Xiao programming, but an issue coding the nRF for Xiao.

I purchased an nRF52840dk to aid in debugging my device as it has the embedded Jlink debugger but from a software perspective it should be the same as running a dedicated Jlink box.

I am using Arduino with the Bluefruit BLE library, running PlatformIO (6.1.14) on VScode (1.88.0) for Windows (10.0.19045)

There are two issues.
1/ When I use PlatformIO to upload to the nRF52840DK, it erases the device and uploads the application but not the Bootloader, so it doesn’t work. If I Burn the bootloader first then select Upload, same thing. If I Burn the bootloader then try Debug with upload, same thing.

Deleting the PIO directory now allows me to Burn the bootloaded and run debug upload.

But if I try a normal upload, or click debug again it still uploads the application without the bootloader.

I have checked the memory map layout via the nrf programmer app and can confirm that the bootloader is missing.

[env]
framework = arduino
; platform = https://github.com/maxgerhardt/platform-nordicnrf52
platform = nordicnrf52
monitor_speed = 115200 

lib_deps =
  # RECOMMENDED
  # Accept new functionality in a backwards compatible manner and patches
  # adafruit/Adafruit nRFCrypto
  bblanchon/ArduinoJson

[env:nrf52840_dk_adafruit]
board = nrf52840_dk_adafruit
upload_protocol = jlink
;change microcontroller
board_build.mcu = nrf52840
; change MCU frequency
board_build.f_cpu = 64000000L
; board_build.upload.offset_address = 0x00027000

; SoftDevice version
build_flags = -D NRF52_S140
build_type = debug
debug_tool = jlink
debug_build_flags =  -O1 -g3

No errors in the upload process

Processing nrf52840_dk_adafruit (board: nrf52840_dk_adafruit; framework: arduino; platform: nordicnrf52)
---------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/nrf52840_dk_adafruit.html
PLATFORM: Nordic nRF52 (10.1.0+sha.cac6fcf) > Nordic nRF52840-DK (Adafruit BSP)
HARDWARE: NRF52840 64MHz, 243KB RAM, 796KB Flash
DEBUG: Current (jlink) On-board (jlink) External (blackmagic, cmsis-dap, stlink)
PACKAGES:
 - framework-arduinoadafruitnrf52 @ 1.10500.0 (1.5.0)
 - framework-cmsis @ 2.50700.210515 (5.7.0)
 - tool-adafruit-nrfutil @ 1.503.0 (5.3)
 - tool-bossac-nordicnrf52 @ 1.10901.201022 (1.9.1)
 - tool-jlink @ 1.78811.0 (7.88.11)
 - tool-openocd @ 3.1200.0 (12.0)
 - tool-sreccat @ 1.164.0 (1.64)
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 14 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ArduinoJson @ 7.0.4
|-- Adafruit Bluefruit nRF52 Libraries
Building in debug mode
Checking size .pio\build\nrf52840_dk_adafruit\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.0% (used 17532 bytes from 248832 bytes)
Flash: [==        ]  17.0% (used 138368 bytes from 815104 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, nrfjprog, stlink
CURRENT: upload_protocol = jlink
Uploading .pio\build\nrf52840_dk_adafruit\firmware_signature.bin
SEGGER J-Link Commander V7.88k (Compiled Jul  5 2023 15:02:18)
DLL version V7.88k, compiled Jul  5 2023 15:00:41


J-Link Command File read successfully.
Processing script file...
J-Link>h
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 Oct 30 2023 12:13:06
Hardware version: V1.00
J-Link uptime (since boot): 6d 00h 25m 05s
S/N: 1050210305
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 "NRF52840_XXAA" selected.


Connecting to target via SWD
InitTarget() start
InitTarget() end - Took 7.40ms
Found SW-DP with ID 0x2BA01477
DPIDR: 0x2BA01477
CoreSight SoC-400 or earlier
Scanning AP map to find all available APs
AP[2]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
AP[1]: JTAG-AP (IDR: 0x02880000)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
[0][0]: E000E000 CID B105E00D PID 000BB00C SCS-M7
[0][1]: E0001000 CID B105E00D PID 003BB002 DWT
[0][2]: E0002000 CID B105E00D PID 002BB003 FPB
[0][3]: E0000000 CID B105E00D PID 003BB001 ITM
[0][4]: E0040000 CID B105900D PID 000BB9A1 TPIU
[0][5]: E0041000 CID B105900D PID 000BB925 ETM
Memory zones:
  Zone: "Default" Description: Default access mode
Cortex-M4 identified.
PC = FFFFFFFE, CycleCnt = 001A620F
R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000
SP(R13)= FFFFFFD8, MSP= FFFFFFD8, PSP= 00000000, R14(LR) = FFFFFFF9
XPSR = 01000003: APSR = nzcvq, EPSR = 01000000, IPSR = 003 (HardFault)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00

FPS0 = 00000000, FPS1 = 00000000, FPS2 = 00000000, FPS3 = 00000000
FPS4 = 00000000, FPS5 = 00000000, FPS6 = 00000000, FPS7 = 00000000
FPS8 = 00000000, FPS9 = 00000000, FPS10= 00000000, FPS11= 00000000
FPS12= 00000000, FPS13= 00000000, FPS14= 00000000, FPS15= 00000000
FPS16= 00000000, FPS17= 00000000, FPS18= 00000000, FPS19= 00000000
FPS20= 00000000, FPS21= 00000000, FPS22= 00000000, FPS23= 00000000
FPS24= 00000000, FPS25= 00000000, FPS26= 00000000, FPS27= 00000000
FPS28= 00000000, FPS29= 00000000, FPS30= 00000000, FPS31= 00000000
FPSCR= 00000000
J-Link>loadbin .pio\build\nrf52840_dk_adafruit\firmware.bin,0x26000
'loadbin': Performing implicit reset & halt of MCU.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
Downloading file [.pio\build\nrf52840_dk_adafruit\firmware.bin]...
Comparing flash   [100%] Done.
Erasing flash     [100%] Done.
Programming flash [100%] Done.
J-Link: Flash download: Bank 0 @ 0x00000000: 1 range affected (139264 bytes)
J-Link: Flash download: Total: 1.694s (Prepare: 0.091s, Compare: 0.014s, Erase: 0.000s, Program & Verify: 1.517s, Restore: 0.070s)
J-Link: Flash download: Program & Verify speed: 89 KB/s
O.K.
J-Link>loadbin .pio\build\nrf52840_dk_adafruit\firmware_signature.bin,0xFF000
'loadbin': Performing implicit reset & halt of MCU.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
Downloading file [.pio\build\nrf52840_dk_adafruit\firmware_signature.bin]...
Comparing flash   [100%] Done.
Erasing flash     [100%] Done.
Programming flash [100%] Done.
J-Link: Flash download: Bank 0 @ 0x00000000: 1 range affected (4096 bytes)
J-Link: Flash download: Total: 0.079s (Prepare: 0.042s, Compare: 0.002s, Erase: 0.000s, Program & Verify: 0.010s, Restore: 0.023s)
J-Link: Flash download: Program & Verify speed: 399 KB/s
O.K.
J-Link>r
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
J-Link>q

Script processing completed.

============================================ [SUCCESS] Took 9.13 seconds ============================================

2/ When I am running the debugger the debugger messages (in blue) appear to be limited to 15 chars before they line wrap, in some cases much less than this. The system messages (in red & orange) appear ok.

image

Hi there,
Have you looked at this thread from Epressif.
https://docs.platformio.org/en/stable/boards/nordicnrf52/nrf52840_dk.html
it shows two configurations, You seem to have mixed them together.
What does this line do in your ini, You think ?

GL :slight_smile: PJ :v:
I’m following this one, Arduino and Nordic nRF52-DK: debugging and unit testing — PlatformIO v6.1 documentation

Looks like you need this INI

[env:nrf52_dk]
platform = nordicnrf52
board = nrf52_dk
framework = arduino
debug_tool = jlink
; SoftDevice version
build_flags = -DNRF52_S132
lib_deps =
  BLEPeripheral

Or close to it…HTH :v:

I started with the base INI then started adding things as I came across other suggestions in the docs and forums.

The core fault is that an Upload or Debug erases the board but does not write back the Bootloader. If I burn the bootloader first, then Upload or Debug it works but uploading a second time deletes the Bootloader.

I am running the Bluefruit BLE library so need the board = nrf52840_dk_adafruit.

I have cut back to as below

[env:nrf52840_dk_adafruit]
; platform = https://github.com/platformio/platform-nordicnrf52.git
; platform = https://github.com/maxgerhardt/platform-nordicnrf52
platform = nordicnrf52
monitor_speed = 115200 
board = nrf52840_dk_adafruit
framework = arduino

Changing the Platform to the upstream version did not change the behavour.

The correct bootloader should be part of the board file but I added build_flags = -DNRF52_S140 to see if I could force a bootloader write, but no change.

The Nordic Semiconductor S132 and S140 are both Bluetooth LE protocol stacks that support up to 20 concurrent connections. The S132 is for the nRF52810 and nRF52832 SoCs, while the S140 is for the nRF52840 chip.

Burn Bootloader, then Upload

Upload again

BTW, the Burn Bootloader command is only available with the adafruit board definition.

The Burn Bootloader loads the Softdevice to the board, the blue box in the prior screen shots/

Hi there,
Interested in knowing, Did you add the Arduino Extension to PLIO? What extension do you have loaded? (it brings the board files Arduino uses, AFAIK)
GL :slight_smile: PJ :v:

I think that it may be related to this ticket

I created a ticket on Github for this Board = nrf52840_dk_adafruit missing SoftDevice on Debug and Build · Issue #196 · platformio/platform-nordicnrf52 · GitHub

The issue can be replicated from a new project.