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

MIMXRT1062/LLD/USBHSv1: Fix USB_USE_WAIT support #343

Merged
merged 1 commit into from
Oct 24, 2022

Conversation

sigprof
Copy link
Contributor

@sigprof sigprof commented Oct 22, 2022

The USBHSv1 LLD for MIMXRT1062 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. Also remove the manipulation of (usbp)->receiving and (usbp)->transmitting, because the _usb_isr_invoke_in_cb() and _usb_isr_invoke_out_cb() macros handle that part too.


This change is NOT tested yet (I don't have the corresponding hardware); maybe @jtojnar (the reporter of qmk/qmk_firmware#18805) could test whether it fixes their problem instead of using a workaround which puts a dummy function pointer into in_cb (qmk/qmk_firmware#18811).

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), but broke on Arm-based Teensy boards (#342 fixes the same problem in the KINETIS driver).

Cc: @stapelberg

The USBHSv1 LLD for MIMXRT1062 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`.  Also remove the manipulation of
`(usbp)->receiving` and `(usbp)->transmitting`, because the
`_usb_isr_invoke_in_cb()` and `_usb_isr_invoke_out_cb()` macros handle
that part too.
@jtojnar
Copy link

jtojnar commented Oct 23, 2022

Thanks. Can confirm this fixes the issue on my Teensy 4.1.

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

@stapelberg
Copy link
Contributor

Thanks for sending this fix!

@utzig utzig merged commit 09ba7e6 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.

4 participants