espressif / arduino-esp32

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

esp32-S2 usb cdc works only after serial monitor is opened #10474

Open Sonic803 opened 1 month ago

Sonic803 commented 1 month ago

Board

Wemos S2 mini

Device Description

Just the board connected with usbc connected to pc

Hardware Configuration

Nothing

Version

latest development Release Candidate (RC-X)

IDE Name

Arduino ide v2

Operating System

Arch Linux

Flash frequency

Lolin s2 default

PSRAM enabled

yes

Upload speed

Lolin s2 default

Description

I'm using the Lolin s2 mini board in arduino ide, with usb cdc enabled . After uploading this program while in dfu mode, If i try to re-upload it in cdc mode it fails with an error.

While if I first open the serial monitor and wait for it to receive some messages, and then try to upload it works.

Sketch

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

void loop() {
  Serial.println("Hello");
  delay(50);
}

Debug Message

FQBN: esp32:esp32:lolin_s2_mini:DebugLevel=verbose
Using board 'lolin_s2_mini' from platform in folder: /home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1
Using core 'esp32' from platform in folder: /home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1

/usr/bin/env bash -c "[ ! -f \"/home/sonic/Desktop/music/arduino/adc_test\"/partitions.csv ] || cp -f \"/home/sonic/Desktop/music/arduino/adc_test\"/partitions.csv \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/partitions.csv"
/usr/bin/env bash -c "[ -f \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/partitions.csv ] || [ ! -f \"/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/variants/lolin_s2_mini\"/partitions.csv ] || cp \"/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/variants/lolin_s2_mini\"/partitions.csv \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/partitions.csv"
/usr/bin/env bash -c "[ -f \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/partitions.csv ] || cp \"/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1\"/tools/partitions/default.csv \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/partitions.csv"
/usr/bin/env bash -c "[ -f \"/home/sonic/Desktop/music/arduino/adc_test\"/bootloader.bin ] && cp -f \"/home/sonic/Desktop/music/arduino/adc_test\"/bootloader.bin \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/adc_test.ino.bootloader.bin || ( [ -f \"/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/variants/lolin_s2_mini\"/bootloader.bin ] && cp \"/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/variants/lolin_s2_mini\"/bootloader.bin \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/adc_test.ino.bootloader.bin || python3 \"/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6\"/esptool.py --chip esp32s2 elf2image --flash_mode dio --flash_freq 80m --flash_size 4MB -o \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/adc_test.ino.bootloader.bin \"/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2\"/bin/bootloader_qio_80m.elf )"
esptool.py v4.6
Creating esp32s2 image...
Merged 2 ELF sections
Successfully created esp32s2 image.
/usr/bin/env bash -c "[ ! -f \"/home/sonic/Desktop/music/arduino/adc_test\"/build_opt.h ] || cp -f \"/home/sonic/Desktop/music/arduino/adc_test\"/build_opt.h \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/build_opt.h"
/usr/bin/env bash -c "[ -f \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/build_opt.h ] || : > \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/build_opt.h"
/usr/bin/env bash -c ": > '/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/file_opts'"
Detecting libraries used...
/home/sonic/.arduino15/packages/esp32/tools/esp-x32/2405/bin/xtensa-esp32s2-elf-g++ -c @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/cpp_flags -w -Os -Werror=return-type -w -x c++ -E -CC -DF_CPU=240000000L -DARDUINO=10607 -DARDUINO_LOLIN_S2_MINI -DARDUINO_ARCH_ESP32 -DARDUINO_BOARD="LOLIN_S2_MINI" -DARDUINO_VARIANT="lolin_s2_mini" -DARDUINO_PARTITION_default -DARDUINO_HOST_OS="linux" -DARDUINO_FQBN="esp32:esp32:lolin_s2_mini:CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,PartitionScheme=default,DebugLevel=verbose,EraseFlash=none" -DESP32 -DCORE_DEBUG_LEVEL=5 -DBOARD_HAS_PSRAM -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/defines -I/home/sonic/Desktop/music/arduino/adc_test -iprefix /home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/include/ @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/includes -I/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/qio_qspi/include -I/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/cores/esp32 -I/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/variants/lolin_s2_mini @/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/build_opt.h @/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/file_opts /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/sketch/adc_test.ino.cpp -o /dev/null
Generating function prototypes...
/home/sonic/.arduino15/packages/esp32/tools/esp-x32/2405/bin/xtensa-esp32s2-elf-g++ -c @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/cpp_flags -w -Os -Werror=return-type -w -x c++ -E -CC -DF_CPU=240000000L -DARDUINO=10607 -DARDUINO_LOLIN_S2_MINI -DARDUINO_ARCH_ESP32 -DARDUINO_BOARD="LOLIN_S2_MINI" -DARDUINO_VARIANT="lolin_s2_mini" -DARDUINO_PARTITION_default -DARDUINO_HOST_OS="linux" -DARDUINO_FQBN="esp32:esp32:lolin_s2_mini:CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,PartitionScheme=default,DebugLevel=verbose,EraseFlash=none" -DESP32 -DCORE_DEBUG_LEVEL=5 -DBOARD_HAS_PSRAM -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/defines -I/home/sonic/Desktop/music/arduino/adc_test -iprefix /home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/include/ @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/includes -I/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/qio_qspi/include -I/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/cores/esp32 -I/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/variants/lolin_s2_mini @/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/build_opt.h @/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/file_opts /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/sketch/adc_test.ino.cpp -o /tmp/171925280/sketch_merged.cpp
/home/sonic/.arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/171925280/sketch_merged.cpp
Compiling sketch...
/home/sonic/.arduino15/packages/esp32/tools/esp-x32/2405/bin/xtensa-esp32s2-elf-g++ -MMD -c @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/cpp_flags -w -Os -Werror=return-type -DF_CPU=240000000L -DARDUINO=10607 -DARDUINO_LOLIN_S2_MINI -DARDUINO_ARCH_ESP32 "-DARDUINO_BOARD=\"LOLIN_S2_MINI\"" "-DARDUINO_VARIANT=\"lolin_s2_mini\"" -DARDUINO_PARTITION_default "-DARDUINO_HOST_OS=\"linux\"" "-DARDUINO_FQBN=\"esp32:esp32:lolin_s2_mini:CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,PartitionScheme=default,DebugLevel=verbose,EraseFlash=none\"" -DESP32 -DCORE_DEBUG_LEVEL=5 -DBOARD_HAS_PSRAM -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/defines -I/home/sonic/Desktop/music/arduino/adc_test -iprefix /home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/include/ @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/includes -I/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/qio_qspi/include -I/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/cores/esp32 -I/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/variants/lolin_s2_mini @/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/build_opt.h @/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/file_opts /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/sketch/adc_test.ino.cpp -o /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/sketch/adc_test.ino.cpp.o
Compiling libraries...
Compiling core...
/usr/bin/env bash -c "echo -DARDUINO_CORE_BUILD > '/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/file_opts'"
Using precompiled core: /tmp/arduino/cores/49a407282d126346c3fd8cbac7e5ae80/core.a
/usr/bin/env bash -c ": > '/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/file_opts'"
Linking everything together...
/home/sonic/.arduino15/packages/esp32/tools/esp-x32/2405/bin/xtensa-esp32s2-elf-g++ @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/ld_flags @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/ld_scripts -Wl,--Map=/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.map -L/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/lib -L/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/ld -L/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/qio_qspi -Wl,--wrap=esp_panic_handler -Wl,--start-group /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/sketch/adc_test.ino.cpp.o /tmp/arduino/cores/49a407282d126346c3fd8cbac7e5ae80/core.a @/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2/flags/ld_libs -Wl,--end-group -Wl,-EL -o /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.elf
python3 /home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool.py --chip esp32s2 elf2image --flash_mode dio --flash_freq 80m --flash_size 4MB --elf-sha256-offset 0xb0 -o /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.bin /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.elf
esptool.py v4.6
Creating esp32s2 image...
Merged 2 ELF sections
Successfully created esp32s2 image.
python3 /home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/tools/gen_esp32part.py -q /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/partitions.csv /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.partitions.bin
/usr/bin/env bash -c "[ ! -d \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/libraries/Insights ] || python3 \"/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1\"/tools/gen_insights_package.py /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5 adc_test.ino \"/home/sonic/Desktop/music/arduino/adc_test\""
/usr/bin/env bash -c "[ ! -d \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/libraries/ESP_SR ] || [ ! -f \"/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2\"/esp_sr/srmodels.bin ] || cp -f \"/home/sonic/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32s2\"/esp_sr/srmodels.bin \"/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5\"/srmodels.bin"
python3 /home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool.py --chip esp32s2 merge_bin -o /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.merged.bin --fill-flash-size 4MB --flash_mode keep --flash_freq keep --flash_size keep 0x1000 /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.bootloader.bin 0x8000 /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.partitions.bin 0xe000 /home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/tools/partitions/boot_app0.bin 0x10000 /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.bin
esptool.py v4.6
Wrote 0x400000 bytes to file /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.merged.bin, ready to flash to offset 0x0

/home/sonic/.arduino15/packages/esp32/tools/esp-x32/2405/bin/xtensa-esp32s2-elf-size -A /tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.elf
Sketch uses 300483 bytes (22%) of program storage space. Maximum is 1310720 bytes.
Global variables use 27224 bytes (8%) of dynamic memory, leaving 300456 bytes for local variables. Maximum is 327680 bytes.
Performing 1200-bps touch reset on serial port /dev/ttyACM3
Waiting for upload port...
No upload port found, using /dev/ttyACM3 as fallback
python3 "/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool.py" --chip esp32s2 --port "/dev/ttyACM3" --baud 921600  --before default_reset --after hard_reset write_flash  -z --flash_mode keep --flash_freq keep --flash_size keep 0x1000 "/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.bootloader.bin" 0x8000 "/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.partitions.bin" 0xe000 "/home/sonic/.arduino15/packages/esp32/hardware/esp32/3.1.0-RC1/tools/partitions/boot_app0.bin" 0x10000 "/tmp/arduino/sketches/5047A9EEBC05BDA2B2491CADD4ACBBF5/adc_test.ino.bin" 
esptool.py v4.6
Serial port /dev/ttyACM3
Connecting...Traceback (most recent call last):
  File "/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool.py", line 37, in <module>

    esptool._main()
  File "/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/__init__.py", line 1064, in _main
    main()
  File "/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/__init__.py", line 678, in main
    esp = esp or get_default_connected_device(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/__init__.py", line 953, in get_default_connected_device
    _esp.connect(before, connect_attempts)
  File "/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/loader.py", line 642, in connect
    last_error = self._connect_attempt(reset_strategy, mode)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/loader.py", line 527, in _connect_attempt
    reset_strategy()  # Reset the chip to bootloader (download mode)
    ^^^^^^^^^^^^^^^^
  File "/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/reset.py", line 83, in __call__
    self._setDTRandRTS(False, False)
  File "/home/sonic/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/reset.py", line 58, in _setDTRandRTS
    fcntl.ioctl(self.port.fileno(), TIOCMSET, struct.pack("I", status))
OSError: [Errno 71] Protocol error

Other Steps to Reproduce

No response

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

VojtechBartoska commented 1 month ago

@SuGlider Please help with triage, thanks

SuGlider commented 3 weeks ago

I'm not sure how to test the issue.

I can help by describing how the S2 USB is supposed to work:

Please describe the steps you have followed when you see the issue. I can replicate them here and check what is going on. Thanks.

SuGlider commented 3 weeks ago

Not sure if this is the issue, but the USB CDC port only shows up (is enumerated by the OS) when CDC is enabled and DFU is disabled. If this is the case, in order to download a new firmware into the S2 Mini, it is necessary to put it into download mode, by holding BOOT and pulsing EN/RESET.

SuGlider commented 3 weeks ago

Yes, indeed something has changed from 3.0.7 to 3.1.0-RC1. S2 could have both CDC and DFU enabled and CDC would work fine in 3.0.7. With 3.1.0-RC1 and RC2 when CDC and DFU are enabled, CDC doesn't work and the host doesn't enumerate the USB port.

@me-no-dev -- would you know about any change that would result in blocking CDC when DFU is enabled?

Sonic803 commented 3 weeks ago

screenshot These are the setting that I am using, even the Lolin s2 mini settings don't work.

Using the 3.0.7 version doesn't solve the issue.

I'm using the Lolin s2 mini board in arduino ide, with usb cdc enabled . After uploading this program while in dfu mode, If i try to re-upload it in cdc mode it fails with an error.

When I said this I meant that the first time I upload the firmware while in download mode (GPIO0 low while toggling reset).

What I actually do to replicate this issue:

  1. Set Board Settings as listed above
  2. Connect the board in download mode
  3. Upload the sketch (it works)
  4. Reset
  5. If now I try to upload the sketch another time it won't work
  6. If I try to upload it with the serial monitor running and printing messages it works.
me-no-dev commented 3 weeks ago

@SuGlider 3.0.7 and RC2 should have the exact same TinyUSB setup