Skip to content

ESP32-S3 Serial.print() calls when not connected to USB cause delays. #8251

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
sblantipodi opened this issue May 25, 2023 · 6 comments
Closed
1 task done
Assignees
Labels
Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Type: Question Only question

Comments

@sblantipodi
Copy link
Contributor

Board

Lolin ESP32-S3

Device Description

Lolin ESP32-S3 and UM S3

Hardware Configuration

no GPIO connected

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Win11

Flash frequency

80MHzù

PSRAM enabled

no

Upload speed

115200

Description

This is a duplicate issue of
#6983

the workaround described in that issue does not work on S3 but the issue is the same.

Sketch

#include <Wire.h>
#include <Adafruit_NeoPixel.h>

#define LED_PIN 6
#define NEOPIXEL_PIN LED_PIN
Adafruit_NeoPixel pixels(1, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

}

void loop() {
  // put your main code here, to run repeatedly:

  pixels.begin();  // INITIALIZE NeoPixel strip object (REQUIRED)
  
  Serial.print("Red... ");
  // drawMessage("Test Red LED");
  pixels.setPixelColor(0, pixels.Color(64, 0, 0));
  pixels.show();
  delay(500);

    Serial.print("Green... ");
// drawMessage("Test Green LED");
  pixels.setPixelColor(0, pixels.Color(0, 64, 0));
  pixels.show();
  delay(500);

    Serial.print("Blue... ");
// drawMessage("Test Blue LED");
  pixels.setPixelColor(0, pixels.Color(0, 0, 64));
  pixels.show();
  delay(500);
  
    Serial.print("White... ");
// drawMessage("Test Whitish LED");
  pixels.setPixelColor(0, pixels.Color(64, 64, 64));
  pixels.show();
  delay(500);

  Serial.print("Off... ");
  pixels.clear();
  pixels.show();
  delay(500);
  Serial.println("Done. Looping");
}

Debug Message

no debug msg

Other Steps to Reproduce

No response

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@sblantipodi sblantipodi added the Status: Awaiting triage Issue is waiting for triage label May 25, 2023
@SuGlider SuGlider self-assigned this May 25, 2023
@SuGlider SuGlider added Type: Question Only question Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip IDE: PlaformIO Issue relates to PlatformIO IDE and removed Status: Awaiting triage Issue is waiting for triage labels May 25, 2023
@SuGlider
Copy link
Collaborator

@sblantipodi - What is the version of the Arduino Core you have used?

I have just tested it (for 5 minutes - with USB plugged and unplugged + closing the Serial Terminal while printing the USB messages etc) using the Arduino IDE 1.8.15 and Arduino Core 2.0.9.
I got no delay issues... #7583 has fixed it.

I seems to be an issue with the PlatformIO configuration used.

@sblantipodi
Copy link
Contributor Author

I'm using [email protected] that uses
Arduino Release v2.0.9 based on ESP-IDF v4.4.4

the issue is there, the fix reduces the lag but not eliminates it.

@sblantipodi
Copy link
Contributor Author

I am driving 100 LEDs at 100FPS with Luciferin.
https://github.com/sblantipodi/glow_worm_luciferin/tree/reduced_footprint

if I Serial.print() various messages every 10 seconds, the framerate goes down to an average of 85FPS.

if I attach the Serial console while driving the LEDs, the average framerate goes back to 100FPS.

This does not happen on S2.

@SuGlider
Copy link
Collaborator

SuGlider commented May 25, 2023

@sblantipodi - I can replicate the issue here when I use the HW CDC USB peripheral of the S3.
The S3 has 2 different CDC peripherals for the USB port: HW JTAG/CDC and USB OTG (the same of the S2).

There is a way to eliminate the delay completely from the HW JTAG/CDC USB port by caling Serial.setTxTimeoutMs(0); before Serial.begin(115200);.

When using the USB OTG CDC port of the S3, the delay issue never happens, like in the S2.

void setup() {
  // put your setup code here, to run once:
  Serial.setTxTimeoutMs(0);
  Serial.begin(115200);
}

Please try it and let me know.

@SuGlider
Copy link
Collaborator

You can also set the USB CDC peripheral that you want to use as your Serial in the sketch.
In order to do it, you need to select the right option in the IDE Menu:

  1. HW JTAG/CDC USB:

USB Mode ==> Hardware CDC and JTAG
USB CDC On Boot ==> Enabled
Upload Mode ==> UART0 / Hardware CDC

  1. USB OTG with TinyUSB (like in the ESP32-S2):

USB Mode ==> USB-OTG (TinyUSB)
USB CDC On Boot ==> Enabled
Upload Mode ==> USB-OTG CDC (TinyUSB)

This option may require the board to be manually reset after uploading a new sketch, by pressing the RESET or EN button of the board.

@SuGlider SuGlider removed the IDE: PlaformIO Issue relates to PlatformIO IDE label May 25, 2023
@sblantipodi
Copy link
Contributor Author

@SuGlider this fixed my issue when using HW JTAG/CDC USB.
thank you very much for the kind answer, I really appreciate it.

closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Type: Question Only question
Projects
None yet
Development

No branches or pull requests

2 participants