Debugging with esp32s3 is not working

Hello all, First off There is no valid documentation on how to properly configure PlatformIO and Visual Studio Code to properly debug any ESP32 chip.

I have setup a simple Hello world project in Platformio using Visual Studio Code.

Here is the program:

#include <Arduino.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Hello World!");
  delay(1000);
}

Here is my Platformio.ini file

[env:esp32s3usbotg]

platform = espressif32

board = esp32s3usbotg

framework = arduino

debug_port = /dev/ttyACM1

debug_tool = esp-builtin

;debug_server = localhost:3333

upload_port = /dev/ttyACM0

build_flags = -v

debug_init_break = tbreak loop

build_type = debug

;lib_deps = arduino-libraries/WiFi@^1.2.7

monitor_speed = 9600

monitor_port = /dev/ttyUSB0

Here is my launch.json file:

"version": "0.2.0",
    "configurations": [
        {
            "name": "ESP32-S3 Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/binshift/Code/helloworld/.pio/build/esp32s3usbotg/firmware.elf",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "PlatformIO: Build",
            "miDebuggerPath": "/home/binshift/.espressif/tools/xtensa-esp-elf-gdb/12.1_20231023/xtensa-esp-elf-gdb/bin/xtensa-esp32s3-elf-gdb",
            "miDebuggerArgs": "--interpreter=mi2",
            "miDebuggerServerAddress": "127.0.0.1:3333"
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug",
            "executable": "/home/binshift/Code/helloworld/.pio/build/esp32s3usbotg/firmware.elf",
            "projectEnvName": "esp32s3usbotg",
            "toolchainBinDir": "/home/binshift/.platformio/packages/toolchain-xtensa-esp32s3/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "preLaunchTask": {
                "type": "PlatformIO",
                "task": "Pre-Debug"
            }
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (skip Pre-Debug)",
            "executable": "/home/binshift/Code/helloworld/.pio/build/esp32s3usbotg/firmware.elf",
            "projectEnvName": "esp32s3usbotg",
            "toolchainBinDir": "/home/binshift/.platformio/packages/toolchain-xtensa-esp32s3/bin",
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (without uploading)",
            "executable": "/home/binshift/Code/helloworld/.pio/build/esp32s3usbotg/firmware.elf",
            "projectEnvName": "esp32s3usbotg",
            "toolchainBinDir": "/home/binshift/.platformio/packages/toolchain-xtensa-esp32s3/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "loadMode": "manual"
        }

I have tried to debug using PIO Debug:
I get the error:

ndefinedOpen On-Chip Debugger  v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
adapter speed: 40000 kHz
Warn : Transport "jtag" was already selected
adapter speed: 5000 kHz

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : esp_usb_jtag: serial (F4:12:FA:CE:ED:C4)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 5000 kHz
Info : JTAG tap: esp32s3.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32s3.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : starting gdb server for esp32s3.cpu0 on 3333
Info : Listening on port 3333 for gdb connections
Reading symbols from /home/binshift/Code/helloworld/.pio/build/esp32s3usbotg/firmware.elf...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = esp-builtin
PlatformIO: Initializing remote target...
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Ignoring packet error, continuing...

I was told by the CLion support staff that this error is related to not using xtensa-esp32s3-elf-gdb
I am also testing this same code using CLion with Platformio.
As indicated above I then created the launch.jsom for xtensa-esp32s3-elf-gdb
for both PlatformIo in Visual Studio Code and Clion.

I get the following error:

Unable to start debugging . Unexpected GDB output from command "-targer-select remote 127.0.0.1:3333". 127.0.0.1:3333: Connection timed out

I am not the first person to complain about not getting the debugger to work and I have yet to see any given resolution on a working solution.

The Arduino IDE team has been working on their debugger for over two years without a solution either.

It would be nice to have a workable debugger solution.

Thanks

Delete that. It’s going over the USB device, not over a serial port. (https://github.com/platformio/platform-espressif32/issues/1220#issuecomment-1785870252)

Hi Everyone.

Well, I’m here again with this topic. The last year I had full amazing debugging with PlatformIO and an ESP32S3 TTGO T7S3 board, without any configuration, and any extra JTAG hardware. But today I was trying to do the same, but nothing, impossible. I added more extra config to my Pio ini file, but nothing. One year ago, I didn’t to add nothing, and was working like a charm :roll_eyes:

The error:

PlatformIO Unified Debugger → 

PlatformIO: debug_tool = esp-builtin
PlatformIO: Initializing remote target…
Open On-Chip Debugger  v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read

invalid command name “gdb”
.pioinit:11: Error in sourced command file:
Remote communication error.  Target disconnected.: Connection reset by peer.

My config:

[esp32s3_common]
extends = oled_common
platform = espressif32 @ 6.9.0
board = esp32-s3-devkitc-1
; debug_tool = esp-builtin
; upload_protocol = esp-builtin
; debug_openocd_scripts = board/esp32s3-builtin.cfg
; debug_port = /dev/ttyACM0
; debug_init_break = break setup
; debug_extra_cmds =
build_flags = 
  ${common.build_flags}
  -D ARDUINO_USB_CDC_ON_BOOT=1
  -D BOARD_HAS_PSRAM=1

[env:TTGO_T7S3]
extends = esp32s3_common
board = lilygo_t7s3
build_flags =
  ${common.build_flags}
  -D ARDUINO_USB_CDC_ON_BOOT=1

And my OPENOCD seems that is working:

$OPENOCD_PATH -f board/esp32s3-builtin.cfg -c "init; halt; exit"
Open On-Chip Debugger v0.12.0-esp32-20260424 (2026-04-24-15:13)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
Info : esp_usb_jtag: serial (34:85:18:8D:7F:64)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 40000 kHz
Info : JTAG tap: esp32s3.tap0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32s3.tap1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : [esp32s3.cpu0] Examination succeed
Info : [esp32s3.cpu1] Examination succeed
Info : [esp32s3.cpu0] starting gdb server on 3333
Info : Listening on port 3333 for gdb connections
Info : [esp32s3.cpu0] Debug controller was reset.
Info : [esp32s3.cpu0] Core was reset.
Info : [esp32s3.cpu0] Target halted, PC=0x42135F16, debug_reason=00000000
Info : Set GDB target to 'esp32s3.cpu0'
Info : [esp32s3.cpu1] Debug controller was reset.
Info : [esp32s3.cpu1] Core was reset.
Info : [esp32s3.cpu1] Target halted, PC=0x403865B1, debug_reason=00000000
Info : [esp32s3.cpu1] Reset cause (1) - (Power on reset)
Info : [esp32s3.cpu1] Chip revision v0.1
Warn : DEPRECATED: 'exit' should only be used in telnet or Tcl sessions to close the session
Warn : Did you mean 'shutdown'?

Thanks in advance for any help.

I don’t know how I fixed it, but I did some things and now is working again. Maybe was:

  • I removed the complete .platformio installation directory
  • I configured to last version of Espressif platform, without any specific version (target latest)

like this:

[env]
build_type = debug              ; <== THIS IS IMPORTANT
framework = arduino
upload_speed = 1500000
monitor_speed = 115200
monitor_filters = 
  esp32_exception_decoder
  time

[env:TTGO_T7S3]
platform = espressif32       ; <== THIS IS IMPORTANT (With 6.9.0 the debugger fails)
board = lilygo_t7s3
build_flags =
  ${common.build_flags}
  -D ARDUINO_USB_CDC_ON_BOOT=1