Skip to content

Commit

Permalink
avoid race condition enabling EP0 RX
Browse files Browse the repository at this point in the history
Even if RX_ST is reset and EP0 is set to NAK, a Setup packet can still
be received early. Don't enable receive if that happens, but instead let
the next iteration of the ISR handle it.
  • Loading branch information
tlyu committed Feb 24, 2023
1 parent 2b78fc7 commit f1a815d
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ static void usbd_ep_rx_enable (usb_dev *udev, uint8_t ep_addr)
{
(void)udev;

/* don't enable receive if a setup packet has come in */
if (0U == EP_ID(ep_addr) && (USBD_EPxCS(0U) & EPxCS_RX_ST)) {
return;
}
/* enable endpoint to receive */
USBD_EP_RX_STAT_SET(EP_ID(ep_addr), EPRX_VALID);
}
Expand Down

0 comments on commit f1a815d

Please sign in to comment.