"Failed to open listener port 2331" starting JLINK

I’m receiving the above error when trying to start the Unified Debugger on an nRF52. I had this working in the past on the nRF52 but when I created a new project I can’t get the debugger to start.

I’m also receiving the warnings:
Cannot insert breakpoint 1.
Cannot access memory at address 0x26334

My program is just the default null project with empty setup() { } and loop() { } procedures.

This is the complete log:

PlatformIO: Initializing remote target…

0x02a000a0 in ?? ()

Select auto target interface speed (2000 kHz)

Resetting target

Loading section .text, size 0x84ac lma 0x26000

Loading section .ARM.exidx, size 0x8 lma 0x2e4ac

Loading section .data, size 0x23c lma 0x2e4b4

Start address 0x262b8, load size 34544

Transfer rate: 16867 KB/sec, 6908 bytes/write.

Temporary breakpoint 1 at 0x26334: file /Users/chrisgr/.platformio/packages/framework-arduinoadafruitnrf52/cores/nRF5/main.cpp, line 75.

PlatformIO: Initialization completed

PlatformIO: Resume the execution to debug_init_break = tbreak main

PlatformIO: More configuration options → Redirecting...

Warning:

Cannot insert breakpoint 1.

Cannot access memory at address 0x26334

Command aborted.

Can you provide additional information please:

  • Exact type of your debug probe
  • Exact type of your board and MCU
  • Full log from DEBUB CONSOLE (if you are using Visual Studio Code)
  • Conents of platformio.ini file

main.cpp A newly created project. The platformio.ini was edited to use J-LINK

#include <Arduino.h>
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}

Probe:J-LINK Edu.
Board: Adafruit Feather Express nRF52840.

platformio.ini:

[env:adafruit_feather_nrf52840]
platform = nordicnrf52
board = adafruit_feather_nrf52840
framework = arduino
debug_tool = jlink
; SWD interface
upload_protocol = jlink

Debug Log:

Processing adafruit_feather_nrf52840 (platform: nordicnrf52; board: adafruit_feather_nrf52840; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Nordic nRF52 4.2.0 > Adafruit Feather nRF52840 Express
HARDWARE: NRF52840 64MHz, 243KB RAM, 796KB Flash
DEBUG: Current (jlink) External (jlink, stlink)
PACKAGES:

  • framework-arduinoadafruitnrf52 1.1900.200401 (19.0)
  • tool-sreccat 1.164.0 (1.64)
  • toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 11 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in debug mode
    Checking size .pio/build/adafruit_feather_nrf52840/firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 2.7% (used 6608 bytes from 248832 bytes)
    Flash: [ ] 4.2% (used 34544 bytes from 815104 bytes)
    ========================= [SUCCESS] Took 1.30 seconds =========================
    SEGGER J-Link GDB Server V6.52 Command Line Version
    JLinkARM.dll V6.52 (DLL compiled Sep 27 2019 17:51:01)

Command line: -singlerun -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 connection: yes
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 V10 compiled Jan 7 2020 16:51:47
Hardware: V10.10
S/N: 260117951
OEM: SEGGER-EDU
Feature(s): FlashBP, GDB
Checking target voltage…
Target voltage: 3.30 V
ERROR: Failed to listen at socket (Err = -1)
ERROR: Failed to open listener port 2331
Restoring target state and closing J-Link connection…
Shutting down…
undefinedFailed to open listener port 2331
Reading symbols from /Users/chrisgr/Documents/PlatformIO/Projects/nRF Test 2/.pio/build/adafruit_feather_nrf52840/firmware.elf…
done.
PlatformIO Unified Debugger → Redirecting...
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target…
0x02a000a0 in ?? ()
Select auto target interface speed (2000 kHz)
Resetting target
Loading section .text, size 0x84ac lma 0x26000
Loading section .ARM.exidx, size 0x8 lma 0x2e4ac
Loading section .data, size 0x23c lma 0x2e4b4
Start address 0x262b8, load size 34544
Transfer rate: 11244 KB/sec, 6908 bytes/write.
Temporary breakpoint 1 at 0x26334:

file /Users/chrisgr/.platformio/packages/framework-arduinoadafruitnrf52/cores/nRF5/main.cpp, line 75.

PlatformIO: Initialization completed
PlatformIO: Resume the execution to debug_init_break = tbreak main
PlatformIO: More configuration options → Redirecting...
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x26334

Command aborted.

I got it working. I think the problem may have been that JLinkGDBServer was not running. I expected the debug server to either be loaded when a USB J-LINK was plugged in or when it was called on by PIO. To start it I tried rebooting with the J-LINK USB plugged in and this apparently did start it.

Now I am able to start the above project in debug mode. I’m still not sure why JLinkGDBServer was not running because I had successfully used it before without having to explicitely start it.