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
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.
EDIT:
Just to clarify: it works for debugandupload, 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.
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