Cannot debug esp32

When I try to debug my esp32-ethernet-kit v1.2 board through PlatformIO on VSCode, I will get errror messages like “.pioinit:13: Error in sourced command file: Remote communication error. Target disconnected.: Success.”

I tried to execute the following command:

C:\Users\rui\.platformio\packages\tool-openocd-esp32>bin\openocd.exe -s C:\Users\rui\.platformio\packages\tool-openocd-esp32\share\openocd\scripts -f interface\ftdi\esp32_devkitj_v1.cfg -f board\esp32-wrover.cfg

And here is the result message

Open On-Chip Debugger  v0.10.0-esp32-20190708 (2019-07-08-11:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
none separate
adapter speed: 20000 kHz
Info : Configured 2 cores
esp32 interrupt mask on
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : ftdi: if you experience problems at higher adapter clocks, try the command     "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : Listening on port 3333 for gdb connections
Info : esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x400E6552 (active)    APP_CPU: PC=0x401B67A6
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Polling target esp32 failed, trying to reexamine
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Examination failed, GDB will be halted. Polling again in 100ms
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Polling target esp32 failed, trying to reexamine
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Examination failed, GDB will be halted. Polling again in 300ms
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Polling target esp32 failed, trying to reexamine
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Examination failed, GDB will be halted. Polling again in 700ms
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Polling target esp32 failed, trying to reexamine
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Examination failed, GDB will be halted. Polling again in 1500ms
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Polling target esp32 failed, trying to reexamine
Error: libusb_handle_events() failed with LIBUSB_ERROR_IO
Error: unable to purge ftdi rx buffers: LIBUSB_ERROR_IO
Error: error while flushing MPSSE queue: -4
Examination failed, GDB will be halted. Polling again in 3100ms

Below is my previous post, in which the errors are different from what I’m getting now.

Can't debug with esp32 - #8 by heiseiggg

Anyone have an idea of what’s going on? Thanks

Very strange. The log indicates that the debugger can initially communicate with the FTDI chip and the ESP32 chip but it then quickly fails. And the problem looks to be between OpenOCD and the FTDI chip.

Have you tried it with a super simple program like one blinking an LED?

Also try a different USB cable and a different USB port on your computer.

Something fishy is going on in the USB adapter. You are powering the target ESP board separately from the debug probe right? The debug probe probably can’t power it on it’s own… Also try another USB port as Manuel said. Further, there are adapter speed settings which can influence stability. See topic ESP32 + J-link debugger does not start - #12 by Yourigh.

Hi, it seems that there is something wrong with the USB port on my PC case so I switched to the port on the motherboard and now it will not throw error when I execute this command

bin\openocd.exe -s C:\Users\username\.platformio\packages\tool-openocd-esp32\share\openocd\scripts -f interface\ftdi\esp32_devkitj_v1.cfg -f board\esp32-wrover.cfg

The log is as follows

Open On-Chip Debugger  v0.10.0-esp32-20190708 (2019-07-08-11:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
none separate
adapter speed: 20000 kHz
Info : Configured 2 cores
esp32 interrupt mask on
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
Info : Listening on port 3333 for gdb connections

However when I try to debug with PlatformIO I will get Failed to launch GDB: .pioinit: 13 Target disconnected.: Not a directory error. And there are a lot of “xtensa_poll: Target failure” in terminal.
Now if I execute the above command after failing to debug in platformio I will get this:

Open On-Chip Debugger  v0.10.0-esp32-20190708 (2019-07-08-11:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
none separate
adapter speed: 20000 kHz
Info : Configured 2 cores
esp32 interrupt mask on
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway...
Error: esp32.cpu0: IR capture error; saw 0x1f not 0x01
Warn : Bypassing JTAG setup events due to errors
Info : Listening on port 3333 for gdb connections

Is there something wrong with my platformio project configuration?

This is now a problem between the FTDI and the ESP32 chip. As you can’t possibly incorrectly wire the two chips given your board, you should try to lower the speed (edit adapter_khz 20000 in esp32-wrover.cfg).

BTW: It should be possible to start the debugger from Visual Studio Code (instead from the command line). The details errors will be visible in the DEBUG CONSOLE view.

Actually I am starting the debugger from VSCode. I’ve tried different speed like 10000kHz, 5000kHz and 3000kHz but it just doesn’t work. Here is the messages I get in debug console:

PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = ftdi
PlatformIO: Initializing remote target...
Open On-Chip Debugger  v0.10.0-esp32-20190708 (2019-07-08-11:04)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
none separate
adapter speed: 3000 kHz
Info : Configured 2 cores
esp32 interrupt mask on
Info : tcl server disabled
Info : telnet server disabled
Info : clock speed 3000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x0F).
Info : accepting 'gdb' connection from pipe
Error: No symbols for FreeRTOS
Info : Target halted. PRO_CPU: PC=0x400E2912 (active)    APP_CPU: PC=0x400E2912
Info : Target halted. PRO_CPU: PC=0x400916EE (active)    APP_CPU: PC=0x400E2912
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 22 KB
Info : Flash mapping 1: 0x20020 -> 0x400d0020, 75 KB
Info : Target halted. PRO_CPU: PC=0x400916EE (active)    APP_CPU: PC=0x400E2912
Info : Auto-detected flash size 4096 KB
Info : Using flash size 4096 KB
Info : Target halted. PRO_CPU: PC=0x400916EE (active)    APP_CPU: PC=0x400E2912
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 22 KB
Info : Flash mapping 1: 0x20020 -> 0x400d0020, 75 KB
Info : Using flash size 76 KB
Info : Target halted. PRO_CPU: PC=0x400916EE (active)    APP_CPU: PC=0x400E2912
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 22 KB
Info : Flash mapping 1: 0x20020 -> 0x400d0020, 75 KB
Info : Using flash size 24 KB
0x400e2912 in esp_pm_impl_waiti () at C:\Users\rui\.platformio\packages\framework-espidf\components\esp32\pm_esp32.c:484
484	    asm("waiti 0");
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Error: cpu0: xtensa_write_memory (line 807): DSR (FFFFFFFF) indicates target still busy!
Error: cpu0: xtensa_write_memory (line 807): DSR (FFFFFFFF) indicates DIR instruction generated an exception!
Error: cpu0: xtensa_write_memory (line 807): DSR (FFFFFFFF) indicates DIR instruction generated an overrun!
Warn : esp32: Failed writing 4 bytes at address 0x3ff48000, data - 00, 20, 49, 9c, 4c, 00, 00, 00
cpu0: xtensa_write_memory (line 807): DSR (FFFFFFFF) indicates target still busy!
cpu0: xtensa_write_memory (line 807): DSR (FFFFFFFF) indicates DIR instruction generated an exception!
Error: xtensa_write_uint32_list: error writing to 3ff48000
Warn : esp32_soc_reset xtensa_write_uint32_list (reg_value_pairs_pre) err=-4
in procedure 'program_esp32'

cpu0: xtensa_write_memory (line 807): DSR (FFFFFFFF) indicates DIR instruction generated an overrun!
esp32: Failed writing 4 bytes at address 0x3ff48000, data - 00, 20, 49, 9c, 4c, 00, 00, 00
embedded:startup.tcl:480: Error: ** Unable to reset target **
in procedure 'program_esp32'
    in procedure 'program_error' called at file "C:/Users/rui/.platformio/packages/tool-openocd-esp32/share/openocd/scripts//target/esp32.cfg", line 119
at file "embedded:startup.tcl", line 480
xtensa_write_uint32_list: error writing to 3ff48000
esp32_soc_reset xtensa_write_uint32_list (reg_value_pairs_pre) err=-4
in procedure 'program_esp32'

Info : xtensa_poll: Target offline
Error: xtensa_poll: Target failure
Polling target esp32 failed, trying to reexamine
embedded:startup.tcl:480: Error: ** Unable to reset target **
in procedure 'program_esp32'
in procedure 'program_error' called at file "C:/Users/rui/.platformio/packages/tool-openocd-esp32/share/openocd/scripts//target/esp32.cfg", line 119
at file "embedded:startup.tcl", line 480
xtensa_poll: Target offline
xtensa_poll: Target failure
Examination failed, GDB will be halted. Polling again in 100ms
Polling target esp32 failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
Error: xtensa_poll: Target failure
Polling target esp32 failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 300ms
xtensa_poll: Target failure
Polling target esp32 failed, trying to reexamine
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway...
Examination failed, GDB will be halted. Polling again in 300ms
Error: esp32.cpu0: IR capture error; saw 0x1f not 0x01
JTAG scan chain interrogation failed: all ones
Warn : Bypassing JTAG setup events due to errors
Check JTAG interface, timings, target power, etc.
Trying to use configured scan chain anyway...
esp32.cpu0: IR capture error; saw 0x1f not 0x01
Bypassing JTAG setup events due to errors
Error: xtensa_poll: Target failure
Error: xtensa_poll: Target failure
Error: xtensa_poll: Target failure
Error: xtensa_poll: Target failure
Error: xtensa_poll: Target failure
xtensa_poll: Target failure
xtensa_poll: Target failure
Error: xtensa_poll: Target failure
xtensa_poll: Target failure
xtensa_poll: Target failure
xtensa_poll: Target failure
xtensa_poll: Target failure

According to Tips and Quirks - ESP32 - — ESP-IDF Programming Guide latest documentation, these errors indicate that JTAG is being disturbed. But I’m not using those pins in my program. Here is the main.c code

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#define BLINK_GPIO 5
void app_main() {
    gpio_pad_select_gpio(BLINK_GPIO);
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
    while(1) {
        printf("Turning off the LED\n");
        gpio_set_level(BLINK_GPIO, 0);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        printf("Turning on the LED\n");
        gpio_set_level(BLINK_GPIO, 1);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

Could there be any place that will interfere with the pin configuration?

When you start debugging with VSCode, you must not have any other OpenOCD servers open, otherwise it’s probably a conflict between two openocd instances. Executing the command with bin\openocd.exe was just a test to see if OpenOCD can in general connect to the target. Execution of openocd can be stopped by pressing Ctrl+C in the cmd window or closing it.

Can you retry starting debugging with no other openocd instance running?

Hi, @maxgerhardt, I’m sure I’ve terminated any other OpenOCD before I start debugging with VSCode.

Well I can only think of a few more things:

  1. When modifying the adapter speed make sure to modify the esp32-wrover.cfg, the linked topic refers to a different file because it has a different target board
  2. In the esp32-wrover.cfg, there are settings for the target flash voltage (either 1.8V or 3.3V). If I read openocd-esp32/esp32-ethernet-kit-3.3v.cfg at master · espressif/openocd-esp32 · GitHub correctly, this board needs the 3.3V config. Make sure the file is configured as in JTAG-Debugging with ESP32-WROOM-32UE - #4 by maxgerhardt.
  3. Re-Check all wires for good continuity and shortness, or replace them with new ones. Usually reading only 1’s (as in 0xFFFFFFFF) on a JTAG line indicates a bad connection (or too high adapter speed)
  4. It might just be that the tool-openocd-esp32 needs an update (latest files found in GitHub - espressif/openocd-esp32: OpenOCD branch with ESP32 JTAG support). For a test, these files can be locally replaced (in C:\Users\<user>\packages\tool-openocd-esp32. Then one can also directly make use of the new openocd config for the board by using board_debug.openocd_board = esp32-ethernet-kit-3.3v.cfg in the platformio.ini. But let’s try the above things first.

I replaced the OpenOCD with the latest version and it is working. Thank you @maxgerhardt for so much help.

Oh that was fast. Do you have the board_debug.openocd_board setting in the platformio.ini or does it work without it?

No, my platformio.ini is pretty simple.

[env:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
framework = espidf
; upload_port = com6
upload_speed = 115200
monitor_speed = 115200