Noob JLink Edu + Arduino Nano 33 IOT + PIO 5.01 Debugger woes

I’m trying to debug the above in PIO hosted by VSCode. I can upload a sketch and have it run, but debugging fails on a number of things and I’ve got to the point where I think it should work, but don’t know where to look to work out what I’ve done wrong…

I should mention I’m a noob at embedded development, but have tons of C/C++, Java etc.

So,

I’ve soldered leads to the 5 pads on the underside of the board and got them plugged into the jlink according like this.

I have a pio.init like this

[env:nano_33_iot]
platform = atmelsam
board = nano_33_iot
framework = arduino
upload_protocol = jlink
debug_tool = jlink

And a sketch like this:

#include <Arduino.h>

int i = 0;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println(“Ready to start counting”);
}

void loop() {
if (i < 1000) {
Serial.println(i++);
}
}

I set a breakpoint at println immediately after the while, but when I run debug and F5 from the initial breakpoint the program stops at the

while(!Serial)

and I see

Program
received signal SIGTRAP, Trace/breakpoint trap.
0x000005f4 in ?? ()

If F5 from there, I get another SIGTRAP and am at the same place on the while. That’s as far as it gets.

When I look at the device monitor there’s nothing shown.

— Available ports:
— Enter port index or full name:

When I upload the sketch I can see a com port.

— More details at Redirecting...
— Miniterm on COM6 9600,8,N,1 —
— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H —

I’ve checked the soldering and my pin connections several times but apart from that, what have I missed???

May be related to Hang Starting nRF52840 Feather Express Under Segger Debugger - #8 by geeksville.

Yes, it was, many thanks for the link.

For those landing here from a search, the solution was to create a file with gdb commands in it and run it from the prompt in the debug console when the program breaks at the init. I’m debugging on Windows 10, and this worked for me with these commands in a file:

define restart
monitor reset
cont
end

Update pio.ini to tell gdb to read the file on startup

debug_extra_cmds = source C:\Users<user name>.gdbinit

The original workaround used the Unix ‘sleep’ command to introduce a delay one second delay between reset and cont, but sleep is not normally available on Windows so I used:

ping -n XXX 127.0.0.1 >nul

Where XXX is 1+ the number of seconds of delay you need. But found that I didn’t need the sleep to get things working.