espressif / arduino-esp32

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

V2.0.15 USB OTG Serial.println() works WITHOUT a Serial.begin() #9532

Open def1149 opened 4 months ago

def1149 commented 4 months ago

Board

Adafruit Feather ESP32-S2

Device Description

N/A

Hardware Configuration

N/A

Version

latest master (checkout manually)

IDE Name

Arduino IDE 2.3.2

Operating System

Windows 10

Flash frequency

80 Mhz

PSRAM enabled

yes

Upload speed

921600

Description

Serial.print() works WITHOUT a Serial.open()

Sketch

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  Serial.println("\nThis Prints !!??");
  delay(2000);
}

Debug Message

N/A

Other Steps to Reproduce

No response

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

SuGlider commented 4 months ago

@def1149 - Adafruit Feather ESP32-S2 uses Native USB CDC to print using the Serial object from Arduino. It has no UART<->USB chip, therefore its USB port is directly connected to the S2 USB pins.

Indeed, Serial.println("\nThis Prints !!??") works because USBCDC::begin() is called in the Arduino Initialization, before the sketch starts in app_main().

I think that there is a reason for that, maybe related to being able to print Debug messages before the Sketch starts, if necessary.

SuGlider commented 4 months ago

@me-no-dev - The call to Serial.begin() in main.cpp->void app_main() started with #5422 followed by #5466 and then finally in #6341

In #5422 there is the commit d425a3fd5f94ace0e8c19d1174e5a54f4d0124c9 that says "USB CDC should also be started in main". Is it still valid? Do you remember the reason for that?

me-no-dev commented 4 months ago

@SuGlider sorry, I did not understand this is USB. It would then make sense that it's ON