Skip to content

ESP32-C3 in USB CDC mode can hang if Serial.flush() called #9172

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

Closed
1 task done
6v6gt-duino opened this issue Jan 24, 2024 · 2 comments
Closed
1 task done

ESP32-C3 in USB CDC mode can hang if Serial.flush() called #9172

6v6gt-duino opened this issue Jan 24, 2024 · 2 comments
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@6v6gt-duino
Copy link

6v6gt-duino commented Jan 24, 2024

Board

ESP32-C3 Supermini (no USB/UART adaptor)

Device Description

ESP32-C3 Supermini is basically an ESP32-C3 chip with a USB-C socket and little else.
https://www.tindie.com/products/adz1122/esp32-c3-development-board-esp32-supermini/

Hardware Configuration

USB-C cable to either a PC (windows 10) or a simple phone charger

Version

v2.0.14

IDE Name

Arduino IDE 1.8.19

Operating System

Windows 10

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

Using "USB CDC on boot : enabled":
If the supermini is powered via a phone charger with no PC connection, Serial.flush() appears to cause a hang.

Sketch

/*
    esp32-c3 supermini test
    similar to: https://www.tindie.com/products/adz1122/esp32-c3-development-board-esp32-supermini/

    set up IDE with
    (a) Board ESP32-C3 dev module
    (b) "USB CDC on boot : enabled"
    (c) JTAG adapter disabled

    Test generates lots of serial output and then forces a Serial.flush

    This test appears to function correctly whether or not Serial.setTxTimeoutMs(0) is set (but see comment below for case(c)) :
    (a) if the supermini is connected via USB to a PC and the serial monitor is active. 
    (c) if the supermini is powered via a phone charger with no PC connection.

    This test appear to work only if Serial.setTxTimeoutMs(0) is set :
    (b) if the supermini is connected via USB to a PC and the serial monitor is NOT active. 
    
    Serial.flush() appears to cause a hang in case (c)

*/


const uint8_t led = 8 ;  // led wired HIGH side





void setup() {

  pinMode( led, OUTPUT ) ;
  digitalWrite( led, HIGH ) ;

  Serial.begin( 115200 ) ;

  // only defined if option "USB CDC on boot" selected in IDE
  // Serial.setTxTimeoutMs(0) ; // https://github.com/espressif/arduino-esp32/pull/7583

  while ( !Serial && millis() < 10000 ) {
    delay(500) ;
  }

  // pulse led for 4 seconds if serial connection found.
  if ( millis() < 10000 ) {
    Serial.println( "found Serial") ;
    digitalWrite( led, LOW ) ;
    delay( 4000 ) ;
    digitalWrite( led, HIGH ) ;
    delay( 1000 ) ;
  }
  else {
    // no Serial found
  }

}



void loop() {

  for ( int j = 0; j < 10 ; j++ ) {
    for ( int i = 0; i < 500 ; i++ ) {
      // Serial.print( i ) ;
      // Serial.print( '\t' ) ;
      // Serial.println(  "the quick brown fox jumps over the lazy dog" ) ;
      Serial.printf( "%4d \t %s \r\n",  i, "the quick brown fox jumps over the lazy dog" ) ;
      delay(1) ;
    }
    digitalWrite( led, LOW ) ;
    delay( 1000 ) ;
    digitalWrite( led, HIGH ) ;
    delay( 1000 ) ;
    if ( j == 9 ) { 
     // this kills it if there is no serial monitor connected 
     Serial.flush() ;
    }
  }
}

Debug Message

No debug messages with this use case (no serial monitor)

Other Steps to Reproduce

image

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@6v6gt-duino 6v6gt-duino added the Status: Awaiting triage Issue is waiting for triage label Jan 24, 2024
@tshcherban
Copy link

tshcherban commented Jan 26, 2024

those might be related? #6983, #7779

@6v6gt-duino
Copy link
Author

6v6gt-duino commented Jan 26, 2024

@tshcherban Yes, thank you. Following the 2 cases I found a reference to another which quite closely matches mine. #7554
Unfortunately I did not find this during my searches.

Duplicate of #7554

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

2 participants