Skip to content

ESP32 {S2, S3} CDC and HID stall when using simultaneously #10307

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

Open
1 task done
ChrGri opened this issue Sep 7, 2024 · 26 comments
Open
1 task done

ESP32 {S2, S3} CDC and HID stall when using simultaneously #10307

ChrGri opened this issue Sep 7, 2024 · 26 comments
Assignees
Labels
Status: Needs investigation We need to do some research before taking next steps on this issue

Comments

@ChrGri
Copy link

ChrGri commented Sep 7, 2024

Board

ESP32 S3 dev and S2 mini

Device Description

Hardware Configuration

USB-OTG port used

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Win 11

Flash frequency

PSRAM enabled

yes

Upload speed

Description

This issue was found during investigation of this ticket. I've opened this ticket, to clean up the issue tracking.

The issue is, that when sending signals over CDC (serial data) and HID (game controller output) at the same time, at least one of the channels will stall after a while and therefore isn't sending data to the PC anymore.

The steps to reproduce this issue:

  1. take ESP32 S2 mini or ESP32 S3 (other boards might behave similar)
  2. upload the software with simultaneous CDC and HID output from here
    https://github.com/ChrGri/DIY-Sim-Racing-FFB-Pedal/tree/develop/Validation/Joystick_Serial_test
  3. restart the ESP
  4. windows game controller output app to check the change in HID output
  5. open a serial monitor
  6. the ESPs output will stall now after a while, if not, please reduce the delay
    https://github.com/ChrGri/DIY-Sim-Racing-FFB-Pedal/blob/e2798eca295c65b02d2448eeabd65c69a27d08bd/Validation/Joystick_Serial_test/src/Joystick_Serial_test.ino#L54

The expected behaviour is that CDC and HID output streams are stable and don't collapse.

Sketch

See link above.

Debug Message

-

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.
@Jason2866
Copy link
Collaborator

Your Platformio setup is mixing versions. Bad idea. If you want to use core 3.0.4 with Platformio you should consider using pioarduino. https://github.com/pioarduino/platform-espressif32

@ChrGri
Copy link
Author

ChrGri commented Sep 7, 2024

Ideally I would want to use core version 2.x due to library compatibility

@Jason2866
Copy link
Collaborator

Development is done with actual core. So if anything is not working with core 2.0.x as wanted/expected it will not be changed/fixed in core 2.0.x.

@ChrGri
Copy link
Author

ChrGri commented Sep 7, 2024

Can you tell me where the versions are mixed?

I've checked the platformio file and it only references espressif32, see
https://github.com/ChrGri/DIY-Sim-Racing-FFB-Pedal/blob/a62915e6e5cbf0ae2353c9a2a32ef5b7ad33ea9d/Validation/Joystick_Serial_test/platformio.ini#L17

@ChrGri
Copy link
Author

ChrGri commented Sep 8, 2024

@Jason2866
Copy link
Collaborator

So you are using core 2.0.x. Not core 3.0.4 as you wrote in the issue template.
For core 2.0.x is no development and bug fixing done anymore.

@ChrGri
Copy link
Author

ChrGri commented Sep 9, 2024

So you are using core 2.0.x. Not core 3.0.4 as you wrote in the issue template. For core 2.0.x is no development and bug fixing done anymore.

No. The issue happens on core 3 too. Please try the toy example from the top.

@SuGlider
Copy link
Collaborator

We have found a couple problems with the TinyUSB version/commit used within the ESP32 Arduino Core.
There are problems with CDC.

It will take some time to fix. This issue will be kept in the list to be tested.

@SuGlider SuGlider self-assigned this Sep 10, 2024
@SuGlider
Copy link
Collaborator

@ChrGri - Could you please test it using Arduino 3.0.0-RC1 version? This uses the last stable TinyUSB version that I have found.

@ChrGri
Copy link
Author

ChrGri commented Sep 11, 2024

@ChrGri - Could you please test it using Arduino 3.0.0-RC1 version? This uses the last stable TinyUSB version that I have found.

@SuGlider 3.1.0-RC1?
Screenshot_20240911-063056

@ChrGri
Copy link
Author

ChrGri commented Sep 27, 2024

@ChrGri - Could you please test it using Arduino 3.0.0-RC1 version? This uses the last stable TinyUSB version that I have found.

Tried it, but it won't even compile
image

What am I doing wrong?

@TD-er
Copy link
Contributor

TD-er commented Sep 28, 2024

Did you remove the packages, platforms and cache folder from your .platformio directory?
Just to make sure you're not dealing with older files being present when changing platform definitions.

Edit:
Oh you're building for Arduino 3.0.x
Maybe you should try pioarduino as platformio has no support for the latest Arduino 3.0.x/ESP-IDF5.x

@ChrGri
Copy link
Author

ChrGri commented Sep 28, 2024

Did you remove the packages, platforms and cache folder from your .platformio directory? Just to make sure you're not dealing with older files being present when changing platform definitions.

Edit: Oh you're building for Arduino 3.0.x Maybe you should try pioarduino as platformio has no support for the latest Arduino 3.0.x/ESP-IDF5.x

Thank you, I tried with
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.05/platform-espressif32.zip and
https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc1/platform-espressif32.zip. The HID + CDC output stall similarly.

@Jason2866
Copy link
Collaborator

Jason2866 commented Sep 28, 2024

This setup

platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.05/platform-espressif32.zip and
https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc1/platform-espressif32.zip

is mixing different source and libs. Result will be unpredictable
Use for latest development Arduino 3.1.0 source code and libs

platform = https://github.com/pioarduino/platform-espressif32.git#Arduino/IDF53

@ChrGri
Copy link
Author

ChrGri commented Sep 28, 2024

@Jason2866
platform = https://github.com/pioarduino/platform-espressif32.git#Arduino/IDF53 same as before, still stall after a few seconds, see attached video

HID_CDC_stall.mp4

@ChrGri
Copy link
Author

ChrGri commented Nov 29, 2024

So this issue is known since a few months and hasn't been fixed. Any hints on how I can approach the fix myself?

BR

@ChrGri
Copy link
Author

ChrGri commented Dec 22, 2024

I've disabled CDC in the script and connected both USB ports (USB-OTG + USB-UART-bridge via CH343) to the PC.
image

The serial output stalls randomly even with the CH343 output, see video:
https://github.com/user-attachments/assets/e5fa02f3-e7c1-43ee-9102-a624a98eb231

I'm not sure if this still is a TinyUSB related issue.
BR

@Jason2866
Copy link
Collaborator

Jason2866 commented Dec 22, 2024

A small example where the issue happens would be good for bug hunting.
Your project is big and has much code which can generate side effects and / or issues.
There is a low chance that any Arduino developer has the time to do bug searching in your complete project

@ChrGri
Copy link
Author

ChrGri commented Dec 22, 2024

Hello @Jason2866, the "small example" is referenced in the first message, see "The steps to reproduce this issue:"

@Jason2866
Copy link
Collaborator

@ChrGri Thx, overlooked. Is there a possibility to test when not using Windows? Dont use Windows and afaik most developers here don't use too.

@ChrGri
Copy link
Author

ChrGri commented Dec 22, 2024

@Jason2866 I've tried it on Windows 11 and Mac M1. On both machines the serial output (from CH343) stalls after a few cycles. Adding Serial.begin(115200), seems to increase the time until stall.

==============================================================================
Edit: When the serial outputs stalls, one short DTR wiggle is sufficient to wake it up again for a period of time, see video

2.mp4

==============================================================================
Edit 2:
The serial output seems to stall similarly on a regular ESP32 (non S3), when the Serial.begin() isn't called in the setup routine.

@ChrGri
Copy link
Author

ChrGri commented Dec 23, 2024

@Jason2866 The UART serial output is caused by a missing Serial.begin(), see above. Unfortunately, this doesn't help in CDC mode. In CDC the output still stalls after a few seconds when HID is activated too.
When HID output is off, CDC serial output runs reliabel.

@kbastronomics
Copy link

I am experiencing this same issue, not using TinyUSB but using schnoog/Joystick_ESP32S2@^0.9.4 instead.
my build file is very basic using what platformio uses with no external references

Processing lolin_s2_mini_release (platform: espressif32; board: lolin_s2_mini; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/lolin_s2_mini.html
PLATFORM: Espressif 32 (6.9.0) > WEMOS LOLIN S2 Mini
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20017.0 (2.0.17) 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
 - toolchain-xtensa-esp32s2 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 44 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit TCA8418 @ 1.0.2
|-- PCA95x5 @ 0.1.3
|-- TM16xx LEDs and Buttons @ 0.6.2404
|-- Adafruit GFX Library @ 1.11.11
|-- Adafruit BusIO @ 1.17.0
|-- arduino-timer @ 3.0.1
|-- Adafruit ADS1X15 @ 2.5.0
|-- Joystick_ESP32S2 @ 0.9.4
|-- ESP32Encoder @ 0.11.7
|-- DCS-BIOS @ 0.3.10
Building in release mode
Retrieving maximum program size .pio\build\lolin_s2_mini_release\firmware.elf
Checking size .pio\build\lolin_s2_mini_release\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   8.8% (used 28896 bytes from 327680 bytes)
Flash: [===       ]  25.0% (used 327790 bytes from 1310720 bytes)
============================================================================= [SUCCESS] Took 5.45 seconds =============================================================================

Environment            Status    Duration
---------------------  --------  ------------
lolin_s2_mini_release  SUCCESS   00:00:05.451

my platformio.ini is much simpler

[env:lolin_s2_mini_release]
platform = espressif32
board = lolin_s2_mini
framework = arduino
monitor_port = COM8
monitor_speed = 250000
monitor_echo = on
lib_deps = 
	adafruit/Adafruit TCA8418@^1.0.2
	hideakitai/PCA95x5@^0.1.3
	maxint-rd/TM16xx LEDs and Buttons@^0.6.2404
	adafruit/Adafruit GFX Library@^1.11.10
	adafruit/Adafruit BusIO@^1.14.5
	contrem/arduino-timer@^3.0.1
	adafruit/Adafruit ADS1X15@^2.5.0
	schnoog/Joystick_ESP32S2@^0.9.4
	madhephaestus/ESP32Encoder@^0.11.7
build_flags = 
	-DARDUINO_USB_CDC_ON_BOOT=1

HID works find on it's own, CDC Serial works find on it own.
Then I enable and Serial communications at all withing 10 seconds HID always stops functioning.

only way to get it back is to reboot the device.

My Serial device (output from DCS-BIOS) is a large amount of simulator data at 250K baud.
I have no control over that data.

I was going to try tinyUSB thinking it would be a better solution but since this is happening in more than one packing doing HID devices, I would tend to believe the issue is not Joystick_ESP32S2 nor is it tinyUSB either

@kbastronomics
Copy link

One thing I just tried was the not send HID messages with every button press but to do it one time in loop()
while this did actually make my Pots run much faster and smoother, i still withing a short time of connecting the CDC port, I loose HID

@michal2229
Copy link

michal2229 commented Jan 27, 2025

I experience the same problem on ESP32-S2 with this code. CDC + HID works for a short time, then it stalls. Disabling CDC makes HID work flawlessly. Tested on Linux.

@Jason2866 Jason2866 added Status: Needs investigation We need to do some research before taking next steps on this issue and removed Status: Awaiting triage Issue is waiting for triage labels Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs investigation We need to do some research before taking next steps on this issue
Projects
None yet
Development

No branches or pull requests

6 participants