diff --git a/system/GD32F30x_firmware/GD32F30x_usbd_library/device/Source/usbd_transc.c b/system/GD32F30x_firmware/GD32F30x_usbd_library/device/Source/usbd_transc.c index 90ba660f..837ee1b8 100644 --- a/system/GD32F30x_firmware/GD32F30x_usbd_library/device/Source/usbd_transc.c +++ b/system/GD32F30x_firmware/GD32F30x_usbd_library/device/Source/usbd_transc.c @@ -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); @@ -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); diff --git a/system/GD32F30x_firmware/GD32F30x_usbd_library/usbd/Source/usbd_lld_int.c b/system/GD32F30x_firmware/GD32F30x_usbd_library/usbd/Source/usbd_lld_int.c index 7fa68384..57572541 100644 --- a/system/GD32F30x_firmware/GD32F30x_usbd_library/usbd/Source/usbd_lld_int.c +++ b/system/GD32F30x_firmware/GD32F30x_usbd_library/usbd/Source/usbd_lld_int.c @@ -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) { @@ -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;