Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] ChibiOS: Fix USB bus disconnect handling #18566

Merged
merged 1 commit into from
Oct 2, 2022

Conversation

KarlK90
Copy link
Member

@KarlK90 KarlK90 commented Oct 2, 2022

Description

usb_disconnect() previously only stopped the USB driver but didn't disconnect the device from USB bus. This is a problem with split keyboards that fail to enumerate on bootup but are actually connected to a USB bus. This can happen in the case that a short SPLIT_USB_TIMEOUT is used but it takes longer to enumerate with the host system correctly. In this condition the host system would still try to enumerate with the keyboard, as it still recognizes it as a connected device, but never succeed as we already disabled the USB driver. This in turn prevents some systems to boot-up correctly or at least slow down the boot process until the device is finally rejected by the host USB stack.

A drive-by fix is the case for rebooting a keyboard without a physical reconnect and not stopping the USB driver before starting it again - which is a violation of ChibiOS state model for the USB driver.

Demo: RP2040 split keyboard that fails to enumerate on boot

With the fix the device is disconnected properly

image

Without the fix the device is not disconnected and the host tries to enumerate until finally giving up

image

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@github-actions github-actions bot added the core label Oct 2, 2022
@KarlK90 KarlK90 force-pushed the fix/usb-bus-handling branch from 3bc6039 to bd19725 Compare October 2, 2022 12:25
@KarlK90 KarlK90 requested a review from a team October 2, 2022 12:33
usb_disconnect() previously only stopped the USB driver but didn't
disconnect the device from USB bus. This is a problem with split
keyboards that fail to enumerate on bootup but are actually connected
to a USB bus. This can happen in the case that a short `SPLIT_USB_TIMEOUT`
is used but it takes longer to enumerate with the host system correctly.
In this condition the host system would still try to enumerate with the
keyboard, as it still recognizes it as a connected device, but never
succeed as we already disabled the USB driver. This in turn prevents
some systems to boot-up correctly or at least slow down the boot process
until the device is finally rejected by the host USB stack.

A drive-by fix is the case for rebooting a keyboard without a physical
reconnect and not stopping the USB driver before starting it again -
which is a violation of ChibiOS state model for the USB driver.
@KarlK90 KarlK90 force-pushed the fix/usb-bus-handling branch from bd19725 to ee5fd01 Compare October 2, 2022 12:49
@KarlK90 KarlK90 added the bug label Oct 2, 2022
Copy link
Member

@daskygit daskygit left a comment

Choose a reason for hiding this comment

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

Can confirm it fixes the issue with my system and a kb2040. Last push also addressed the restart_usb_driver being in the reverse order.

@KarlK90
Copy link
Member Author

KarlK90 commented Oct 2, 2022

Thanks for the quick tests and approvals 🎉 I'll wait for the ci build and merge afterwards.

@KarlK90 KarlK90 merged commit 6f13a76 into qmk:develop Oct 2, 2022
@KarlK90 KarlK90 deleted the fix/usb-bus-handling branch October 2, 2022 13:35
@KarlK90 KarlK90 added the hacktoberfest-accepted All the good issues to tackle during Hacktoberfest! label Oct 2, 2022
ramonimbao pushed a commit to ramonimbao/qmk_firmware that referenced this pull request Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug core hacktoberfest-accepted All the good issues to tackle during Hacktoberfest!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants