Hub enumeration reliability improvements #3371
Open
+51
−25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



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_MAXis 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
#3Start 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.