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

ChibiOS USB: Add a dummy IN callback to work around LLD bugs #18811

Merged
merged 1 commit into from
Oct 22, 2022

Conversation

sigprof
Copy link
Contributor

@sigprof sigprof commented Oct 22, 2022

Description

In #18631 some IN notification callbacks that were doing nothing were removed, which should be a valid thing to do (ChibiOS HAL checks the in_cb and out_cb pointers for being non-NULL before invoking those optional callbacks). However, it turned out that some less popular USB LLDs (KINETIS and MIMXRT1062) have their own checks for those pointers, and (incorrectly) skip the ChibiOS callback handling when those pointers are NULL, which breaks the code for the USB_USE_WAIT configuration option (the waiting thread never gets resumed if the corresponding callback pointer is NULL).

Add those dummy callbacks again (but use a single function for all of them instead of individual ones for each endpoint); this restores the KINETIS and MIMXRT1062 boards to the working state while the LLDs are getting fixed.

A more in-depth analysis of what happens in the code is in #18805 (comment).

Tested on a Teensy 3.2 board (qmk flash -kb handwired/onekey/teensy_32 -km default). On that hardware without this fix the lockup happens immediately after pressing a key mapped to KC_A; this does not match the MIMXRT1062 behavior described in #18805 (where plain keys still work), but that problem should hopefully be fixed by this change too (given that a revert of #18631 helps there).

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).

In qmk#18631 some IN notification callbacks that were doing nothing were
removed, which should be a valid thing to do (ChibiOS HAL checks the
`in_cb` and `out_cb` pointers for being non-NULL before invoking those
optional callbacks).  However, it turned out that some less popular USB
LLDs (KINETIS and MIMXRT1062) have their own checks for those pointers,
and (incorrectly) skip the ChibiOS callback handling when those pointers
are NULL, which breaks the code for the `USB_USE_WAIT` configuration
option (the waiting thread never gets resumed if the corresponding
callback pointer is NULL).

Add those dummy callbacks again (but use a single function for all of
them instead of individual ones for each endpoint); this restores the
KINETIS and MIMXRT1062 boards to the working state while the LLDs are
getting fixed.
@sigprof
Copy link
Contributor Author

sigprof commented Oct 22, 2022

The actual fixes for the underlying driver bugs should be:

The KINETIS fix was minimally tested on a Teensy 3.2 (MK20DX256); ideally it should be tested on other Teensy variations which have different MCUs but still use the same driver (LC, 3.5, 3,6), but I don't have that hardware. The MIMXRT1062 fix was just compile-tested with kinesis/kint41 (for some reason there is no handwired/onekey/teensy_40 or handwired/onekey/teensy_41), again due to the lack of hardware.

When these fixes finally land in the chibios-contrib submodule, this PR could be reverted again.

Copy link
Member

@fauxpark fauxpark left a comment

Choose a reason for hiding this comment

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

ouch

@fauxpark fauxpark requested a review from a team October 22, 2022 14:09
@jtojnar
Copy link

jtojnar commented Oct 23, 2022

Thanks, can confirm that this one fixes the issue as well on Teensy 4.1.

ramonimbao pushed a commit to ramonimbao/qmk_firmware that referenced this pull request Nov 28, 2022
In qmk#18631 some IN notification callbacks that were doing nothing were
removed, which should be a valid thing to do (ChibiOS HAL checks the
`in_cb` and `out_cb` pointers for being non-NULL before invoking those
optional callbacks).  However, it turned out that some less popular USB
LLDs (KINETIS and MIMXRT1062) have their own checks for those pointers,
and (incorrectly) skip the ChibiOS callback handling when those pointers
are NULL, which breaks the code for the `USB_USE_WAIT` configuration
option (the waiting thread never gets resumed if the corresponding
callback pointer is NULL).

Add those dummy callbacks again (but use a single function for all of
them instead of individual ones for each endpoint); this restores the
KINETIS and MIMXRT1062 boards to the working state while the LLDs are
getting fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants