Gdb with ATmega2560 (vscode) gets pioinit:13 - no SERIAL_PORT

I’m trying to initiate debugging using avr-stub on an ATmega2560 (arduino). I’ve simplified my project as much as possible. It seems to compile, load, and try to start debugging when it gets:

========================= [SUCCESS] Took 3.05 seconds =========================
Reading symbols from /home/don/Documents/PlatformIO/Projects/Testing/.pio/build/megaatmega2560/firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = avr-stub
PlatformIO: Initializing remote target...
.pioinit:13: Error in sourced command file:
SERIAL_PORT: No such file or directory.

Since it loads, I presume at least vscode is detecting the proper port.

My platform.ini:

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
debug_tool = avr-stub
debug_port = SERIAL_PORT
lib_deps = 
      jdolinay/avr-debugger @ ~1.1
board_build.mcu = atmega2560
board_build.f_cpu = 16000000L

and my code is:
#include “Arduino.h”
#include “…/.pio/libdeps/megaatmega2560/avr-debugger/avr8-stub/avr8-stub.h”
#define PIN_LED_8 (8u)
#define DIGIT_1 PIN_LED_8

void setup() {
    debug_init();
    breakpoint();
    pinMode(DIGIT_1, OUTPUT);
    digitalWrite(DIGIT_1, LOW);
    delay(500);
    digitalWrite(DIGIT_1, HIGH);
    delay(500);
}

void loop() {
    breakpoint();
    for (int i = 5; i > 0; i--) {
        digitalWrite(DIGIT_1, LOW);
        delay(500);
        digitalWrite(DIGIT_1, HIGH);
        delay(500);
    }
    for (int i = 50; i > 0; i--) {
        digitalWrite(DIGIT_1, LOW);
        delay(50);
        digitalWrite(DIGIT_1, HIGH);
        delay(50);
    }
}

I’ve verified that everything works if I don’t try to debug it. I’m at a bit of a loss about what may be wrong. Any help appreciated.
–Don

You’re supposed to put the serial port you’re connecting to here. Go into your Windows device manager and check for the serial ports named “COM…”. The last COM port is porobably the right one. Then put that COM port name instead of SERIAL_PORT.

Thx, I’m on Ubuntu and it is otherwise detecting the port (ttyacm0, I believe). You are saying that platform.ini operates differently when starting gdb? or the port is somehow properly detected for loading, but not executing (maybe it’s known by my system, but doesn’t get to the board for reverse communication??), or …

I’ve stumbled with port problems before, so I’m not surprised here. I was thinking the name SERIAL_PORT was already bound to the proper port during the build.

You can also try it without and see if PIO’s auto-detect port logic kicks in. PIO could probably do it automatically, but if it says in the docs that you should give it a serial port, better to do so.

platformio.ini files can use externally-bound variable names but that is then with a $ prefix, e.g. $UPLOAD_PORT or $PROJECT_PACKAGES_DIR (example docs)

I hate to be thick here, but I’ve tried both ttyS0 and ttyACM0 (both identified when running pio device list). I get the same error:

Reading symbols from /home/don/Documents/PlatformIO/Projects/Testing/.pio/build/megaatmega2560/firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = avr-stub
PlatformIO: Initializing remote target...
.pioinit:13: Error in sourced command file:
ttyACM0: No such file or directory.

I have:

debug_tool = avr-stub
debug_port = ttyACM0

Since the complaint is about a file or directory, I would assume that the issue has to do with a file/directory on my system, not on the board under test.

You need the full device path. /dev/ttyACM0. /dev/ttyS0 is usually a hardware COM port on your motherboard, which is the wrong one.

Thanks - that works. Appreciate the help.
–Don