Error: Please specify `debug_port` for environment debugging Arduino

Before this program did an update I had no problem debugging my code. I spent three days on line trying to resolve the issue. I can upload and run my program but now since the update I get this error. I try going back to an early version and still no luck. When I start debugging I get a pop up box saying " The preLaunchTask undefine terminated with exit code 1". I have tried to do everything that I found on the internet with no luck. I uninstall this program and visual studio code software plus scan my computer for any files and folders that contained both software and deleted everything. I really like using this program when it was working great to debug the Arduino boards but since the upgrade I can’t. Any help would be appreciated Thanks.

With which method are you debugging the which exact Arduino?

Full platformio.ini

What’s the output in the “Debug Console” when debugging?

After I write the code I setup my break points and hit F5 to start debugging. In the past I was able to write the code and debug it for either the mega board or the uno board. When I debug this I ge the following message and then the pop up box.t

> Executing task in folder test bug: C:\Users\xxxxx\.platformio\penv\Scripts\platformio.exe debug <

Error: Please specify `debug_port` for environment
The terminal process "C:\Users\xxxxx\.platformio\penv\Scripts\platformio.exe 'debug'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.

This is what the program generated for the platformio.ini

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino

Newer updates have introduced avr-stub as the default debugging tool instead of the simavr program.

That is documented at the board page.

Since the default is avr-stub know it looks for a COM port where it can connect to the GDB server opened by the avr-stub library (docs).

Since it seems you want to keep the old behavior and debug in the simulator, just set

debug_tool = simavr

in the platformio.ini.

I only went back to the old to see if I could get the debugging to work again. I am going to do update and then try what you suggested . and Thanks for the help.

Thanks maxgerhardt Your suggestions helped and pointing me in the right direction. Here is what I added to the Platformio.ini

debug_tool = avr-stub
debug_port = SERIAL_PORT

This is incomplete because

  • SERIAL_PORT has to be substituted with the actual serial port identifier that the device is connected to
  • lib_deps = jdolinay/avr-debugger @ ~1.1 as a library dependency needs to be added and special code has to be written to start the avr-stub and your firmware must not use the Serial, per above linked documentation

There’s a complete example at How to debug on Arduino mega 2560 - #2 by maxgerhardt.

But you got me a little bit confused: The old behavior should have been just simavr, (simulated device) and now you’ve switched to avr-stub (executed on real device). Are you 100% sure that that’s what you initially wanted?

Maxgerhardt,
thanks for the help
I have done more research online trying to figure this out I am new to setting up the platformio.ini. Here is my latest code I have tried using and getting a new error.

[env:uno]

platform = atmelavr

board = uno

framework = arduino

upload_port = COM4

debug_port = COM4

[env:debug]

platform = atmelavr

board = uno

DEBUG_TOOL = avr-stub

; Set optimization level and amount of debug information generated by the compiler

debug_build_flags = -O0 -ggdb3 -g3

debug_init_break = tbreak Reset_Handler

I am still researching and I am kind of getting closer because now I am getting the following error and I have not figured it out yet.
" Failed to launch GDB::.pionit13: Error in sourced command file: Bogus trace status reply from target timeout ( from interpreter-exec console “source.pioinit”)

I know there is one more thing I need to config and I haven’t found it yet.

I am using the latest software for PlatformIO , Python 3.8 and Visual Studio code.

Reset_Handler is for ARM Cortex chip – this won’t work on your Atmel AVR type chip. You’re telling PlatformIO here that you want to break at this function that doesn’t exist. You should leave it out, then PIO will automatically break in setup.

This should not be necessary unless you want to investigate something that doesn’t show up with the default -Og behavior.

Should be lower-case.

Also I don’t see the lib_deps line for the debugger library there.

Are you able to reproduce a working debugging setup when following the complete example linked above, while exchanging my COM14 with your COM4?

I removed everything off my computer in case I had a corrupt file for the platformio. I reinstalled it to start from the beginning. In my ini file I put in

[env:uno]
platform = atmelavr
board = uno
framework = arduino
; Set breakpoint mode
build_flags =
  -DAVR8_BREAKPOINT_MODE=1
debug_tool = avr-stub
debug_port = COM4  ; COM 4
lib_deps =
    jdolinay/avr-debugger @ ~1.1

In my debug console I am now getting this message.

========================= [SUCCESS] Took 2.68 seconds =========================
Reading symbols from C:\Users\jmonte\Documents\PlatformIO\Projects\Blinky.pio\build\uno\firmware.elf…
done.
PlatformIO Unified Debugger → Redirecting...
PlatformIO: debug_tool = avr-stub
PlatformIO: Initializing remote target…
Ignoring packet error, continuing…
warning: unrecognized item “timeout” in “qSupported” response
Ignoring packet error, continuing…
.pioinit:13: Error in sourced command file:
Bogus trace status reply from target: timeout
and my code have the following include files:
#include <Arduino.h>
#include <avr8-stub.h>
I’m new to this and I am still scanning the web to find the solution. Setting up the ini file is new to me and I am still learning about all the commands for it.

Seems like the device didn’t answer. The code in the src\main.cpp is the same as per avr-stub — PlatformIO latest documentation? Otherwise the GDB server won’t run on the device.

Try without lines ifyou still have problems.

Okay Here is what now is happening with debugging. I try with a Uno and a Mega board. Now when I debug it will run but will not stop at break point search on line try many things this is what I have now .
In my Platformio.ini I have the following setup.

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
; change microcontroller
board_build.mcu = atmega2560
; change MCU frequency
board_build.f_cpu = 16000000
debu_tool = avr-stub
debug_port = \\.\COM7 ; Read in a post that the program works better with \\.\COM7 but tried with just COM7
build_type = debug
; GDB stub implementation
lib_deps = jdolinay/avr-debugger @ ~1.2 ; Note try 1.1
debug_int_break = tbreak setup

I also came across adding breakpoint() inside the program. I used the blink to try to get the debugging to work again after the upgrade of the AVR.

#include <Arduino.h>
#include <avr8-stub.h>
#include <app_api.h>
int x;
void setup() {
  debug_init(); // added to see if I can get it to work right found on PlatformIO site
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  x  = 0;
    breakpoint(); // added to see if I can get it to work right found on PlatformIO site
// Placed a break point on the left side of the next line. I added the x into the program to get the debugging to break at this point. 
   x = 1;
   x = 34;
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

I notice I started to have a debugging issue after the AVR upgraded. I also removed everything off my computer and try reloading the older version to see if I can get the debugger to work but I ended up striking out.

Works for me on the latest VSCode + PlatformIO core + Atmel AVR platform version (3.3.0) on my Uno.

I’ve changed the platformio.ini accordingly with my actual COM port number that I see in the device manager.

[env:megaatmega2560]
platform = atmelavr
board = uno
framework = arduino
; change microcontroller
;board_build.mcu = atmega2560
; change MCU frequency
;board_build.f_cpu = 16000000
debu_tool = avr-stub
debug_port = \\.\COM33  
build_type = debug
; GDB stub implementation
lib_deps = jdolinay/avr-debugger @ ~1.2 ; Note try 1.1
debug_int_break = tbreak setup

Note that in my screenshot, it didn’t stop at the x = 1; line. This is expected since the debug build is done with -Og optimization, so optimizes a tiny bit for debug an the variable gets killed. If I completely disable optimizations per Redirecting... by further adding

debug_build_flags = -O0 -ggdb3 -g3

in the platformio.ini, it does stop in that line

But you will also notice that the AVR standard library then says

c:\users\max\.platformio\packages\toolchain-atmelavr@1.70300.191015\avr\include\util\delay.h:112:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
 # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
   ^~~~~~~

in the compiler output, so the actual behavior will slightly differ – thus i’d recommend the standard -Og.

Thanks for the help but I am starting to believe my issues is that I am still running Window 7 and I can not upgrade python which could be some of my issue. The program was running great until it upgraded.

I don’t specfically see here whyWindows 7 or Python should be the culprit here though.

Are you able reproduce my findings on an Uno? (I do not have a Mega to test the other side).

Also, you can try and open a CLI and execute

pio upgrade --dev
pio platform update atmelavr

to make absolutely sure you’ve got the latest versions for the relevant things (core + platform).

Thanks you it’s working. I went and removed Visual Studio code then did a search for any folders or files on my computer that was VScode and PlatformIO and deleted all files and dlls. then I rebooted my computer and did a reinstall and it’s working Thanks for the help.