Using esp-builtin as the upload_protocol on ESP32-S3 boards

Has anyone had any luck using the esp-builtin as an upload protocol?

I am trying to find a way to seamlessly debug in PlatformIO. The normal debug process first starts openocd, then attempts to flash the firmware, however if we use “esptool” as the upload protocol it fails because openocd has already opened the /dev/ttyACM0 device for the JTAG interface.

If I flash the firmware normally using esptool, and then run the “Debug (without uploading)” I can get a functional debug session, but this adds an unnecessary step to the process.

My relevant platformio settegs are:

upload_protocol = esptool

upload_port = /dev/ttyACM0

debug_tool = esp-builtin

debug_port = :3333

build_type = debug

If you use upload_protocol = esptool with debug_tool = esp-builtin and it fails to debug in your config, then that’s a bug in https://github.com/platformio/platform-espressif32/issues/, file on there.

And just to confirm, when you have both upload_protocol = esp-builtin and debug_tool = esp-builtin it shows what error?

I have done some digging into this and I think I know what is happening, but I’m not sure where the error belongs:

When we tell platformio to upload the binary flash images it is invoked via the espressif builder python code:

./platforms/espressif32/builder/main.py

This ultimately calls the openocd libraries via a defined function called “program_esp” in esp_common.cfg

./packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg

When it invokes this call it pads the filename with braces:

963: “program_esp {{$SOURCE}} %s verify”

976: “program_esp {{%s}} %s verify”

I think this is to handle the case when a filename has spaces in it, although it only does it for the openocd case. For the other cases it just puts quotes around the filename.

The program_esp code then takes this file and adds quotes to it for the same reason - possible spaces in the filename.

407    echo "** program_esp input args <$args> **"
405
406    # Place quotes around the path in case it contains spaces
407    set filename "\"$filename\""

This has the effect of making the braces a part of the filename rather than a shell variable expansion.

adapter speed: 5000 kHz
** program_esp input args <0x10000 verify> **
** Programming Started **
You can enable skip_loaded to increase download speed.
Error: couldn’t open {.pio/build/octo/firmware.bin}
embedded:startup.tcl:1869: Error: ** Programming Failed **
Traceback (most recent call last):
File “/home/euan/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg”, line 534, in program_esp
program_error {** Programming Failed } 0
File “embedded:startup.tcl”, line 1869, in program_error
error {
Programming Failed **}
*** [upload] Error 1

If we remove either or both of these, then it works as expected.

adapter speed: 5000 kHz
** program_esp input args <0x10000 verify> **
** Programming Started **
You can enable skip_loaded to increase download speed.
** Programming Finished in 5552 ms **
** Verify Started **
** Verify OK **

Looking in the github repos, both of these have been in the code for several years, so I must assume it has never worked or I am doing something very wrong.

For reference, my platform version is fairly new from the pioarduino project:

platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.34/platform-espressif32.zip

If this is a path problem, post a minimal reproducable project (PlatformIO project + project path) to https://github.com/pioarduino/platform-espressif32/issues to get it handled.