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

KINETIS/LLD/USBHSv1: Fix USB_USE_WAIT support #342

Merged
merged 1 commit into from
Oct 24, 2022

Conversation

sigprof
Copy link
Contributor

@sigprof sigprof commented Oct 22, 2022

The USBHSv1 LLD for KINETIS was checking epc->in_cb and epc->out_cb to be non-NULL before calling _usb_isr_invoke_in_cb() and _usb_isr_invoke_out_cb(). This is not correct, because if the USB_USE_WAIT option is enabled, those ChibiOS macros do more than just invoking the callback - they also resume the thread that may be waiting for the transfer completion, and omitting the call results in that thread never getting resumed. The macros also perform the same pointer check internally before invoking the callback.

Remove the unneeded checks to make the driver work properly with any APIs enabled by USB_USE_WAIT.


Tested on Teensy 3.2 (MK20DX256) in QMK. The error was uncovered by qmk/qmk_firmware#18631 — the cleanup part of that PR removed some in_cb callback functions that were doing nothing, and the resulting code worked fine on most supported chips (e.g, various STM32 and RP2040); however, on Teensy 3.2 that change resulted in a lockup immediately after sending a single keyboard event, because the main thread waiting for the USB transfer completion was not getting resumed when the in_cb pointer was NULL.

The USBHSv1 LLD for KINETIS was checking `epc->in_cb` and `epc->out_cb`
to be non-NULL before calling `_usb_isr_invoke_in_cb()` and
`_usb_isr_invoke_out_cb()`.  This is not correct, because if the
`USB_USE_WAIT` option is enabled, those ChibiOS macros do more than just
invoking the callback - they also resume the thread that may be waiting
for the transfer completion, and omitting the call results in that
thread never getting resumed.  The macros also perform the same pointer
check internally before invoking the callback.

Remove the unneeded checks to make the driver work properly with any
APIs enabled by `USB_USE_WAIT`.
Copy link
Member

@utzig utzig left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the fix and the nice commit message!

@utzig utzig merged commit 39c230d into ChibiOS:chibios-21.11.x Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants