nRF52840 Dongle Debug with JLINK (Internal or External) in NCS 2.1.0

Hi guys,

As I want to debug on my nRF52840 Dongle with a Debugger, my first step was to connect it with internal segger OB JLINK integrated into nRF52840DK.
This was not efficient, and I was not able to debug using the usual and suggested configuration as 


Maybe due to bootloader or voltage references different ?
The VSCode always show me the DK and not the target device.

SO, I tried with a JLINK base device.

Settings are theese:

Hardware config:

JLINK       | nRF52840

SWDIO       | SWDIO
SWDCLK      | SWDCLK
VREF        | VBUS
GND         | GND
RESET       | RESET

nRF52840 is powered by an external battery of 3.7V
I also connected RESET to the testpoint under the dongle.


launch.json is configured as this:

	"configurations": [
	{
		"name": "Debug with JLink",
		"cwd": "${workspaceFolder}",
		"executable": "${workspaceFolder}\\build\\zephyr\\zephyr.hex",
		"request": "launch",
		"type": "cortex-debug",
		"device": "nRF52840_xxAA",
		"runToEntryPoint": "main",
		"showDevDebugOutput": "raw",
		"servertype": "jlink",
		"interface": "swd",
	},

I select as DEBUGGER EXTENSION the Cortex-Debugger (as nRF-Debugger seems to be not working with external debugger)

BUT the dongle is not working.
VSCode shows me this:

[2022-10-14T13:59:10.968Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session connected. You can switch to "DEBUG CONSOLE" to see GDB interactions.
"C:\\Program Files (x86)\\SEGGER\\JLink\\JLinkGDBServerCL.exe" -singlerun -nogui -if swd -port 50000 -swoport 50001 -telnetport 50002 -device nRF52840_xxAA -select usb=51017173 -rtos "C:\\Program Files\\SEGGER\\JLink\\GDBServer\\RTOSPlugin_Zephyr.dll"
SEGGER J-Link GDB Server V7.66a Command Line Version

JLinkARM.dll V7.66a (DLL compiled May 19 2022 15:13:27)

Command line: -singlerun -nogui -if swd -port 50000 -swoport 50001 -telnetport 50002 -device nRF52840_xxAA -select usb=51017173 -rtos C:\Program Files\SEGGER\JLink\GDBServer\RTOSPlugin_Zephyr.dll
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     50000
SWO raw output listening port: 50001
Terminal I/O port:             50002
Accept remote connection:      localhost only
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               on
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 nRF52840_xxAA
Target interface:              SWD
Target interface speed:        4000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link V11 compiled Sep 22 2022 14:53:28
Hardware: V11.00
S/N: 51017173
Feature(s): GDB
Checking target voltage...
Target voltage: 3.45 V
Listening on TCP/IP port 50000
Connecting to target...
Connected to target
Waiting for GDB connection...Connected to 127.0.0.1
Reading all registers
Read 4 bytes @ address 0x00000578 (Data = 0x0000E7FE)
Read 2 bytes @ address 0x00000578 (Data = 0xE7FE)
Loading RTOS plugin: C:\Program Files\SEGGER\JLink\GDBServer\RTOSPlugin_Zephyr.dll...
RTOS plugin load failed (Error 193, %1 is not a valid Win32 application.).
Received monitor command: halt
Halting target CPU...
...Target halted (PC = 0x00000578)
Received monitor command: reset
Resetting target
Downloading 16256 bytes @ address 0x00001000
Downloading 16208 bytes @ address 0x00004F80
Downloading 16224 bytes @ address 0x00008ED0
Downloading 12752 bytes @ address 0x0000CE30
Downloading 16128 bytes @ address 0x00010000
Downloading 16000 bytes @ address 0x00013F00
Downloading 15984 bytes @ address 0x00017D80
Downloading 16048 bytes @ address 0x0001BBF0
Downloading 1376 bytes @ address 0x0001FAA0
Downloading 16032 bytes @ address 0x00020000
Downloading 16032 bytes @ address 0x00023EA0
Downloading 16000 bytes @ address 0x00027D40
Downloading 16016 bytes @ address 0x0002BBC0
Downloading 1456 bytes @ address 0x0002FA50
Downloading 15968 bytes @ address 0x00030000
Downloading 15984 bytes @ address 0x00033E60
Downloading 16032 bytes @ address 0x00037CD0
Downloading 16064 bytes @ address 0x0003BB70
Downloading 1488 bytes @ address 0x0003FA30
Downloading 16112 bytes @ address 0x00040000
Downloading 16272 bytes @ address 0x00043EF0
Downloading 11912 bytes @ address 0x00047E80
Comparing flash   [....................] Done.
Writing register (PC = 0x   1a414)
Received monitor command: reset
Resetting target
Read 4 bytes @ address 0x0001A414 (Data = 0x49132000)
Read 2 bytes @ address 0x0001A414 (Data = 0x2000)
Reading 64 bytes @ address 0x0003B980
Read 2 bytes @ address 0x0003B9C0 (Data = 0xB002)
Reading 64 bytes @ address 0x0003C7C0
Read 2 bytes @ address 0x0003C7CE (Data = 0x4040)
Reading 64 bytes @ address 0x00012500
Read 4 bytes @ address 0x000125D4 (Data = 0x00043694)
Read 2 bytes @ address 0x00012594 (Data = 0xF000)
Read 2 bytes @ address 0x0001250C (Data = 0xB5F0)
Reading register (MSP = 0x20040000)
Reading register (PSP = 0x       0)
Reading register (PRIMASK = 0x       0)
Reading register (BASEPRI = 0x       0)
Reading register (FAULTMASK = 0x       0)
Reading register (CONTROL = 0x       0)
Reading register (FPSCR = 0x       0)
Reading register (s0 = 0x       0)
Reading register (s1 = 0x       0)
Reading register (s2 = 0x       0)
Reading register (s3 = 0x       0)
Reading register (s4 = 0x       0)
Reading register (s5 = 0x       0)
Reading register (s6 = 0x       0)
Reading register (s7 = 0x       0)
Reading register (s8 = 0x       0)
Reading register (s9 = 0x       0)
Reading register (s10 = 0x       0)
Reading register (s11 = 0x       0)
Reading register (s12 = 0x       0)
Reading register (s13 = 0x       0)
Reading register (s14 = 0x       0)
Reading register (s15 = 0x       0)
Reading register (s16 = 0x       0)
Reading register (s17 = 0x       0)
Reading register (s18 = 0x       0)
Reading register (s19 = 0x       0)
Reading register (s20 = 0x       0)
Reading register (s21 = 0x       0)
Reading register (s22 = 0x       0)
Reading register (s23 = 0x       0)
Reading register (s24 = 0x       0)
Reading register (s25 = 0x       0)
Reading register (s26 = 0x       0)
Reading register (s27 = 0x       0)
Reading register (s28 = 0x       0)
Reading register (s29 = 0x       0)
Reading register (s30 = 0x       0)
Reading register (s31 = 0x       0)
Reading register (d0 = 0x       0)
Reading register (d1 = 0x       0)
Reading register (d2 = 0x       0)
Reading register (d3 = 0x       0)
Reading register (d4 = 0x       0)
Reading register (d5 = 0x       0)
Reading register (d6 = 0x       0)
Reading register (d7 = 0x       0)
Reading register (d8 = 0x       0)
Reading register (d9 = 0x       0)
Reading register (d10 = 0x       0)
Reading register (d11 = 0x       0)
Reading register (d12 = 0x       0)
Reading register (d13 = 0x       0)
Reading register (d14 = 0x       0)
Reading register (d15 = 0x       0)
Setting breakpoint @ address 0x0001250C, Size = 2, BPHandle = 0x0001
Setting breakpoint @ address 0x00012594, Size = 2, BPHandle = 0x0002
Setting breakpoint @ address 0x0003B9C0, Size = 2, BPHandle = 0x0003
Setting breakpoint @ address 0x0003C7CE, Size = 2, BPHandle = 0x0004
Starting target CPU...



Another question, as using an external debugger, the original bootloader will be removed... could this cause a problem during compilation? 
I mean, selecting "nRf52840 dongle" in build configuration, will cause an issue if there's no bootloader mounted ?

Parents Reply Children
  • Hi Hung,

    I tried with VBUS = 5V (powering the dongle with USB).

    What I read is this on the terminal VSCode Side:

    Feature(s): GDB
    Checking target voltage...
    Target voltage: 1.83 V
    Listening on TCP/IP port 50000
    Connecting to target...
    Connected to target
    Waiting for GDB connection...Connected to 127.0.0.1
    Reading all registers
    Read 4 bytes @ address 0x00000578 (Data = 0x0000E7FE)
    Read 2 bytes @ address 0x00000578 (Data = 0xE7FE)
    Loading RTOS plugin: C:\Program Files\SEGGER\JLink\GDBServer\RTOSPlugin_Zephyr.dll...
    RTOS plugin load failed (Error 193, %1 is not a valid Win32 application.).
    Received monitor command: halt
    Halting target CPU...
    ...Target halted (PC = 0x00000578)
    Received monitor command: reset
    Resetting target
    Downloading 16256 bytes @ address 0x00001000
    Downloading 16208 bytes @ address 0x00004F80
    Downloading 16224 bytes @ address 0x00008ED0
    Downloading 12752 bytes @ address 0x0000CE30
    Downloading 16128 bytes @ address 0x00010000
    Downloading 16000 bytes @ address 0x00013F00
    Downloading 15984 bytes @ address 0x00017D80
    Downloading 16048 bytes @ address 0x0001BBF0
    Downloading 1376 bytes @ address 0x0001FAA0
    Downloading 16032 bytes @ address 0x00020000
    Downloading 16032 bytes @ address 0x00023EA0
    Downloading 16000 bytes @ address 0x00027D40
    Downloading 16016 bytes @ address 0x0002BBC0
    Downloading 1456 bytes @ address 0x0002FA50
    Downloading 15968 bytes @ address 0x00030000
    Downloading 15984 bytes @ address 0x00033E60
    Downloading 16032 bytes @ address 0x00037CD0
    Downloading 16064 bytes @ address 0x0003BB70
    Downloading 1488 bytes @ address 0x0003FA30
    Downloading 16112 bytes @ address 0x00040000
    Downloading 16272 bytes @ address 0x00043EF0
    Downloading 11912 bytes @ address 0x00047E80
    Comparing flash   [....................] Done.
    Writing register (PC = 0x   1a414)
    Received monitor command: reset
    Resetting target
    Read 4 bytes @ address 0x0001A414 (Data = 0x49132000)
    Read 2 bytes @ address 0x0001A414 (Data = 0x2000)
    Reading 64 bytes @ address 0x0003B980
    Read 2 bytes @ address 0x0003B9C0 (Data = 0xB002)
    Reading 64 bytes @ address 0x0003C7C0
    Read 2 bytes @ address 0x0003C7CE (Data = 0x4040)
    Read 2 bytes @ address 0x0001250C (Data = 0xB5F0)
    Reading register (MSP = 0x20040000)
    Reading register (PSP = 0x       0)
    Reading register (PRIMASK = 0x       0)
    Reading register (BASEPRI = 0x       0)
    Reading register (FAULTMASK = 0x       0)
    Reading register (CONTROL = 0x       0)
    Reading register (FPSCR = 0x       0)
    Reading register (s0 = 0x       0)
    Reading register (s1 = 0x       0)
    Reading register (s2 = 0x       0)
    Reading register (s3 = 0x       0)
    Reading register (s4 = 0x       0)
    Reading register (s5 = 0x       0)
    Reading register (s6 = 0x       0)
    Reading register (s7 = 0x       0)
    Reading register (s8 = 0x       0)
    Reading register (s9 = 0x       0)
    Reading register (s10 = 0x       0)
    Reading register (s11 = 0x       0)
    Reading register (s12 = 0x       0)
    Reading register (s13 = 0x       0)
    Reading register (s14 = 0x       0)
    Reading register (s15 = 0x       0)
    Reading register (s16 = 0x       0)
    Reading register (s17 = 0x       0)
    Reading register (s18 = 0x       0)
    Reading register (s19 = 0x       0)
    Reading register (s20 = 0x       0)
    Reading register (s21 = 0x       0)
    Reading register (s22 = 0x       0)
    Reading register (s23 = 0x       0)
    Reading register (s24 = 0x       0)
    Reading register (s25 = 0x       0)
    Reading register (s26 = 0x       0)
    Reading register (s27 = 0x       0)
    Reading register (s28 = 0x       0)
    Reading register (s29 = 0x       0)
    Reading register (s30 = 0x       0)
    Reading register (s31 = 0x       0)
    Reading register (d0 = 0x       0)
    Reading register (d1 = 0x       0)
    Reading register (d2 = 0x       0)
    Reading register (d3 = 0x       0)
    Reading register (d4 = 0x       0)
    Reading register (d5 = 0x       0)
    Reading register (d6 = 0x       0)
    Reading register (d7 = 0x       0)
    Reading register (d8 = 0x       0)
    Reading register (d9 = 0x       0)
    Reading register (d10 = 0x       0)
    Reading register (d11 = 0x       0)
    Reading register (d12 = 0x       0)
    Reading register (d13 = 0x       0)
    Reading register (d14 = 0x       0)
    Reading register (d15 = 0x       0)
    Setting breakpoint @ address 0x0001250C, Size = 2, BPHandle = 0x0001
    Setting breakpoint @ address 0x0003B9C0, Size = 2, BPHandle = 0x0002
    Setting breakpoint @ address 0x0003C7CE, Size = 2, BPHandle = 0x0003
    Starting target CPU...
    

    but nothing happens.............. and breakpoints are not working.

    To the Debug Console Side I can see this:

    Cortex-Debug: VSCode debugger extension version 1.6.6 git(9844153). Usage info: https://github.com/Marus/cortex-debug#usage
    Warn: c:/2BiTS/progetti/ShockTest/iotnode/build_dongle/zephyr/zephyr.hex is not an ELF file format. Some features won't work -- Globals, Locals, disassembly, etc.Launching GDB: "c:\\ncs\\toolchains\\v2.1.0-rc2\\opt\\zephyr-sdk\\arm-zephyr-eabi\\bin\\arm-zephyr-eabi-gdb-no-py.exe" -q --interpreter=mi2
       
        IMPORTANT: Set "showDevDebugOutput": "raw" in "launch.json" to see verbose GDB transactions here. Very helpful to debug issues or report problems
    Launching gdb-server: "C:\\Program Files (x86)\\SEGGER\\JLink\\JLinkGDBServerCL.exe" -singlerun -nogui -if swd -port 50000 -swoport 50001 -telnetport 50002 -device nRF52840_xxAA -select usb=51017173 -rtos "C:\\Program Files\\SEGGER\\JLink\\GDBServer\\RTOSPlugin_Zephyr.dll"
       
        Please check TERMINAL tab (gdb-server) for output from C:\Program Files (x86)\SEGGER\JLink\JLinkGDBServerCL.exe
    
    0x00000578 in ?? ()
    Program stopped, probably due to a reset and/or halt issued by debugger
    add symbol table from file "c:/2BiTS/progetti/ShockTest/iotnode/build_dongle/zephyr/zephyr.elf"
    (y or n) [answered Y; input not from terminal]
    Reading symbols from c:/2BiTS/progetti/ShockTest/iotnode/build_dongle/zephyr/zephyr.elf...
    
    
    2 Resetting target

    this is the only think I can see... 


    Another question, in the guide there's the indication in order to maintain the original bootloader on the device.
    Is it necessary if I use an external debugger ?

    I ask this because if I flash from scratch my application, using the jlink and the nordic programmer tool, my application doesn't start.....

  • Hi Enrico, 
    I don't think trying to debug zephyr application would be a good idea to test. 
    Please try to test by just reading and writing  /erasing to a location in the memory of the dongle to make sure you can write to it. 
    What I would suggest is to write something to the PCA10056 , for example blinky firmware. Let it blink. Just to make sure you don't erase the wrong chip and you are actually working with the dongle instead of the PCA10056. 
    After that you can start either by Jlink Commander or by nrfjprog.exe I would suggest nrfjprog. 

    You can try to do a nrfjprog --eraseall , or nrfjprog --memrd or nrfjprog --memwr to test. 

    After you have verify that you can erase, write to the dongle, you can start testing with debugging an application. 

  • Hi Hung, 

    Using nRF programmer tool I can write and read to Dongle.
    I tested for example flasing the original bootloader, thus, jlink is working properly.

    The problems remain during debugging and also trying to flash an application.
    How can I go on this issue ? Using a professional and common debugger as JLink is fundamental for companies which builts a lot of custom board on your devices... and that's why I need to debug well dongle before going on production stages.

    thank you so much Hung, waiting for your support!
    Enrico 

  • Hi Enrico, 

    Please be aware that the dongle is not a development board, it's more of a end device for nRF Connect and the nRF Sniffer please find the following in the documentation: 
    For other use cases please do note that there is no debug support on the Dongle, only support for programming the device and communicating through USB."

    After you managed to flash bootloader, next step is to try erase everything and flash a simple application for example blinking LED.

    After you have the LED blink correctly, you can start debugging. I assume you will use GDB for debug ? 
    Make sure you select debug option when you build the application. 

  • Hi again Enrico, 

    Please try to sum up your issue. Maybe it's easier to answer the following questions: 

    - Have you managed to program any application to the dongle. Please test with very simple application for example blinky.

    - If you can flash the blinky application, did the blinky work ? (LED blink ?)

    - Have you managed to flash the bootloader on the dongle ? Which bootloader you used ? 

    - Please state step by step how you run the debugger ? Which GDB server you used ?  Have you configure the board for debugging. You need to select this : 

Related