Unknown debug_tool `stlink`

Hi,
I tried to debug an STM32-WROOM.32U by the us of ST-LINK/V2 debugger. I think the connection is OK with four wires. The ini file in PlatformIO is this:

[env:esp32dev]
platform = espressif32@~5.0.0
board = esp32dev
framework = arduino
lib_deps = 
	adafruit/Adafruit INA219@^1.2.3
build_flags =
	-Wwrite-strings
debug_tool = stlink
debug_init_break = tbreak setup

I get the following error message:

Resolving esp32dev dependencies...
Already up-to-date.
Updating metadata for the vscode IDE...
UserSideException: Processing esp32dev (platform: espressif32@~5.0.0; board: esp32dev; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
DebugInvalidOptionsError: Unknown debug tool `stlink`. Please use one of `cmsis-dap, esp-bridge, 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` or `custom`:
  File "C:\Users\franz\.platformio\penv\Lib\site-packages\platformio\builder\main.py", line 173:
    env.SConscript("$BUILD_SCRIPT")
  File "C:\Users\franz\.platformio\packages\tool-scons\scons-local-4.8.1\SCons\Script\SConscript.py", line 620:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\franz\.platformio\packages\tool-scons\scons-local-4.8.1\SCons\Script\SConscript.py", line 280:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "C:\Users\franz\.platformio\platforms\espressif32@5.0.0\builder\main.py", line 283:
    target_elf = env.BuildProgram()
  File "C:\Users\franz\.platformio\packages\tool-scons\scons-local-4.8.1\SCons\Util\envs.py", line 252:
    return self.method(*nargs, **kwargs)
  File "C:\Users\franz\.platformio\penv\Lib\site-packages\platformio\builder\tools\piobuild.py", line 61:
    env.ProcessProgramDeps()
  File "C:\Users\franz\.platformio\packages\tool-scons\scons-local-4.8.1\SCons\Util\envs.py", line 252:
    return self.method(*nargs, **kwargs)
  File "C:\Users\franz\.platformio\penv\Lib\site-packages\platformio\builder\tools\piobuild.py", line 111:
    env.PrintConfiguration()
  File "C:\Users\franz\.platformio\packages\tool-scons\scons-local-4.8.1\SCons\Util\envs.py", line 252:
    return self.method(*nargs, **kwargs)
  File "C:\Users\franz\.platformio\penv\Lib\site-packages\platformio\builder\tools\pioplatform.py", line 233:
    _get_debug_data(),
  File "C:\Users\franz\.platformio\penv\Lib\site-packages\platformio\builder\tools\pioplatform.py", line 197:
    % board_config.get_debug_tool_name(env.GetProjectOption("debug_tool")),
  File "C:\Users\franz\.platformio\penv\Lib\site-packages\platformio\platform\board.py", line 126:
    raise DebugInvalidOptionsError(
========================== [FAILED] Took 3.03 seconds ==========================

The wiring is from here

Do anybody have any idea what should I do?
Thanks for your help!
Frank

So you’re connecting via JTAG (not SWD since it’s not an ARM chip) to the ESP32? I’ve never seen anyone use a ST-Link for that, usually an FTDI usb-to-jtag converter.

(FYI you can also double check the JTAG pins with the article https://medium.com/@manuel.bl/low-cost-esp32-in-circuit-debugging-dbbee39e508b).

Fundamentally, PlatformIO won’t let you use debug_tool = stlink because it’s not contained in the supported debug tools that are created here. You could modify this file locally as a test to include "stlink".

But, before that, test the connection with OpenOCD directly.

Open a new command terminal (Windows + R → cmd.exe). Then

cd C:\Users\franz\.platformio\packages\tool-openocd-esp32
bin\openocd.exe -s share\openocd\scripts -f interface/stlink.cfg -c "transport select dapdirect_jtag" -f target/esp32.cfg

What is the resulting output?

Never mind, ST-Link is stated as unsupported. DAPDirect JTAG likely only works against ARM targets, not XTensa.

https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/jtag-debugging/index.html#selecting-jtag-adapter

I dont have the

C:\Users\franz\.platformio\packages\tool-openocd-esp32

just have

C:\Users\franz\.platformio\packages\tool-openocd

it sends

C:\Users\franz\.platformio\packages\tool-openocd>bin\openocd.exe -s share\openocd\scripts -f interface/stlink.cfg -c "transport select dapdirect_jtag" -f target/esp32.cfg
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Error: Debug adapter doesn't support 'dapdirect_jtag' transport

Because no debugging session has ever been started successfully on your PC, PlatformIO hasn’t installed the tool-openocd-esp32 package yet.
You could trigger the installation with the CLI command

pio pkg install -g -t "tool-openocd-esp32"

But per above, trying to use an ST-Link with ESP32 is futile anyway.

I installed the package you advised.
Now the result of the command is lightly the same:

C:\Users\franz\.platformio\packages\tool-openocd-esp32>bin\openocd.exe -s share\openocd\scripts -f interface/stlink.cfg -c "transport select dapdirect_jtag" -f target/esp32.cfg
Open On-Chip Debugger v0.12.0-esp32-20230419 (2023-04-18-22:02)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Debug adapter doesn't support 'dapdirect_jtag' transport

What is your advise how could I debug a program on my ESP32-WROOM-U?

Oh, I think it should be stlink_jtag instead of dapdirect_jtag in accordance to this. Otherwise it will be on “SWD” by default instead of JTAG. Or also try just jtag or hla_jtag?

In any case, a known-working debugging setup is definitely with an ESP-PROG or an Adafruit FT232H device. The Medium article I linked to in my first post describes it exactly.

Note that modern versions of the ESP32, such as ESP32S3, C3 etc., have a builtin USB-JTAG controller that can be used for debugging, which the classical ESP32 does not have.