espressif / arduino-esp32

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

Set the correct reset sequence after flashing for CDC targets #10228

Open peterdragun opened 3 weeks ago

peterdragun commented 3 weeks ago

Board

all boards with OTG (ESP32-S2, ESP32-S3)

Device Description

devkit connected using native USB and OTG mode enabled

Hardware Configuration

no other HW required

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

macOS, but can be reproduced anywhere

Flash frequency

N/A

PSRAM enabled

yes

Upload speed

N/A

Description

When flashing using USB-OTG esptool is not able to reset the target. The default behavior is that esptool tries to reset the target to run the application. Because this is not available when connected using OTG esptool fails with an error that this was not done because it was not able to reset the target. Arduino gets this message and appends ''uploading error" even though uploading was successful and the only issue is that the chip wasn't reset.

There are two ways how this can be improved from the Arduino side:

  1. Pass the correct --after argument when CDC is selected
  2. Catch the error message and adjust the output accordingly - instead of 'Failed to upload' to something like 'Failed to reset...'

In the newer version of esptool, we will try to improve this message and at least pass it as part of the exception.

Sketch

any sketch, e.g. Blink example

Debug Message

Warning: ESP32-S2 (revision v0.0) chip was placed into download mode using GPIO0.
esptool.py can not exit the download mode over USB. To run the app, reset the chip manually.
To suppress this note, set --after option to 'no_reset'.
Failed uploading: uploading error: exit status 1

Other Steps to Reproduce

No response

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

me-no-dev commented 3 weeks ago

S2 should work. Doesn't it? This is when not manually entering DownloadMode, but using esptool to reset into download?

peterdragun commented 3 weeks ago

Only if the previous application enabled the OTG port. If you are running just e.g. blink the port won't show up, so you need to switch to download mode manually.

me-no-dev commented 2 weeks ago

I used the following sketch to test and got different results.

Test sketch (CDC on Boot is enabled):

void setup() {
  Serial.begin(115200);
}

void loop() {
  while (Serial.available()) {
    size_t l = Serial.available();
    uint8_t b[l];
    l = Serial.read(b, l);
    Serial.write(b, l);
  }
}

Error from the IDE for S3:

Screenshot 2024-08-29 at 11 36 25

Same error on the new IDE2:

Screenshot 2024-08-29 at 11 41 20
peterdragun commented 1 week ago

I don't think you are using the correct ports on your devkits. For S2 this is easy, you just need a devkit (e.g. ESP32-S2-DevKitC-1) with two ports, usually, one is marked UART and the other one is USB. And connect to the USB port. For S3 it is similar but by default, USB Serial/JTAG peripheral is connected to that port - so you need to change it in eFuse or by strapping pin.

That way you should get the warning/error from esptool because there is no way to reset the target using a USB-CDC port.

me-no-dev commented 1 week ago

Of course I am using the proper USB ports and in proper mode (OTG not JTAG/CDC) and CDC_ON_BOOT set to 1. The same as all our users. If I have to set an efuse, then we are going outside of the regular Arduino use case.

Both chips tested with TinyUSB booted and esptool commanding reboot to Download + flash.