Skip to content

fix(usb_device): check endpoints against the selected port's USB-OTG core - #925

Merged
finger563 merged 1 commit into
mainfrom
fix/usb-device-in-endpoint-budget
Nov 23, 2026
Merged

finger563 merged 1 commit into
mainfrom
fix/usb-device-in-endpoint-budget

Conversation

@finger563

Copy link
Copy Markdown
Contributor

Fixes #924.

initialize() allowed 5 data IN endpoints on every port. The full-speed USB-OTG core (ESP32-S2 / -S3, and the ESP32-P4's port 0) has 5 IN endpoints including EP0 IN, so only 4 data IN.

Change

initialize() now checks against the limits TinyUSB's DWC2 driver enforces (its _dwc2_controller table) for the core behind the port the device will use. That port is Config::port, or esp_tinyusb's TINYUSB_DEFAULT_CONFIG() port when it is -1.

Core Where Data IN Endpoint numbers
Full-speed ESP32-S2, ESP32-S3, ESP32-P4 port 0 4 1-6
High-speed ESP32-P4 port 1 (default there), ESP32-S31 7 1-15
  • Checks: the data IN count, the highest IN endpoint number, and the highest endpoint number overall. The error names the core, the port and the limit exceeded.
  • Endpoint numbering: X-Input's OUT number is now taken after every IN endpoint, so IN numbers stay contiguous from 1. Numbers are unchanged for every combination without MSC (e.g. Vendor + X-Input stays 1 / 2 IN / 3 OUT).
  • FIFO RAM: not checked, because no combination can exceed it. Full-speed needs ~142 of 256 words; high-speed with all five functions needs ~730 of 992. A comment in the code shows the arithmetic.
  • Docs: README and docs have a per-core budget table and list which combinations fit on the full-speed core.

Testing

Built usb_device/example for ESP32-S3 and ESP32-P4, and xinput_example with sdkconfig.composite for ESP32-S3, under IDF 6.1, with no warnings. Not run on hardware.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU

…core

The IN budget allowed 5 data IN endpoints, but the full-speed USB-OTG core
(ESP32-S2 / -S3, the ESP32-P4's port 0) has 5 IN endpoints including EP0 IN:
4 data IN. CDC + Vendor + HID + MSC passed the check, then its fifth IN
endpoint failed to open at SET_CONFIGURATION and the device stayed
unconfigured (hathach/tinyusb#4450). TinyUSB also gives IN endpoint n TX
FIFO n, so an IN endpoint numbered past the FIFOs opens but never transmits
(hathach/tinyusb#4007); X-Input's separate OUT number could push a later
function's IN endpoint there (Vendor + HID + X-Input + MSC put MSC IN on 5).

initialize() now checks against the limits TinyUSB's DWC2 driver enforces
for the core behind the port the device will use (Config::port, else
esp_tinyusb's default): data IN count and highest IN number below
ep_in_count, and every endpoint number below ep_count - full-speed 4 data
IN / numbers 1-6, high-speed (ESP32-P4 port 1, its default) 7 data IN /
numbers 1-15. X-Input's OUT number is taken after every IN endpoint, so IN
numbers stay contiguous. Endpoint numbers are unchanged for every
combination without MSC. The error names the core, the port and the limit
exceeded. FIFO RAM is not a limit for any combination (comment shows why).
README + docs: per-core budget table and the combinations that fit.

Fixes #924

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
@github-actions

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

@finger563
finger563 merged commit 60c0a81 into main Nov 23, 2026
186 checks passed
@finger563
finger563 deleted the fix/usb-device-in-endpoint-budget branch November 23, 2026 01:48
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.

usb_device: IN endpoint budget is one too high for ESP32-S2/S3

1 participant