Debugging ESP32 with JLINK

Hello everyone

I am working on an ESP32 project and want to debug it with a JLINK EDU. Previously I have worked with STM32 via the SWD and JTAG interface and it has always worked like a charm. I was able to program and debug the STM32s via the JLINK commandline interface but also with PlatformIO.

I work with a Windows 11 PC and have changed the drivers for the JLINK with Zadig to the WinUSB as recommended on the Internet. I suspect that there is a problem with Windows 11 or my drivers, so I hope that someone has already found a solution.

2022-07-02_09h49_04
2022-07-02_09h49_17

I am trying to load an empty sketch:

#include <Arduino.h>

void setup()
{
    // put your setup code here, to run once:
}

void loop()
{
    // put your main code here, to run repeatedly:
}

And I use the following settings for it:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
debug_tool = jlink
upload_protocol = jlink

When I click on upload I get the following output:

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.5.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (jlink) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.10006.210326 (1.0.6) 
 - tool-esptoolpy @ 1.30100.210531 (3.1.0) 
 - tool-mkspiffs @ 2.230.0 (2.30) 
 - tool-openocd-esp32 @ 2.1000.20210721 (10.0) 
 - toolchain-xtensa32 @ 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 28 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.0% (used 13224 bytes from 327680 bytes)
Flash: [==        ]  15.4% (used 201216 bytes from 1310720 bytes)
Configuring upload protocol...
AVAILABLE: esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = jlink
Uploading .pio\build\esp32dev\firmware.bin
Open On-Chip Debugger  v0.10.0-esp32-20210721 (2021-07-21-13:35)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.
adapter speed: 5000 kHz

Warn : Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED.
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
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
Error: Couldn't halt target before SoC reset
embedded:startup.tcl:449: Error: ** Unable to reset target **
in procedure 'program_esp'
in procedure 'program_error' called at file "C:/Users/geiss/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 93
at file "embedded:startup.tcl", line 449
*** [upload] Error 1
==================================================================================================================================== [FAILED] Took 2.31 seconds ====================================================================================================================================
The terminal process "C:\Users\geiss\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

I don’t think you have to replace the drivers for the Serial USB though.

Usually this means wrong cabeling or debug speed to high. Given the ESP32’s JTAG pins at https://medium.com/@manuel.bl/low-cost-esp32-in-circuit-debugging-dbbee39e508b (GPIO 12 to 15), how do you connect them to the JLink? Have you connected GND and VTRef (=3.3V) too?

Thanks for the quick reply!
Did I understand correctly, I only have to replace the driver of Interface 2 with the WinUSB?

As a template for the wiring I have used the following picture from the PlatformIO documentation: