How to select builtin debug probe for multiple ESP S3?

Hi,

I connected 2 ESP32 S3 (via USB/JTAG port only) and select the active one with upload_port and monitor_port.
After a lot of confusion about which board got flashed and debugged I found out upload_port is not used for esp-builtin type?
So JTAG adapter is probably chosen by serial. But how?
I’m using linux, in case it is relevant.

For that, you first of all need the serial numbers for each connected ESPS3.

Disconnect all ESP32S3 boards execpt one. Then, by for example executing

cd "C:\Users\<user>\.platformio\packages\tool-openocd-esp32"
.\bin\openocd.exe -f "board/esp32s3-builtin.cfg" 

in a regular terminal, OpenOCD will try to connect and show you the serial number: (Here doing that for an ESP32C3)

Open 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
Warn : Transport "jtag" was already selected
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
Info : esp_usb_jtag: serial (34:B4:72:87:47:50)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
[..]

Then, OpenOCD can be told to only accept the adapter that matches this serial string by using e.g.

-c "adapter serial 34:B4:72:87:47:50"

as an additional command parameter.

Thus we can add to our platformio.ini

upload_flags =
  -c
  adapter serial 34:B4:72:87:47:50

E.g. full

[env:esp32-c3-devkitc-02]
platform = espressif32@6.9.0
board = esp32-c3-devkitc-02
framework = arduino
build_flags = 
  -D ARDUINO_USB_CDC_ON_BOOT=1 ; serial port via USB CDC
  -D ARDUINO_USB_MODE=1  ; hardware USB, no TinyUSB
upload_protocol = esp-builtin
debug_tool = esp-builtin
; only upload and debug ESP32 with specific serial
upload_flags =
  -c
  adapter serial 34:B4:72:87:47:50
1 Like

Sadly, this way debugging a specific ESP32S3 does not work. We would have to be able to inject a -c "adpater serial .." into the OpenOCD arguments, but there’s no way to configure it, and I also didn’t find a way to modify that with a script. :frowning:

So there, only opening an issue at Issues · platformio/platform-espressif32 · GitHub helps.

Also slightly related, but does not work for fixing debugging in this case:

Thanks for the upload solution!

Unfortunately this already works as I use an udev rule to setup a tty:

SUBSYSTEM=="tty", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="1001", ATTRS{serial}=="F4:12:FA:E9:93:60", MODE:="0660", GROUP:="dialout", SYMLINK+="ttyACM_s3_1_jtag" 

Any advantages over the udev solution?

I mean, except yours being project specific and not requiring root, which is already nice.

Opened issue How to select builtin debug probe for multiple ESP S3? · Issue #1490 · platformio/platform-espressif32 · GitHub

Thanks!

Hello together. If you provide a PR here I am happy to integrate this possibility

1 Like

I have a hack now that works for me: debug_speed can have a second token, which is the serial, like

debug_speed = 40000 F4:12:FA:CA:A4:B8

You can have a look in my fork of your pioarduino

EDIT:
Just to clarify: it works for debug and upload, upload_flags not needed.
Tested to accept correct serial and reject wrong serial for debug and flash. Without given serial it works as before: some kind of first come, first serve.

1 Like

Got the idea and it works. It is a hack since it hijacks the debug speed entry
Maybe I add a new entry in boards json for this.
How about debug_port?

1 Like

I think other platforms would benefit if the PlatformIO core added a debug_sernum / debug_id / debug_adapter_num or similiar in the base debug configuration. debug_port is already taken and might be interpreted by PlatformIO as “what GDB should connect to”, e.g., localhost:3333 (OpenOCD’s GDB server port), so debug_port should not be equal to the adapter’s serial number.

Thx Max for heads up not using my suggestion for the name. Honestly i doubt there will be changes done in Pio core for this. Overall I have the impression development is stalled at all… Don’t want to fork the core and modify “just” for this. This will be needed when actual espressif Tools and Toolchains are not in there registry. So going to add the debug port whatever name we find for in the espressif32 platform