Skip to content

Conversation

@HiFiPhile
Copy link
Collaborator

@HiFiPhile HiFiPhile commented Nov 26, 2025

Describe the PR
I've made 3 hub enumeration reliability improvements, they works well here but not sure if there are any edge case.

  • Stop enumeration gracefully if EP0 can't be open
    When CFG_TUH_FSDEV_ENDPOINT_MAX is not enough, usbh_edpt_control_open() fails and the hub become stuck.

    With quick plug/unplug sometimes old endpoint release happens after new endpoint open. Normally my config only needs 15 EPs (3 for hub + 4 for keyboard + 4 for USB key + 4 for FTDI) but I hit assert(usbh_edpt_control_open()) with total 16 EPs.
    ---> Fixed by #3

  • Start hub status transfer before driver config
    At the end of enumeration driver config is launched by usbh_driver_set_config_complete(), if the device is bouncing and transfer failed, enum_full_complete() is not called (especially MSC needs some time to init) leaving hub in stuck.

    I've also made enum_full_complete(bool success) to avoid triggering a 2nd hub status in case of success, which cause some wieldiness stuff.

  • Detach existing device first if an attach event is received
    Previously old device is not removed until ENUM_SET_ADDR, remove the device before EP0 opening can lower endpoint usage.

Copilot AI review requested due to automatic review settings November 26, 2025 22:38
Copilot finished reviewing on behalf of HiFiPhile November 26, 2025 22:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves hub enumeration reliability by addressing two edge cases that could cause the hub to become stuck during device enumeration:

  1. Graceful handling of EP0 open failures: When usbh_edpt_control_open() fails (e.g., when CFG_TUH_FSDEV_ENDPOINT_MAX is exhausted or during quick plug/unplug scenarios), enumeration now stops gracefully by calling enum_full_complete(false) and cleaning up device state, rather than triggering a hard assertion that leaves the hub stuck.

  2. Earlier hub status transfer initiation: Hub status transfers are now initiated immediately when a device is configured (before driver initialization), rather than waiting until after all drivers complete their set_config() callbacks. This prevents the hub from getting stuck when a driver's set_config() fails or stalls (e.g., MSC devices that take time to initialize).


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants