Understanding terminal prints for debugging

Hi, I’ve been working Arduino for a couple weeks now. I’ve had some success debugging but I just wonder why I can’t perform the easiest of all debugging the print statement.

I am running VS Code with a PlatformIO extension.
My target is a mega 2560 Rev 3

I am able to set breakpoints, view memory and view watch variables when compiler optimization is disabled.

What I would like to do is also be able to print to the terminal.
It makes sense to me that I can’t do this during a debug session but I can’t get it to work at all.
I’m running a tight loop with a 300 ms delay
Here’s my setup and loop

void setup() {
debug_init();
pinMode(13, OUTPUT);
Serial1.begin(57600);
// The next statement causes the error
Serial.begin(9600); // Serial seems to be extended from HardwareSerial
}
loop() {
delay(300);
if (lightOn) {
lightOn = false;
digitalWrite(13,HIGH);
}
else {
lightOn = true;
digitalWrite(13,LOW);
}
}

And here is the error I get when the line in setup() is Not commented out

Linking .pio\build\megaatmega2560\firmware.elf
HardwareSerial0.cpp.o (symbol from plugin): In function Serial': (.text+0x0): multiple definition of __vector_25’
avr8-stub.c.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\megaatmega2560\firmware.elf] Error 1
================================================ [FAILED] Took 1.40 seconds

And my Platformio.ini file looks like this. I commented out all debug info but fails no matter what
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
;debug_tool = avr-stub
;debug_port = COM3
;build_flags = -DRS_SERIAL_PORT=Serial3
;debug_build_flags = -O0 -ggdb3 -g3 ;disable compile options
lib_deps = jdolinay/avr-debugger @ ~1.4

I know it’s possible so if you have an idea please let me know.

thanks

Rick

You are using an outdated version of the avr-debugger library, please upgrade it to

lib_deps = jdolinay/avr-debugger@^1.5

per library page.

Yes, exactly – we’ve already talked about this in Linker error after adding the RS485 library - #2 by maxgerhardt, since the avr-debugger library is default-configured to use the Serial hardware (USART0), all usages of Serial in your firmware code are forbidden, attempting to use it will cause a linker error. As is documented.

Serial uses USART0.
Serial1 uses USART1 (Rx=PD2=D19, Tx=PD3=D18), etc.

Thank you for mentioning that I was using an outdated avr-debugger

It’s true that you mentioned this before and that helped me in understanding why I was getting this error but it did not help me understand how I can enable terminal prints.

I work with someone that has been using the same board which is identical to my setup (board and IDE) but he never used any debugging except the print to terminal so I know it’s possible) I’m just trying to understand how to do that on my system.

I even created several brand new projects based on different articles all similar to

which did not work

I’m actually just fine using breakpoints, watch windows and memory dumps but I’m just trying to get grasp of what’s going on. Thanks so much for your input.
Kind Regards,
Rick