Skip to content

feat(hub): Added support for multiple root ports#389

Merged
tore-espressif merged 3 commits intomasterfrom
feat/hub_multi_root_port
Feb 10, 2026
Merged

feat(hub): Added support for multiple root ports#389
tore-espressif merged 3 commits intomasterfrom
feat/hub_multi_root_port

Conversation

@tore-espressif
Copy link
Collaborator

@tore-espressif tore-espressif commented Jan 26, 2026

This will allow having both FS and HS root ports active at the same time and connected devices working properly.


Note

Medium Risk
Touches core USB host hub/enumeration plumbing and root-port state management, which can affect device attach/detach, enumeration ordering, and suspend/resume behavior across ports. Changes are scoped but concurrency/ISR-driven paths and multi-port edge cases increase regression risk.

Overview
Adds multi-root-port support across the USB host stack. The Hub driver now initializes/powers multiple HCD root ports based on hub_config->port_map, tracks per-port state/requests, and routes ISR events and recovery/disable actions per root port.

Makes devices root-port aware end-to-end. Device tree nodes and usbh_devs_add() now associate devices with a specific root_port_hdl, adds usbh_dev_get_root_port_hdl() and ext_hub_get_root_port(), and tightens the “address 0” constraint to only conflict within the same root port.

Improves enumeration scheduling for multi-port scenarios. Enumeration starts by UID via new usbh_devs_open_uid(), and adds a small pending-UID queue so concurrent attach events enqueue and enumerate sequentially (returning ESP_ERR_NO_MEM if the queue is full).

Test/build updates. Moves/standardizes test port/PHY selection macros, adjusts an isoch test to use TEST_PORT_NUM, bumps a CDC test leak threshold, and adds a Linux mock define for SOC_USB_OTG_PERIPH_NUM.

Written by Cursor Bugbot for commit f456438. This will update automatically on new commits. Configure here.

@tore-espressif tore-espressif self-assigned this Jan 26, 2026
Copy link
Collaborator

@peter-marcisovsky peter-marcisovsky left a comment

Choose a reason for hiding this comment

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

Leaving some minor comments. I tested on the HW, working fine.

Copy link
Collaborator Author

@tore-espressif tore-espressif left a comment

Choose a reason for hiding this comment

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

@peter-marcisovsky thank you for the review! I fixed the easy comments and left few open, PTAL!

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Copy link
Collaborator

@peter-marcisovsky peter-marcisovsky left a comment

Choose a reason for hiding this comment

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

LGTM, nice addition. I will test bit more on HW.

@peter-marcisovsky
Copy link
Collaborator

Before merging this, we should wait for the #393 to be merged and usb component v1.2 released. Not to include this changes to the v1.2 release.

@tore-espressif tore-espressif added this to the usb_host 1.3.0 milestone Feb 5, 2026
This will allow having both FS and HS root ports active at the same time
and connected devices working properly.
@tore-espressif tore-espressif added Component: usb_host Issue affects usb_host component BUILD_AND_TEST_IDF_EXAMPLES Build and run esp-idf usb host and device examples in PR BUILD_AND_TEST_ALL_APPS Build and test all apps even if no related code has changed. labels Feb 10, 2026
@tore-espressif tore-espressif force-pushed the feat/hub_multi_root_port branch from 74501cf to 82ace30 Compare February 10, 2026 08:08
@igi540
Copy link
Collaborator

igi540 commented Feb 10, 2026

Overall the multi-port refactor looks solid. One small robustness suggestion: there are a few places where we rely on assert() / abort() to guard conditions that could potentially be hit in non-debug builds (where asserts may be compiled out). To make this safer in production configs, could we convert those into regular HUB_DRIVER_CHECK(_FROM_CRIT) / graceful error returns (and keep assert() only for true internal invariants)? This would help avoid any chance of a NULL deref or unexpected abort if configuration/state ever deviates.

@tore-espressif tore-espressif merged commit 48d3c83 into master Feb 10, 2026
72 checks passed
@tore-espressif tore-espressif deleted the feat/hub_multi_root_port branch February 10, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BUILD_AND_TEST_ALL_APPS Build and test all apps even if no related code has changed. BUILD_AND_TEST_IDF_EXAMPLES Build and run esp-idf usb host and device examples in PR Component: usb_host Issue affects usb_host component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants