From c671969e8d162e40bb5ed449bca85147a45bab61 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Sat, 22 Oct 2022 16:40:07 +0300 Subject: [PATCH] MIMXRT1062/LLD/USBHSv1: Fix `USB_USE_WAIT` support 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. --- .../MIMXRT1062/LLD/USBHSv1/hal_usb_lld.c | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/os/hal/ports/MIMXRT1062/LLD/USBHSv1/hal_usb_lld.c b/os/hal/ports/MIMXRT1062/LLD/USBHSv1/hal_usb_lld.c index e4752c181b..ccde0f6499 100644 --- a/os/hal/ports/MIMXRT1062/LLD/USBHSv1/hal_usb_lld.c +++ b/os/hal/ports/MIMXRT1062/LLD/USBHSv1/hal_usb_lld.c @@ -308,7 +308,6 @@ static usb_status_t device_ep0_control_callback(usb_device_handle handle, if (direction == USB_OUT) { printf_debug(" complete, OUT ep=%d (OUT), rxbuf=%x", ep, epc->out_state->rxbuf); - (usbp)->receiving &= ~(1 << ep); USBOutEndpointState *osp = epc->out_state; osp->rxcnt = message->length; @@ -317,19 +316,14 @@ static usb_status_t device_ep0_control_callback(usb_device_handle handle, /* Endpoint Receive Complete Event */ /* Transfer Direction OUT */ - if (epc->out_cb != NULL) { - printf_debug(" invoking out_cb for ep %d", ep); - _usb_isr_invoke_out_cb(usbp, ep); - } + printf_debug(" invoking out_cb for ep %d", ep); + _usb_isr_invoke_out_cb(usbp, ep); } else if (direction == USB_IN) { printf_debug(" complete, IN ep=%d (IN), txbuf=%x", ep, epc->in_state->txbuf); - (usbp)->transmitting &= ~(1 << ep); /* Endpoint Transmit Complete Event */ /* Transfer Direction IN */ - if (epc->in_cb != NULL) { - printf_debug(" invoking in_cb for ep %d", ep); - _usb_isr_invoke_in_cb(usbp, ep); - } + printf_debug(" invoking in_cb for ep %d", ep); + _usb_isr_invoke_in_cb(usbp, ep); } return kStatus_USB_Success; @@ -468,7 +462,6 @@ static usb_status_t device_epN_control_callback(usb_device_handle handle, if (direction == USB_OUT) { printf_debug(" complete, OUT ep=%d (OUT), rxbuf=%x", ep, epc->out_state->rxbuf); - (usbp)->receiving &= ~(1 << ep); USBOutEndpointState *osp = epc->out_state; osp->rxcnt = message->length; @@ -476,19 +469,14 @@ static usb_status_t device_epN_control_callback(usb_device_handle handle, /* Endpoint Receive Complete Event */ /* Transfer Direction OUT */ - if (epc->out_cb != NULL) { - printf_debug(" invoking out_cb for ep %d", ep); - _usb_isr_invoke_out_cb(usbp, ep); - } + printf_debug(" invoking out_cb for ep %d", ep); + _usb_isr_invoke_out_cb(usbp, ep); } else if (direction == USB_IN) { printf_debug(" complete, IN ep=%d (IN), txbuf=%x", ep, epc->in_state->txbuf); - (usbp)->transmitting &= ~(1 << ep); /* Endpoint Transmit Complete Event */ /* Transfer Direction IN */ - if (epc->in_cb != NULL) { - printf_debug(" invoking in_cb for ep %d", ep); - _usb_isr_invoke_in_cb(usbp, ep); - } + printf_debug(" invoking in_cb for ep %d", ep); + _usb_isr_invoke_in_cb(usbp, ep); } return kStatus_USB_Success; }