Skip to content

feat(usb_device): Config::port to pick the USB-OTG port (ESP32-P4) - #802

Merged
finger563 merged 1 commit into
mainfrom
feat/usb-device-port
Sep 20, 2026
Merged

finger563 merged 1 commit into
mainfrom
feat/usb-device-port

Conversation

@finger563

Copy link
Copy Markdown
Contributor

Summary

  • UsbDevice::Config::port (default -1 = TinyUSB's default for the target) selects the USB-OTG peripheral through esp_tinyusb's tinyusb_config_t.port, validated against TINYUSB_PORT_MAX.
  • Motivation: on the ESP32-P4 TinyUSB defaults to the high-speed (OTG 2.0) port, but boards do not always route it to a device-capable connector. The M5Stack Tab5 wires the high-speed port to its USB-A host jack, and its USB-C carries the full-speed port (shared with the USB-Serial-JTAG console), so a device application there has to pick port 0.

Test plan

  • tab5-emu (M5Stack Tab5): MSC over port = 0 enumerates on the Mac after the application swaps OTG 1.1 onto FSLS PHY 0 (LP_SYS.usb_ctrl); the SD card mounts as a drive and hands back to the application.
  • Default (port = -1) leaves TINYUSB_DEFAULT_CONFIG() untouched.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BAeyJSuzVyqvSe4mffGUZo

esp_tinyusb's tinyusb_config_t.port selects the peripheral on targets with
two USB-OTG controllers; TinyUSB defaults to the high-speed port on the
ESP32-P4. Boards do not always route that port to a device-capable
connector (the M5Stack Tab5 wires it to its USB-A host jack; its USB-C
carries the full-speed port), so let the application choose: -1 keeps the
TinyUSB default, otherwise the value is validated against TINYUSB_PORT_MAX
and passed through.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BAeyJSuzVyqvSe4mffGUZo
Copilot AI lite review requested due to automatic review settings September 20, 2026 04:59
@github-actions

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Fix validation for values below -1 and update the published documentation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Adds configurable USB-OTG port selection for UsbDevice, primarily supporting ESP32-P4 boards.

Changes:

  • Adds Config::port with -1 preserving TinyUSB’s default.
  • Applies selected port configuration and documents ESP32-P4/Tab5 usage.
  • Requires stricter validation and documentation updates before approval.
File Summary Findings
components/​usb_device/​src/​usb_device.cpp Applies the selected TinyUSB port. Moderate: reject values below -1 (3 votes).
components/​usb_device/​README.md Documents port selection and the Tab5 use case. Nit: update linked usb_cdc.rst documentation (3 votes).
components/​usb_device/​include/​usb_device.hpp Adds Config::port. None.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1499 to +1500
if (config_.port >= 0) {
if (config_.port >= static_cast<int>(TINYUSB_PORT_MAX)) {
Comment on lines +82 to +85
- **Port selection** (`Config::port`): on targets with two USB-OTG
controllers (ESP32-P4) pick the full-speed or the high-speed port; boards do
not always route the high-speed port to a device-capable connector (the
M5Stack Tab5's USB-C carries the full-speed port).
@finger563
finger563 merged commit 80a6df0 into main Sep 20, 2026
166 checks passed
@finger563
finger563 deleted the feat/usb-device-port branch September 20, 2026 05:19
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