Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32-S3 USB Usage #8237

Closed
1 task done
frankcohen opened this issue May 22, 2023 · 65 comments
Closed
1 task done

ESP32-S3 USB Usage #8237

frankcohen opened this issue May 22, 2023 · 65 comments
Assignees
Labels
Type: Documentation Issue pertains to Documentation of Arduino ESP32 Type: For reference Common questions & problems Type: Question Only question

Comments

@frankcohen
Copy link

Board

Reflections ESP32-S3-Mini custom board, similar to Adafruit Feather S3

Device Description

I'm building an ESP32-based wrist watch to show movies of my kids. It's an open-source platform (https://github.com/frankcohen/ReflectionsOS). I'm using the built-in USB support in ESP32-S3 and building code using Arduino IDE 2.1.0. I haven't written my own board definition yet, so I'm using the Adafruit Feather ESP32-S3 No PSRAM board.
screenshot_8048

Hardware Configuration

USB port is connected to the normal ESP32-S3 pins for communication, power, and reset.

Version

v2.0.9

IDE Name

Arduino IDE 2.1.0

Operating System

MacOS 13.3.1 (Ventura)

Flash frequency

80 Mhz

PSRAM enabled

no

Upload speed

921600

Description

Most of the time I have to go through these steps to get the board to accept a new code upload:

  • Hold Boot down, press and release Reset (Reset is closer USB port)
  • From pop-up "Select other board and port", choose Adafruit Feather ESP32-S3 No PSRAM and USB port
  • Upload
  • Press Boot, then press Reset
  • Re-open the Serial Monitor

esptool.py reports "Hard resetting via RTS pin..." yet I need to press Boot, then press Reset to get the sketch to run. Espressif appears aware of this problem and has no solution yet. #6762

CDC support is incompatible with TinyUSB. That doesn't bother me yet. I'm expecting I will soon enable Over The Air OTA uploads and will use USB only for providing power.

I'd like to move on to Platform.IO and JTAG debugging. That just seems like another can of worms. The Platform.IO interface seems confusing to me, and I'm thinking I'll have the same USB problems.

What are you using? Am I missing something?

-Frank

Sketch

#include <Arduino.h>

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  long time = millis();
  while (!Serial && ( millis() < time + 5000) ); // wait up to 5 seconds for Arduino Serial Monitor  
  delay(2000);
  Serial.println(" ");
  Serial.println("Test");

}

int i = 0;

void loop() {
  Serial.println( i++ );
  delay(500);
}

Debug Message

Sketch uses 359541 bytes (17%) of program storage space. Maximum is 2097152 bytes.
Global variables use 43028 bytes (13%) of dynamic memory, leaving 284652 bytes for local variables. Maximum is 327680 bytes.
Performing 1200-bps touch reset on serial port /dev/cu.usbmodem14301
Waiting for upload port...
No upload port found, using /dev/cu.usbmodem14301 as fallback
"/Users/frankcohen/Library/Arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool" --chip esp32s3 --port "/dev/cu.usbmodem14301" --baud 921600  --before default_reset --after hard_reset write_flash  -z --flash_mode dio --flash_freq 80m --flash_size 8MB 0x0 "/private/var/folders/8y/z6t4zfcs2611ddcwsm1cg1080000gn/T/arduino/sketches/D4A47B7A0DB94325FA4038B7D88EA811/AccelGestureDTW.ino.bootloader.bin" 0x8000 "/private/var/folders/8y/z6t4zfcs2611ddcwsm1cg1080000gn/T/arduino/sketches/D4A47B7A0DB94325FA4038B7D88EA811/AccelGestureDTW.ino.partitions.bin" 0xe000 "/Users/frankcohen/Library/Arduino15/packages/esp32/hardware/esp32/2.0.9/tools/partitions/boot_app0.bin" 0x10000 "/private/var/folders/8y/z6t4zfcs2611ddcwsm1cg1080000gn/T/arduino/sketches/D4A47B7A0DB94325FA4038B7D88EA811/AccelGestureDTW.ino.bin" 0x410000 "/Users/frankcohen/Library/Arduino15/packages/esp32/hardware/esp32/2.0.9/variants/adafruit_feather_esp32s3_nopsram/tinyuf2.bin"
esptool.py v4.5.1
Serial port /dev/cu.usbmodem14301
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 60:55:f9:f5:7e:14
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00067fff...
Flash will be erased from 0x00410000 to 0x00438fff...
Compressed 22624 bytes to 14245...
Writing at 0x00000000... (100 %)
Wrote 22624 bytes (14245 compressed) at 0x00000000 in 0.4 seconds (effective 417.7 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 136...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (136 compressed) at 0x00008000 in 0.1 seconds (effective 487.2 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 638.0 kbit/s)...
Hash of data verified.
Compressed 359904 bytes to 209872...
Writing at 0x00010000... (7 %)
Writing at 0x0001a3be... (15 %)
Writing at 0x0002740f... (23 %)
Writing at 0x0002ca1b... (30 %)
Writing at 0x000327c2... (38 %)
Writing at 0x0003818e... (46 %)
Writing at 0x0003d919... (53 %)
Writing at 0x00042ed4... (61 %)
Writing at 0x00047f74... (69 %)
Writing at 0x0004d21a... (76 %)
Writing at 0x00052749... (84 %)
Writing at 0x0005ac36... (92 %)
Writing at 0x000634e7... (100 %)
Wrote 359904 bytes (209872 compressed) at 0x00010000 in 3.9 seconds (effective 744.8 kbit/s)...
Hash of data verified.
Compressed 165536 bytes to 106746...
Writing at 0x00410000... (14 %)
Writing at 0x00418667... (28 %)
Writing at 0x0041dbce... (42 %)
Writing at 0x0042459a... (57 %)
Writing at 0x0042a572... (71 %)
Writing at 0x0042feab... (85 %)
Writing at 0x004352c0... (100 %)
Wrote 165536 bytes (106746 compressed) at 0x00410000 in 1.9 seconds (effective 686.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Other Steps to Reproduce

I also tried to run esptool.py directly, same result... the cannot get a response from the ESP32-S3.

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@frankcohen frankcohen added the Status: Awaiting triage Issue is waiting for triage label May 22, 2023
@me-no-dev
Copy link
Member

You are using the OTG USB peripheral, instead of the integrated CDC+JTAG. That port can not reset from download mode. If you do not need the USB for things other than serial port and JTAG, I suggest you switch to use that mode. You can also use the ESP32-S3 Dev Board definition, because it offers all options and does not use a custom bootloaders, etc., like the Adafruit boards. They are mostly meant to be used with MSC UF2 (drop a file in a USB storage device)

@VojtechBartoska VojtechBartoska added Type: Question Only question and removed Status: Awaiting triage Issue is waiting for triage labels May 22, 2023
@mrengineer7777 mrengineer7777 added the Type: For reference Common questions & problems label May 22, 2023
@frankcohen
Copy link
Author

frankcohen commented May 24, 2023

Thanks for the reply @me-no-dev. I received an ESP32-S3-DevKitM-1 board. I connect it to my Mac Book Pro over USB, and not the UART. I select ESP32-S3-USB-OTG and the port. Yet, I cannot get the board to upload code. I get an error. Here is the behavior I see in Arduino IDE 2.1:

Sketch uses 258301 bytes (19%) of program storage space. Maximum is 1310720 bytes.
Global variables use 19496 bytes (5%) of dynamic memory, leaving 308184 bytes for local variables. Maximum is 327680 bytes.
Performing 1200-bps touch reset on serial port /dev/cu.usbmodem1234561
Waiting for upload port...
No upload port found, using /dev/cu.usbmodem1234561 as fallback
"/Users/frankcohen/Library/Arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool" --chip esp32s3 --port "/dev/cu.usbmodem1234561" --baud 921600  --before default_reset --after hard_reset write_flash  -z --flash_mode dio --flash_freq 80m --flash_size 8MB 0x0 "/private/var/folders/8y/z6t4zfcs2611ddcwsm1cg1080000gn/T/arduino/sketches/7E6873437A0CB0B0CF5921C73E32951B/sketch_may21a.ino.bootloader.bin" 0x8000 "/private/var/folders/8y/z6t4zfcs2611ddcwsm1cg1080000gn/T/arduino/sketches/7E6873437A0CB0B0CF5921C73E32951B/sketch_may21a.ino.partitions.bin" 0xe000 "/Users/frankcohen/Library/Arduino15/packages/esp32/hardware/esp32/2.0.9/tools/partitions/boot_app0.bin" 0x10000 "/private/var/folders/8y/z6t4zfcs2611ddcwsm1cg1080000gn/T/arduino/sketches/7E6873437A0CB0B0CF5921C73E32951B/sketch_may21a.ino.bin" 
esptool.py v4.5.1
Serial port /dev/cu.usbmodem1234561
Connecting......................................

A fatal error occurred: Failed to connect to ESP32-S3: No serial data received.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
Failed uploading: uploading error: exit status 2

I see this in the Serial monitor:

�[0;32mI (2121188) example: log -> USB�[0m
example: print -> stdout
example: print -> stderr
�[0;32mI (2122688) example: log -> USB�[0m
example: print -> stdout
example: print -> stderr
�[0;32mI (2124188) example: log -> USB�[0m
example: print -> stdout
example: print -> stderr

How do I upload a sketch and let it run without pressing buttons?

-Frank

@dsilletti
Copy link

dsilletti commented May 24, 2023

please follow this guide, for the 1st upload you must put the board in DFU mode manually, the it will put the device in DFU, upload and reset the board automatically using the embedded USB controller in the ESP32-S3 https://www.hackster.io/hanguyen92205/program-debug-esp32s3-via-usb-serial-onchip-with-arduino-eeead3

@mrengineer7777 mrengineer7777 added the Type: Documentation Issue pertains to Documentation of Arduino ESP32 label May 25, 2023
@SuGlider
Copy link
Collaborator

@frankcohen - In order to make the S3 work seamless for uploading and reseting the board after uploading, please use the USB HW (JTAG/CDC) configuration. It can be selected in the IDE Menu:

USB Mode ==> Hardware CDC and JTAG
USB CDC On Boot ==> Enabled
Upload Mode ==> UART0 / Hardware CDC

Upload any sketch to activate it for the next time.
Serial will work in the USB CDC port of the board.
Serial0 is UART 0, Serial 1 is UART 1 and so on.

image

@frankcohen
Copy link
Author

frankcohen commented May 26, 2023 via email

@SuGlider
Copy link
Collaborator

@frankcohen - The ESP32-S3 doesn't need the ESP-PROG because it already has the JTAG USB.
Please follow the instructions that can be found in the documentation:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/jtag-debugging/index.html
https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/jtag-debugging/configure-builtin-jtag.html

As for the new IDE 2.1.0, it is necessary to:

  1. Select the ESP32-S3 DevKit board
  2. Select the USB port
  3. Enable CDC on Boot (IDE Board Menu)
  4. Select "Upload Mode" as "UART0 / Hardware CDC"
  5. Select "USB Mode" as "Hardware CDC and JTAG"
  6. Select "JTAG Adapter" as "Integrated USB JTAG"
  7. Select and load the Sketch that will be debugged
  8. Build and Upload it
  9. Press the Debug "play" button to open the DEBUG window
  10. Press the Green "play" button and wait for OpenOCD and dbg to start in the "Debug Console"
  11. Add the BREAKPOINTS
  12. Use the DEBUG UI as desired

Some Images of my IDE may help:

Menu Options:
image

Screenshot of the Debugger in Action:
image

@SuGlider
Copy link
Collaborator

@frankcohen - I hope that the ESP32-S3 USB stops frustrating you now. Let me know.

@sblantipodi
Copy link
Contributor

@SuGlider ESP32-S3 USB works really bad...
it destroyed the usability with tools like ESP Web Tools.

@SuGlider
Copy link
Collaborator

@SuGlider ESP32-S3 USB works really bad... it destroyed the usability with tools like ESP Web Tools.

I'll test the Web USB uploading.
Beside it, could you use the USB JTAG as uploading port, like as with a plain UART?
Did it work as JTAG debugging tool within the Arduino IDE?
All this information will help the community and also will be used as base for a future FAQ about the S3.

@SuGlider
Copy link
Collaborator

@frankcohen - About ESP Web Tools:

  1. I can select the USB JTAG port and connect to the S3, seeing the logs, including debug log messages (see screenshots)
    image
    image

  2. I can also reset the device from the ESP Web Tools:
    image

  3. I also can't upload Tasmota for the S3 using their ESP WEB TOOL.
    image

When using the USB JTAG port, I see that it can't detect correctly the device.
This can be an issue with the TS scripts...

  1. By other hand, I can use the same USB JTAG to upload a C3, which uses exactly the same digital design for this USB port from the S3. I have used an Espressif Tool: https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-matter/launchpad.toml

image

@SuGlider
Copy link
Collaborator

@SuGlider ESP32-S3 USB works really bad... it destroyed the usability with tools like ESP Web Tools.

It seems that ESP Home Web Tools may need some patches to work in the same way that Espressif Launchpad does in order to be able to upload using the USB JTAG port.

@sblantipodi
Copy link
Contributor

sblantipodi commented May 26, 2023

@SuGlider to be able to upload using USB JTAG you need to do the following:
press the "0" button,
keep it pressed,
press "RST" you hear a sound from windows,
release "RST", you need to hear another sound from windows so don't do it too fast,
reload the web flasher page,
then select the flash procedure,
select com port, etc. and when it is showing the progress meter with at least a few % you can release the "0" button.

This works on S3 and C3. Does not work on S2.

When using TinyUSB (that it's obviously far better for our firmwares) the procedure is even more tricky...

@SuGlider
Copy link
Collaborator

I see, but as I could verify, Espressif Lauchpad (Web Uploading) does something different that works with no button pressing.
I think that the team from ESP Web Tool could check it out and try to implement something similar there.

https://github.com/espressif/esp-launchpad

@sblantipodi
Copy link
Contributor

@SuGlider esp launchpad does not see TinyUSB devices at all...
if I put the ESP in CDC mode it does not connect on my S2.

image

@SuGlider
Copy link
Collaborator

Yes, there is a problem with TinyUSB (S2 and S3). Something to investigate...
Anyway, I think we have covered the S3 + USB JTAG pretty well.

@SuGlider
Copy link
Collaborator

@SuGlider to be able to upload using USB JTAG you need to do the following: press the "0" button, keep it pressed, press "RST" you hear a sound from windows, release "RST", you need to hear another sound from windows so don't do it too fast, reload the web flasher page, then select the flash procedure, select com port, etc. and when it is showing the progress meter with at least a few % you can release the "0" button.

This works on S3 and C3. Does not work on S2.

When using TinyUSB (that it's obviously far better for our firmwares) the procedure is even more tricky...

Please try this other web site:
https://espressif.github.io/esp-launchpad/?flashConfigURL=https://espressif.github.io/esp-matter/launchpad.toml

It can connect to the USB JTAG from the S3 with no issues and no need for pressing buttons.
When flashing, the tool seems to do not test the ChipID and therefore it tries to flash a wrong firmaware into the S3.

@SuGlider
Copy link
Collaborator

SuGlider commented May 26, 2023

Another importante detail: In order to make USB JTAG upload and reset automatially, it is necessary to upload a first sketch with the USB JTAG/CDC configuration as defines in #8237 (comment)

After uploading this (any) first sketch, the S3 will work exactly as when it uses the UART for uploading. Also after it, the process of uploading with WEB USB as described above will work. The same for the JTAG debugging.

In other words, it is necessary to activate the USB JTAG/CDC prior to using it with the Arduino IDE or with Web USB Flashing.

@frankcohen
Copy link
Author

frankcohen commented May 26, 2023 via email

@frankcohen
Copy link
Author

Seems that Github doesn't like embedded images from email. Here is my messsage again.

This is great and thank you. Now I’m wondering about cables. Reading the docs you reference I see these ESP pins and USB signals:

screenshot_8063

My custom board followed the data sheet spec and put the JTAG header pins off GPIO 39, 40, 41, 42, with GPIO 39 = as TCK, 40 as TDO, 41 as TDI, and 42 as TMS.

image

from the data sheet:
'
image

Seems like a custom USB cable is needed:
screenshot_8062

Right?

@SuGlider
Copy link
Collaborator

The ESP32-S3 USB JTAG is all that you need for debugging. Just GPIO 19 and 20 (D- / D+).
GPIOs 39 to 42 are meant for using with the ESP-PROG.
Those are 2 different and independet ways to using JTAG.

@SuGlider
Copy link
Collaborator

SuGlider commented May 26, 2023

Arduino IDE has a few option in S3 the Menu-->JTAG Adapter:
Integrated USB JTAG --> use the regular USB (GPIO19 D- and GPIO20 D+) as JTAG interface - implemented in HW
FTDI Adapter --> When there is an FTDI chip with JTAG (USB) in the board, like the ESP-PROG
ESP USB Bridge --> Utilizing an ESP32-S2 or an ESP32-S3 chip to create a JTAG bridge - it's a software JTAG.

Each of these 3 options will set a different OpenOCD configuration file to be used within the IDE debugger.

@SuGlider
Copy link
Collaborator

SuGlider commented May 26, 2023

@frankcohen
Copy link
Author

Hi @SuGlider thanks! I created a USB cable for the JTAG support.

screenshot_8065

This connects to the ESP32-S3-DevKitMini-1 I just bought. I selected ESP32-S3-Box in Arduino IDE 2.1 on Macbook Pro. I could find no ESP32-S3-DevKitMini board definition in Arduino IDE 2.1. The upload speed compared to Arduino IDE 2.1 over USB was surprising - much faster on the JTAG interface.

screenshot_8066

screenshot_8067

Next for me:

  1. On Arduino 2.1 how to see output to the Serial Monitor over JTAG? Or, do I need to connect a second USB cable to my Powerbook to see the Serial.println(" "); logging?
  2. How to do step/breakpoints on Arduino 2.1 on JTAG?
  3. How to configure this board and JTAG cable on Platform IO?

I'm not finding useful search results on the above issues on Google nor the Espressif Web site search.

-Frank

@SuGlider
Copy link
Collaborator

On Arduino 2.1 how to see output to the Serial Monitor over JTAG? Or, do I need to connect a second USB cable to my >Powerbook to see the Serial.println(" "); logging?

The same USB JTAG works as USB CDC (serial communication over USB). When USB CDC On Boot is set Enabled in the Arduino IDE, the software will set the object Serial to the HWCDC class and it will work out of the box, using the JTAG/CDC USB port for any Serial.print().

No need to connect any second cable.

log_d() also works, but it is necessary to tell Arduino to use the HWCDC interface about it.
Serial.setDebugOutput(true) will do it when USB CDC On Boot is set Enabled - in this case Serial0 is the UART0
USBSerial.setDebugOutput(true) will do it when USB CDC On Boot is set Disabled - in this case Serial is the UART0

How to do step/breakpoints on Arduino 2.1 on JTAG?

First of all, it is necessary to set the Arduino IDE 2.1 and activate the Debugging mode.
Please refer to #8237 (comment)
After that, in the Debug Window there is a Breakpoints session - click on + to add functions or go to the Source Code window and click on the left border to the Code Line to add a breakpoint there.

How to configure this board and JTAG cable on Platform IO?

For the Hardware, there is no change. It is the same as explained above.
The PIO IDE can open a /dev/.... (linux, Mac) or COMxx (Windows) and set it for the Output.

@SuGlider
Copy link
Collaborator

SuGlider commented May 27, 2023

@frankcohen - The S3 DevKit already exposes the GPIOs 19 and 20 as USB. Maybe you already know it.
image

UART0 is the regular CP2102 chip attached to the UART 0 Rx/Tx GPIOs.

@Jason2866
Copy link
Collaborator

Jason2866 commented May 28, 2023

@SuGlider Thx for the links how to flash. Having no issues with flashing any espressif device local. Sorry for being unclear here. The issue is finally all about Web Flashing.
Espressif is providing https://github.com/espressif/esptool-js which is the base of ALL Web tools
for flashing via a Browser. This is a great way for users which "just" want to install a ready made firmware.
Without installing any tools or knowing how this all works. Plug and Play.
Dont get me wrong i appreciate the great work you and your colleagues are doing.
It is a bit frustrating that the issue (wherever it is) prevents the easy flashing of the S3 CDC boards via Browser, as it is possible for every other espressif Arduino supported device.

@frankcohen
Copy link
Author

I created a companion video for the ESP32-S3 (and why you should stay away from the others). View it here https://youtu.be/vQBxMgNvwZI -Frank

@SuGlider
Copy link
Collaborator

SuGlider commented Jun 1, 2023

I created a companion video for the ESP32-S3 (and why you should stay away from the others). View it here https://youtu.be/vQBxMgNvwZI -Frank

Thanks @frankcohen for the discussion and questions.
I'll close this issue given that most doubts are answered.
Please feel free to reopen it whenever needed.

@SuGlider SuGlider closed this as completed Jun 1, 2023
@VojtechBartoska VojtechBartoska changed the title ESP32-S3 USB frustrates me, you too? ESP32-S3 USB Usage Jun 1, 2023
@VojtechBartoska
Copy link
Contributor

VojtechBartoska commented Jun 1, 2023

Changing the title as the original one will no one find in the future, even though the new one is still generic.

@frankcohen
Copy link
Author

frankcohen commented Jun 1, 2023 via email

@frankcohen
Copy link
Author

frankcohen commented Jun 1, 2023 via email

@frankcohen
Copy link
Author

I posted the JCUSB solution (my name for the S3 + USB + CDC + OpenOCD + Arduino IDE solution) to Reddit at
https://www.reddit.com/r/esp32/comments/140nc29/esp32_usb_is_frustrating_try_jcusb_for_s3_usb_cdc/

@BotSpace
Copy link
Contributor

Thank you for sharing this. I have been very frustrated by esp32S3 USB upload, but now JCUSB works very well for me. I can upload code and use the serial monitor, all without having to press buttons or change settings.

I have just one issue, when I unplug and replug my board, ArduinoIDE does not remember my port. And in the drop down my device shows up as TAMC Termod S3?
image
It is easy enough to select the port again but Im just curious to hear if anyone has thoughts on this.

@frankcohen
Copy link
Author

frankcohen commented Jun 21, 2023 via email

@me-no-dev
Copy link
Member

Arduino.cc are aware of this issue and will fix it. Can not give timeframe yet :)

@frankcohen
Copy link
Author

frankcohen commented Jun 21, 2023 via email

@me-no-dev
Copy link
Member

That's great, thank you. Is there a ticket number or URL to the issue? Do
they take software contributions?

Issue is mentioned in a few places, but we have spoken to them directly to explain everything in detail. They do take contributions, though it might take some time for an external contribution to be accepted. I am fairly certain that this happens in arduino-cli and not the IDE itself

@frankcohen
Copy link
Author

frankcohen commented Jun 21, 2023 via email

@mukarram1999
Copy link

@frankcohen - The ESP32-S3 doesn't need the ESP-PROG because it already has the JTAG USB. Please follow the instructions that can be found in the documentation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/jtag-debugging/index.html https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/jtag-debugging/configure-builtin-jtag.html

As for the new IDE 2.1.0, it is necessary to:

1. Select the ESP32-S3 DevKit board

2. Select the USB port

3. Enable CDC on Boot (IDE Board Menu)

4. Select "Upload Mode" as "UART0 / Hardware CDC"

5. Select "USB Mode" as "Hardware CDC and JTAG"

6. Select "JTAG Adapter" as "Integrated USB JTAG"

7. Select and load the Sketch that will be debugged

8. Build and Upload it

9. Press the Debug "play" button to open the DEBUG window

10. Press the Green "play" button and wait for OpenOCD and dbg to start in the "Debug Console"

11. Add the BREAKPOINTS

12. Use the DEBUG UI as desired

Some Images of my IDE may help:

Menu Options: image

Screenshot of the Debugger in Action: image

Could you please give full detailed instructions on how to enable debugging of esp32s3 through Arduino IDE 2.x? I am messing up somewhere but I have no idea where.

@frankcohen
Copy link
Author

Thank you for the detailed instructions, I appreciate your effort. I wrote an article pulling together all that I learned. I posted it to Reddit and got a good dialogue going. I'm calling the technique JCUSB. I am hosting a how-to document here: https://github.com/frankcohen/ReflectionsOS/blob/main/Docs/JCUSB%20using%20JTAG%2C%20CDC%2C%20USB%20for%20debugging.md

-Frank

@frankcohen
Copy link
Author

frankcohen commented Jul 28, 2023

@mukarram1999
Copy link

Thank you for the detailed instructions, I appreciate your effort. I wrote an article pulling together all that I learned. I posted it to Reddit and got a good dialogue going. I'm calling the technique JCUSB. I am hosting a how-to document here: https://github.com/frankcohen/ReflectionsOS/blob/main/Docs/JCUSB%20using%20JTAG%2C%20CDC%2C%20USB%20for%20debugging.md

-Frank

Thank you so much for that. However, this is where I am stumped:

  1. What should launch.json config be to enable debugging? Debug does not happen without editing that but my Arduino IDE is not able to save any configurations in the first place.
  2. I got OpenOCD installed using the official ESP-IDF tools installer, how do I get Arduino IDE to use it to enable debugging?
  3. Is debugging plus uploading all possible with one cable? If not, how do I get the Arduino IDE to use a cable for uploading and the other for debugging?

@frankcohen
Copy link
Author

frankcohen commented Jul 29, 2023 via email

@mukarram1999
Copy link

Using Arduino IDE 2.1 Nightly Build on Mac OS, launch.json is ignored. Arduino IDE does some internal calculation to figure out where to find OpenOCD. It can get confused because OpenOCD uses Python 3 and there is some path strangeness on Mac. I found this resolved by using the Nightly Build. I click Upload, it’s builds and uploads, then I click the Debug button (upper left list of icons), and the debug panel appears.

I am using Arduino 2.1.1 IDE on Windows and unfortunately those stops don't work for me. Please help.

Yes, debugging plus uploading happens using the one cable (that I’m calling JCUSB).

That is awesome.

Thanks so much for all your help on this, Frank.

@frankcohen
Copy link
Author

frankcohen commented Aug 2, 2023 via email

@AMttos
Copy link

AMttos commented Aug 7, 2023

All,

could any of you (that successfully can run the ESP32-S3 USB JTAG debugging in the Arduino IDE 2.1X) share your launch.json / debug_custom.json files, therefore I can troubleshoot my setup? I posted at the endo of this tread the errors I am getting. Am I missing something? @SuGlider or @frankcohen

USB programming and reboot works fine.

I am using the following:

ESP32-S3-WROOM-2 with GPIO 19 and 20 as USB CDC communications and programing.
Arduino IDE 2.1.1
esp32 by Espressif 2.011, which installs OpenOCD and other tools

  • checked "Optimize for debugging" - (IDE Sketch Menu)
  • Enabled "CDC on Boot" - (IDE Board Menu)
  • Selected "Upload Mode" as "UART0 / Hardware CDC" - (IDE Board Menu)
  • Selected "USB Mode" as "Hardware CDC and JTAG" - (IDE Board Menu)
  • Selected "JTAG Adapter" as "Integrated USB JTAG" - (IDE Board Menu)

Here is my launch.json settings (as the Start Debugging button is pressed)
{
"version": "0.2.0",
"configurations": [
{
"cwd": "${workspaceRoot}",
"name": "Arduino on ESP32-S3",
"request": "attach",
"type": "cortex-debug",
"executable": "C:\Users\USER\AppData\Local\Temp\arduino\sketches\D0059C980E0F01DD711B407D02FD1697/Handheld_S3.ino.elf",
"servertype": "openocd",
"serverpath": "C:\Users\USER\AppData\Local\Arduino15\packages\esp32\tools\openocd-esp32\v0.11.0-esp32-20221026/bin/openocd",
"armToolchainPath": "C:\Users\USER\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp-elf-gdb\11.2_20220823/bin/",
"configFiles": [
"debug.cfg"
],
"toolchainPrefix": "xtensa-esp32s3-elf",
"svdFile": "debug.svd",
"overrideAttachCommands": [
"set remote hardware-watchpoint-limit 2",
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
],
"overrideRestartCommands": [
"monitor reset halt",
"monitor gdb_sync"
]
}
]
}

MY ERRORS
OpenOCD: GDB Server Quit Unexpectedly. See gdb-server output for more details.

gdb-server
[2023-08-07T20:56:20.472Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session connected. You can switch to "DEBUG CONSOLE" to see GDB interactions.
"C:\Users\USER\AppData\Local\Arduino15\packages\esp32\tools\openocd-esp32\v0.11.0-esp32-20221026/bin/openocd" -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s "c:\Users\USER\Documents\Electronics\01-Proj\Handheld_S3" -f "C:/Program Files/Arduino IDE/resources/app/plugins/cortex-debug/extension/support/openocd-helpers.tcl" -f debug.cfg
Open On-Chip Debugger v0.11.0-esp32-20221026 (2022-10-26-14:48)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
CDRTOSConfigure
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 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Error: esp_usb_jtag: could not find or open device!

[2023-08-07T20:56:20.802Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
GDB server session ended. This terminal will be reused, waiting for next session to start...

Thanks in Advance

@me-no-dev
Copy link
Member

@AMttos your configuration is correct, but openocd can not find the board.

@SuGlider is there anything additional that needs to be done on Windows?

@frankcohen
Copy link
Author

frankcohen commented Aug 8, 2023 via email

@AMttos
Copy link

AMttos commented Aug 9, 2023

@frankcohen and @me-no-dev

Thank you very much for replying to my questions and confirming my settings are correct. the weird thing is I can program and get serial monitor on the USB without issues. I do not understand why OpenOCD cannot find the board. I will do more digging and also try to use another PC and see if the issue is reproducible. I will let you know my findings.
Thanks again.

@frankcohen
Copy link
Author

frankcohen commented Aug 9, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Documentation Issue pertains to Documentation of Arduino ESP32 Type: For reference Common questions & problems Type: Question Only question
Projects
None yet
Development

No branches or pull requests