Skip to content
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

Don't set TX timeout to 0 anymore for HW/USB CDC #2340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LennartF22
Copy link
Contributor

Due to a change in the Espressif Arduino core, the TX timeout for the HW CDC (used in the ESP32-S3, for example) must not be set to 0, as otherwise, an integer underflow occurs (see here).

Removing the TX timeout is not necessary anymore anyways, because it is now detected when CDC is not active, and attempts to write will return immediately until the host read something again. Only when the transmit buffer becomes full initially, the default timeout of just 100ms takes effect once (and that is actually a good thing, because it prevents text from being swallowed unintentionally, when someone is actually using CDC).

For USB CDC (used with the ESP32-S2, for example), the timeout is not relevant either, although I could not test that myself.

This fixes an issue where OpenDTU won't fully boot on the ESP32-S3, unless CDC is used. Although I'm not sure yet why the issue sometimes occurs and sometimes not, I was relatively consistently able to reproduce the issue when using the latest esptool on Linux (Debian 12, Linux kernel v6.1) to reset the ESP32-S3: esptool --chip esp32s3 read_flash --flash_size detect 0x0 0x1000 /dev/null

Due to a change in the Espressif Arduino core, the TX timeout for the HW CDC
(used in the ESP32-S3, for example) must not be set to 0, as otherwise, an
integer underflow occurs.

Removing the TX timeout is not necessary anymore anyways, because it is now
detected when CDC is not active, and attempts to write will return immediately
until the host read something again. Only when the transmit buffer becomes
full initially, the default timeout of just 100ms takes effect once.

For USB CDC (used with the ESP32-S2, for example), the timeout is not relevant
either.
@LennartF22
Copy link
Contributor Author

I also removed a 100ms delay. I'm not sure why that was there. Maybe so that there is some time to open a serial terminal before OpenDTU boots? In that case, 100ms would likely have been to short anyways.

delay(100);
#else
#if !ARDUINO_USB_CDC_ON_BOOT
// Only wait for serial interface to be set up when not using CDC

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Espressif's Documentation of USB CDC (Communications Device Class) and the respective event's.

#if !ARDUINO_USB_CDC_ON_BOOT
USBCDC USBSerial;
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants