espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.61k stars 7.41k forks source link

ESP32-S3 USB Usage #8237

Closed frankcohen closed 1 year ago

frankcohen commented 1 year ago

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:

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. https://github.com/espressif/arduino-esp32/issues/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

me-no-dev commented 1 year ago

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)

frankcohen commented 1 year ago

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:

I (2121188) example: log -> USB example: print -> stdout example: print -> stderr I (2122688) example: log -> USB example: print -> stdout example: print -> stderr I (2124188) example: log -> USB example: print -> stdout example: print -> stderr

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

-Frank

dsilletti commented 1 year ago

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

SuGlider commented 1 year ago

@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 commented 1 year ago

Thank you Rodrigo, very kind to post these instructions.

May I ask you another question: I have an Espressif ESP-Prog board for JTAG debugging. I connect it to GPIO39, 40, 41, 42. What are the Arduino IDE settings to use that?

-Frank

On May 25, 2023, at 1:57 PM, Rodrigo Garcia @.***> wrote:

@frankcohen https://github.com/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.

https://user-images.githubusercontent.com/65977697/241057982-56c1f114-01f9-4163-8a7c-4826a38898aa.png — Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/8237#issuecomment-1563497918, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUEWMIHHN7DX35KDXRWTFLXH7BVFANCNFSM6AAAAAAYJ6XWIU. You are receiving this because you were mentioned.

SuGlider commented 1 year ago

@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 commented 1 year ago

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

sblantipodi commented 1 year ago

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

SuGlider commented 1 year ago

@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 commented 1 year ago

@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...

4) 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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 https://github.com/espressif/arduino-esp32/issues/8237#issuecomment-1563497918

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 commented 1 year ago

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:

ESP32-S3 Pin USB Signal GPIO19 D- GPIO20 D+ 5V V_BUS GND Ground 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.

from the data sheet:

Seems like a custom USB cable is needed:

Right?

-Frank

On May 25, 2023, at 7:51 PM, Rodrigo Garcia @.***> wrote:

@frankcohen https://github.com/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:

Select the ESP32-S3 DevKit board Select the USB port Enable CDC on Boot (IDE Board Menu) Select "Upload Mode" as "UART0 / Hardware CDC" Select "USB Mode" as "Hardware CDC and JTAG" Select "JTAG Adapter" as "Integrated USB JTAG" Select and load the Sketch that will be debugged Build and Upload it Press the Debug "play" button to open the DEBUG window Press the Green "play" button and wait for OpenOCD and dbg to start in the "Debug Console" Add the BREAKPOINTS Use the DEBUG UI as desired Some Images of my IDE may help:

Menu Options: https://user-images.githubusercontent.com/65977697/241106387-326779a4-7b96-4a33-9b3e-2de57dc39347.png Screenshot of the Debugger in Action: https://user-images.githubusercontent.com/65977697/241106615-28ef3269-1a17-4113-a3b4-8110b8fe3ec7.png — Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/8237#issuecomment-1563746127, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUEWMLUPLFXEZXYBYS6Q4LXIALEZANCNFSM6AAAAAAYJ6XWIU. You are receiving this because you were mentioned.

frankcohen commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@frankcohen -- Important Note from Documentation: image https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/jtag-debugging/configure-other-jtag.html

frankcohen commented 1 year ago

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 commented 1 year ago

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 https://github.com/espressif/arduino-esp32/issues/8237#issuecomment-1563746127 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 commented 1 year ago

@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.

frankcohen commented 1 year ago

@SuGlider thank you Rodrigo! I appreciate your experience and willingness to share. I plan to follow your instruction for Arduino IDE 2.1 and Platform.io. I feel a tutorial video for YouTube and Reddit article coming from this experience to help others. Also, I will let Andreas Speiss know about this, perhaps he will be inspired to make a video too. -Frank

Jason2866 commented 1 year ago

@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 The issue is known. But actually no one has an idea how to solve. Open Issue https://github.com/esphome/esp-web-tools/issues/331 Webtools is using esptool.js v2.1 which is the exact same version as in LaunchPad

frankcohen commented 1 year ago

Hi @SuGlider, Rodrigo, I'm seeing Serial Monitor logging over JTAG USB, thanks!

When I try to enable the debugger in Arduino IDE 2.1 with the Espressif ESP32-S3-DevKitMini-1 over JTAG USB using Adafruit Feather S3 No PSRam board. I don't think I have everything configured correctly. I'm on a Mac Powerbook, running 13.3.1 (a). I do not have OpenOCD installed.

screenshot_8076

Should I install OpenOCD with HomeBrew?

SuGlider commented 1 year ago

Should I install OpenOCD with HomeBrew?

No, it is installed with the ESP32 Pacakage at /Users/{username}/Library/Arduino15/packages/esp32/tools/openocd-esp32 Have you selected the JTAG Adapter option in the menu as Integrated USB JTAG? Press the Green "Play" button, it shall load OpenOCD and activate the debugging.

SuGlider commented 1 year ago

@SuGlider The issue is known. But actually no one has an idea how to solve. Open Issue esphome/esp-web-tools#331 Webtools is using esptool.js v2.1 which is the exact same version as in LaunchPad

From what I could test, I found out that the S3 must have CDC/JTAG already active. This can be done by uploading, for example an empty sketch, with CDC/JTAG setup prior to using LaunchPad. This firmware will "turn on CDC/JTAG" after booting, setting the conditions to the S3 to work with LaunchPad. The new uploaded firmware shall also turn on CDC/JTAG for the following upload, and so on...

I had a similar issue with other MCUs when dealing with USB bootloaders... Since, it is activated by software, it need to have a uploaded proper firmware in order to work fine. The MCU boots, sets the proper USB mode, it may also need a running active USB driver when WebUSB tries to upload a new firmware.

TinyUSB mode seems to fail when uploading using LaunchPad.

I agree that it is not easy and quite confusing...

SuGlider commented 1 year ago

The S3 native USB has 3 modes: (1) CDC/JTAG || (2) OTG - TinyUSB driver || (3) disabled Each of these 3 modes are activated by the running firmware of the S3, right after booting.

USB Web tools and other uploading modes work best with the (1) CDC/JTAG. It is possible to activate this mode by uploading an empty (or small) firmware/sketch that sets the CDC/JTAG mode. But if the next uploaded firmware is created/programmed to use (2) or (3), the following uploads using USB will fail.

Therefore, S3 demands that CDC/JTAG is activated by the running firmware and that all next firmwares keep this mode always active.

frankcohen commented 1 year ago

I confirmed the openOCD is installed in the correct path on my Mac. I set a breakpoint in the code and Debug seems to ignore it.

screenshot_8080

The program runs, and I see results in Serial Monitor, and nothing else, no breakpoints, etc.

Also, I am not seeing JTAG Adapter as an option when selecting ESP32-S3-Mini.

frankcohen commented 1 year ago

And, of course, I wasn't running the sketch with the "Start Debugging" icon. Doing so I see the error: screenshot_8082

Jason2866 commented 1 year ago

The S3 native USB has 3 modes: (1) CDC/JTAG || (2) OTG - TinyUSB driver || (3) disabled Each of these 3 modes are activated by the running firmware of the S3, right after booting.

USB Web tools and other uploading modes work best with the (1) CDC/JTAG. It is possible to activate this mode by uploading an empty (or small) firmware/sketch that sets the CDC/JTAG mode. But if the next uploaded firmware is created/programmed to use (2) or (3), the following uploads using USB will fail.

Therefore, S3 demands that CDC/JTAG is activated by the running firmware and that all next firmwares keep this mode always active.

If I understand your post correct, you are saying there is no possibility to flash a brand new S3 (which has no additional UART chip) reproducible correctly with the target productive firmware? If this is the case it is a big hardware bug, which has to be mentioned in all S3 data sheets!

sblantipodi commented 1 year ago

@Jason2866 PlatformIO and Arduino IDE are able to flash these chips in the way you want with the firmware you want. Sometimes you need to put the device in CDC mode before flashing by doing an absurd sequence of steps like pressing the IO button, then pressing the RST one, wait a bit, release the RST button leaving the IO pressed, than start flashing, then releasing the IO button.

It's clear that new S2 and S3 has some serious flaws on this. The proof is the even the official web tools from espressif isn't able to flash their own devices.

Using CDC on S3 is a non sense since you loose all the benefits of having a native USB. CDC creates lags and some weird issues when pushing it with data. TinyUSB works very well when streaming data on it but it's very difficult to flash the ESP once set in TinyUSB mode.

Jason2866 commented 1 year ago

@sblantipodi Yes, but as @SuGlider correctly mentioned only because there is a firmware before which enables the S3 to be correctly flashed. It is a bug. The use case decides whether it needs all the USB features. For many use cases it is a one time need only. -> Flashing the firmware For Tasmota use case the USB options are not needed. There are many Tasmota users :-) Do not assume from your needs to other needs. So CDC is the perfect mode. To mention a other big Open Source project. EspEasy does not need or use USB features too. Both projects are fighting with issues from users not possible to flash there S3 devices via the WebInstaller.

The espressif Launchpad uses under the hood esptool.js v2.1 too. Same as in ESPhome WebInstaller. So the problem is there too.

EDIT: If you follow the thread, the CDC is the only mode for the S3 where an auto start after flashing is possible. So what to use? Every option has serious bugs.

EDIT2: One possible solution i see, enhancing esptool to workaround the CDC S3 bug with loading a "repair" firmware before the real target firmware is flashed.

SuGlider commented 1 year ago

@sblantipodi @Jason2866

If I understand your post correct, you are saying there is no possibility to flash a brand new S3 (which has no additional UART chip) reproducible correctly with the target productive firmware? If this is the case it is a big hardware bug, which has to be mentioned in all S3 data sheets!

All said is exclusively about using Web tools. WebUSB is different from the other tools. For Win/Linux/Mac Espressive command line tools, it works fine.

Jason2866 commented 1 year ago

@SuGlider Thats good news. So just esptool.js needs to be fixed

SuGlider commented 1 year ago

There many ways to flash a new firmware, including Wireless, SPI, UART (or JTAG), DFU, any other can be "invented". Uploading a firmware or any user application data means that some piece of software will store a block of data in the Flash, using the internal ROM functions.

I "could invent a new way" that takes I2C data and store it in the flash. It is up the application/software. ESP32 has ROM functions (software) that help the user to achieve it more easily using, for instance, UART. ROM functions also check if BOOT GPIO is pressed right after a RESET, starting an upload mode, as defined in the ROM code. This is documented. https://docs.espressif.com/projects/esptool/en/latest/esp32s3/advanced-topics/boot-mode-selection.html https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-guides/dfu.html# https://docs.espressif.com/projects/esptool/en/latest/esp32s3/esptool/flashing-firmware.html

SuGlider commented 1 year ago

Check this video: https://www.youtube.com/watch?v=Zqqj8GC0Q9Q BOOT + RESET activates S2 TinyUSB ROM layer and then the computer is able to enumerate it.

Jason2866 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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.

VojtechBartoska commented 1 year ago

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

frankcohen commented 1 year ago

Thanks

On Thu, Jun 1, 2023, 7:42 AM Vojtěch Bartoška @.***> wrote:

Changing the title as the original one will no one find in the future, even though it's still generic.

— Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/8237#issuecomment-1572186958, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUEWMJVWHS6VML4HIHKSSLXJCS5VANCNFSM6AAAAAAYJ6XWIU . You are receiving this because you were mentioned.Message ID: @.***>

frankcohen commented 1 year ago

Thanks

On Thu, Jun 1, 2023, 7:34 AM Rodrigo Garcia @.***> wrote:

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 https://www.youtube.com/watch?v=vQBxMgNvwZI -Frank

Thanks @frankcohen https://github.com/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.

— Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/8237#issuecomment-1572173847, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUEWMJ3BWDPTIXG4FRPBCTXJCSAPANCNFSM6AAAAAAYJ6XWIU . You are receiving this because you were mentioned.Message ID: @.***>

frankcohen commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

I have the same problem. I haven’t looked into Arduino IDE to see if the source is available, if it is I propose a contribution that does a better job at remembering the previously chosen board and port.

-Frank

On Jun 20, 2023, at 10:55 PM, Jacob Williams @.***> wrote:

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? https://user-images.githubusercontent.com/47766188/247444965-41d25e47-afe4-443d-866f-839a66d9ae3b.png It is easy enough to select the port again but Im just curious to hear if anyone has thoughts on this.

— Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/8237#issuecomment-1600218595, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUEWMNJ7HSZPHNVYSVT77DXMKEFFANCNFSM6AAAAAAYJ6XWIU. You are receiving this because you were mentioned.

me-no-dev commented 1 year ago

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