Skip to content

Commit

Permalink
WIP delay clearing EP_RX_ST
Browse files Browse the repository at this point in the history
Avoid a race condition by delaying clearing EP_RX_ST on EP0 until the
packet buffer has been read.
  • Loading branch information
tlyu committed Nov 30, 2022
1 parent 07821c4 commit 96121af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ OF SUCH DAMAGE.

#include "usbd_enum.h"
#include "usbd_transc.h"
#include "usbd_lld_regs.h"

/* local function prototypes ('static') */
static inline void usb_stall_transc (usb_dev *udev);
Expand All @@ -56,8 +57,12 @@ void _usb_setup_transc (usb_dev *udev, uint8_t ep_num)

usb_reqsta reqstat = REQ_NOTSUPP;

/* Force to IDLE state, to cancel actions by any pending completion handlers. */
udev->control.ctl_state = USBD_CTL_IDLE;

uint16_t count = udev->drv_handler->ep_read((uint8_t *)(&udev->control.req), 0U, (uint8_t)EP_BUF_SNG);

USBD_EP_RX_ST_CLEAR(ep_num);
if (count != USB_SETUP_PACKET_LEN) {
udev->drv_handler->err(count);
usb_stall_transc(udev);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ void usbd_isr (void)
/* handle the USB OUT direction transaction */
if (USBD_EPxCS(ep_num) & EPxCS_RX_ST) {
/* clear successful receive interrupt flag */
USBD_EP_RX_ST_CLEAR(ep_num);
if (0U != ep_num) {
USBD_EP_RX_ST_CLEAR(ep_num);
}

if (USBD_EPxCS(ep_num) & EPxCS_SETUP) {

Expand All @@ -132,6 +134,10 @@ void usbd_isr (void)

uint16_t count = udev->drv_handler->ep_read (transc->xfer_buf, ep_num, (uint8_t)EP_BUF_SNG);

if (0U == ep_num) {
USBD_EP_RX_ST_CLEAR(ep_num);
}

transc->xfer_buf += count;
transc->xfer_count += count;

Expand Down

0 comments on commit 96121af

Please sign in to comment.