ch32: remove redundant EP toggle check Signed-off-by: HiFiPhile <admin@hifiphile.com>
diff --git a/src/portable/wch/dcd_ch32_usbhs.c b/src/portable/wch/dcd_ch32_usbhs.c index d531feb..f04f9aa 100644 --- a/src/portable/wch/dcd_ch32_usbhs.c +++ b/src/portable/wch/dcd_ch32_usbhs.c
@@ -102,16 +102,12 @@ } } -static void update_out(uint8_t rhport, uint8_t ep_num, uint16_t rx_len, bool is_tog_ok) { +static void update_out(uint8_t rhport, uint8_t ep_num, uint16_t rx_len) { xfer_ctl_t* xfer = XFER_CTL_BASE(ep_num, TUSB_DIR_OUT); if (!xfer->valid) { return; } - if (!is_tog_ok && ep_num != 0 && !xfer->is_iso) { - return; - } - uint16_t remaining = xfer->total_len - xfer->queued_len; uint16_t len = TU_MIN(rx_len, TU_MIN(remaining, xfer->max_size)); @@ -423,19 +419,21 @@ uint32_t frame_count = USBHSD->FRAME_NO & USBHS_FRAME_NO_NUM_MASK; dcd_event_sof(rhport, frame_count, true); } - } else if (token == USBHS_TOKEN_PID_OUT) { + // Drop an OUT packet whose data toggle doesn't match what we expect -- a host retransmit + // after a lost ACK, or a host that doesn't alternate DATA0/DATA1. + } else if (token == USBHS_TOKEN_PID_OUT && (int_status & USBHS_DEV_UIS_TOG_OK)) { if (ep_num != 0) { // Release early: ISO transfers ignore INT_BUSY and would overwrite // the shared INT_ST/RX_LEN of this pending completion. xfer_ctl_t const *const out = XFER_CTL_BASE(ep_num, TUSB_DIR_OUT); // Keep the receive armed if update_out() rejects this packet's toggle. - if (!out->is_iso && (int_status & USBHS_TOG_MATCH) != 0) { + if (!out->is_iso) { EP_RX_CTRL(ep_num) = (EP_RX_CTRL(ep_num) & ~(USBHS_EP_R_RES_MASK)) | USBHS_EP_R_RES_NAK; } USBHSD->INT_FG = USBHS_TRANSFER_FLAG; released = true; } - update_out(rhport, ep_num, len, (int_status & USBHS_TOG_MATCH) != 0); + update_out(rhport, ep_num, len); } else if (token == USBHS_TOKEN_PID_IN) { if (ep_num != 0) { // Release early, as for OUT.