Why Can’t I Debug

I’m running VSCode with Platform IO on a Mac running BigSur and once again I am unable to debug my code. This happens regularly and is becoming very frustrating as I lose days fixing it.

My latest set of errors are

Processing nano33iot (platform: atmelsam; board: nano_33_iot; framework: arduino)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/nano_33_iot.html
PLATFORM: Atmel SAM (6.1.0) > NANO 33 IoT
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (jlink) External (atmel-ice, blackmagic, jlink)
 - framework-arduino-samd 1.8.11 
 - framework-cmsis 1.40500.0 (4.5.0) 
 - framework-cmsis-atmel 1.2.2 
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Checking size .pio/build/nano33iot/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.8% (used 2544 bytes from 32768 bytes)
Flash: [=         ]   5.7% (used 15016 bytes from 262144 bytes)
========================= [SUCCESS] Took 0.73 seconds =========================

Environment    Status    Duration
-------------  --------  ------------
nano33iot      SUCCESS   00:00:00.728
========================= 1 succeeded in 00:00:00.728 =========================
SEGGER J-Link GDB Server V7.20 Command Line Version
JLinkARM.dll V7.20 (DLL compiled Apr 28 2021 17:34:09)

Command line: -singlerun -if SWD -select USB -device ATSAMD21G18 -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:                 ATSAMD21G18
Target interface:              SWD
Target interface speed:        4000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link EDU Mini V1 compiled Feb 18 2021 11:25:23
Hardware: V1.00
S/N: 801024088
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.29 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/matthew/Development/Interrupts/.pio/build/nano33iot/firmware.elf...
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target...
0x2042be12 in ?? ()
Select auto target interface speed (2000 kHz)
Resetting target
Loading section .text, size 0x3a14 lma 0x2000
Loading section .ramfunc, size 0x5c lma 0x5a14
Loading section .data, size 0x94 lma 0x5a70
Start address 0x3e80, load size 15108
Transfer rate: 120864 bits in <1 sec, 5036 bytes/write.
Temporary breakpoint 1 at 0x23ac: file src/main.cpp, line 275.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak setup`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
Cannot insert breakpoint 2.
Cannot access memory at address 0x2106
Cannot insert breakpoint 1.
Cannot access memory at address 0x23ac
Cannot insert breakpoint 3.
Cannot access memory at address 0x23d8
Cannot insert breakpoint 4.
Cannot access memory at address 0x2438
Cannot insert breakpoint 5.
Cannot access memory at address 0x2448

Command aborted.

I have tried reinstalling VSCode, PlatformIO, Segger JLink, various extensions. I’ve switched back to a code base that worked previously, checked and played with settings and yet I am unable to figure this out. My suspicion is that some software has been updated and therefore I am once again stuck.

Does anyone have any idea where I go next??

A load memory address of 0x2000 of the main code indicates you debugging something that has a bootloader. I’ve seen many instances here where having a bootloader (that uses USB) interfered with the ability to debug correctly, the solution to that being to create a modified board definition file with adapted offset information and linker script. That was also for exactly ATSAMD21 chips by the way. See e.g. Problems starting debug session with jlink on feather M0 - #11 by prototypicalpro

This seems fishy to me when that is what JLink says as one of the first startup messages. Maybe you can ask why that could be on the JLink forums.

Either the connection from GDB to JLink is dead (previous socket issue?) or there’s something wrong with Jlink, or there are too many breakpoints set and it exceeds the hardware capabilities.

If you think that a JLink software update is at fault here, use platform_packages to adapt the version of the tool-jlink package with one of the available versions. The same can be done for the toolchain (which includes GDB as the other side), toolchain-gccarmnoneeabi. For example, add

; revert JLink.exe and friends from 7.20 back to  6.88.1
platform_packages = 

You can also revert back the entire platform version fpr Atmel-SAM, see releases in conjuction with documentation.

Hi maxgerhardt,

many thanks for replying, I feel we have discussed similar issues previously.

I think I understand what you are saying, but I am confused as to why now I can’t debug, when I could last month without any down changes taking place. I have used the jlink hardware and software for a couple of years, and it periodically stops working with no real evidence as to why.

Yes the Arduino is running a boot loader, it always has and as far as I know it hasn’t changed. The only change is the updates on VSCode and Platform IO.

I will get onto the Segger forum and ask the same question, but I know it is not too many breakpoints as I removed all but one to try and figure it out.

I just wish I got some decent information to work with or could find an understanding of what is actually going on as it is all just black box stuff.

thanks for your reply, I really appreciate it.

Not sure which, but I think it is working again

I have again re-installed the Segger tools and the Xcode Command line tools and voila, it is debugging again. There must be some dependency that gets broken.

thanks for your help.