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.

@PJ_Glasso .

I have an issue with my JLink display on PlatformIO, which I think is a PlatformIO bug as per this thread.

As you also use JLink, can you do me a favour?

Can you create a new blank PIO project for Arduino using the nrf52840DK board, don’t worry that you don’t have that board as the check happens later.

The INI file should be

[env:nrf52840_dk]
platform = nordicnrf52
board = nrf52840_dk
framework = arduino

Then try to debug, I want to see if you get the same output formatting as me before I log it as a bug ticket.

Hi there,
Actually I do have one, nRF52840-DK,
I opened a Empty PIO project, Built it AOK,
Hit debug and Yes, the Width is locked, but appears to work Either way?
Not as tight as the display you have,
Here is what it looks like

Checking size .pio\build\nrf52840_dk\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.1% (used 140 bytes from 262144 bytes)
Flash: [          ]   0.2% (used 1968 bytes from 1048576 bytes)
Building .pio\build\nrf52840_dk\firmware.hex
============================================================================= [SUCCESS] Took 1.72 seconds =============================================================================

J
LinkARM.dll V7.88k (DLL compiled Jul  5 2023 15:00:41)

Command line: -single
r
un -if SWD -select USB -device nRF52840_xxAA -port 2331
-----GDB Server start settings-----
GDBInit file: 
                none
GDB Server Listening port:     2331
SWO raw
 
output listening port: 2332
Terminal I/O port:      
 
      2333
Accept remote connecti
on:      loc
al
host only
Generate logfile:         
     off
Verify download:
               off
Init re
gs on start:            off

Silent mode:             
      off
Single run mode:      
         on

Terminal output;

 *  Executing task: C:\Users\Dude\.platformio\penv\Scripts\platformio.exe debug 

Processing nrf52840_dk (platform: nordicnrf52; board: nrf52840_dk; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/nrf52840_dk.html
PLATFORM: Nordic nRF52 (10.1.0+sha.cac6fcf) > Nordic nRF52840-DK
HARDWARE: NRF52840 64MHz, 256KB RAM, 1MB Flash
DEBUG: Current (jlink) On-board (cmsis-dap, jlink) External (blackmagic, stlink)
PACKAGES: 
 - framework-arduinonordicnrf5 @ 1.700.201209 (7.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 2 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Compiling .pio\build\nrf52840_dk\src\main.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduinoVariant\variant.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\Print.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\RingBuffer.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf51.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf52.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf52805.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf52810.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf52811.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf52820.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf52833.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf52840.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf5340_application.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\gcc\gcc_startup_nrf5340_network.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf51.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf52.c.o
src\main.cpp: In function 'void setup()':
src\main.cpp:8:7: warning: unused variable 'result' [-Wunused-variable]
   int result = myFunction(2, 3);
       ^~~~~~
Archiving .pio\build\nrf52840_dk\libFrameworkArduinoVariant.a
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf52805.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf52810.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf52811.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf52820.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf52833.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf52840.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf5340_application.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\SDK\components\toolchain\system_nrf5340_network.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\Uart.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\WInterrupts.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\WString.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\abi.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\avr\dtostrf.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\delay.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\hooks.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\itoa.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\main.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\new.cpp.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\pulse.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\pulse_asm.S.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\wiring.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\wiring_analog_nRF51.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\wiring_analog_nRF52.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\wiring_private.c.o
Compiling .pio\build\nrf52840_dk\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\nrf52840_dk\libFrameworkArduino.a
Linking .pio\build\nrf52840_dk\firmware.elf

Works Great!
HTH
GL :slight_smile: PJ :v:

Perfect thanks will log bug report on the display issue.

Next issue is with the Adafruit Bluefruit implimentation of that board.

If you replace the ini file with

[env:nrf52840_dk_adafruit]
framework = arduino
platform = nordicnrf52
board = nrf52840_dk_adafruit

You will now get a bootloader option under Project Tasks
image

If you try to Upload or Debug, the program won’t load as the bootloader is not included in the firmware, if you “Burn Bootloader” first, then upload or debug it works, but if you stop the debug and then restart it will erase the bootloader.

This behavour feels wrong to me, either the bootloader should be included in the upload/debug or once the bootloader is loaded it shouldn’t be erased by an upload/debug.

Can you confirm you get the same behavour, and I will log a bug.

As per my post here

Thanks
Dave