Skip to content

Commit f01a725

Browse files
atxgalak
authored andcommitted
drivers: usb_dc_stm32: Reinitialize the write semaphores on bus reset
If the user attempts to send data before the USB connection is established (see the HID sample for an example of such code), the DataInCallback never gets called which leaves the write semaphore in a taken state forever. Signed-off-by: Josef Gajdusek <[email protected]>
1 parent 29ffcae commit f01a725

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/usb/device/usb_dc_stm32.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,12 +880,21 @@ int usb_dc_reset(void)
880880

881881
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
882882
{
883+
int i;
884+
883885
LOG_DBG("");
884886

885887
HAL_PCD_EP_Open(&usb_dc_stm32_state.pcd, EP0_IN, EP0_MPS, EP_TYPE_CTRL);
886888
HAL_PCD_EP_Open(&usb_dc_stm32_state.pcd, EP0_OUT, EP0_MPS,
887889
EP_TYPE_CTRL);
888890

891+
/* The DataInCallback will never be called at this point for any pending
892+
* transactions. Reset the IN semaphores to prevent perpetual locked state.
893+
* */
894+
for (i = 0; i < DT_USB_NUM_BIDIR_ENDPOINTS; i++) {
895+
k_sem_give(&usb_dc_stm32_state.in_ep_state[i].write_sem);
896+
}
897+
889898
if (usb_dc_stm32_state.status_cb) {
890899
usb_dc_stm32_state.status_cb(USB_DC_RESET, NULL);
891900
}

0 commit comments

Comments
 (0)