From 25ea72328249146b323843a1bd6ed070d26948bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thi=C3=A9baud=20Fuchs?= Date: Sun, 9 Jun 2024 19:29:13 +0200 Subject: [PATCH] WCH569 triggers an OUT interrupt even if it NAKs the packet --- src/wch-ch56x-lib/USBDevice/usb20.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wch-ch56x-lib/USBDevice/usb20.c b/src/wch-ch56x-lib/USBDevice/usb20.c index 05f1195..628b1c9 100644 --- a/src/wch-ch56x-lib/USBDevice/usb20.c +++ b/src/wch-ch56x-lib/USBDevice/usb20.c @@ -810,6 +810,12 @@ __attribute__((interrupt("WCH-Interrupt-fast"))) void USBHS_IRQHandler(void) { if (ep0_passthrough_enabled) { + // WCH569 will trigger an interrupt for a DATA packet, even if RX_CTRL was set to NAK + // discard this packet, as even though data has been received it shouldn't be taken into account + if (R8_UEP0_RX_CTRL & (UEP_R_RES_NAK | UEP_R_RES_STALL)) + { + break; + } usb2_out_transfer_handler(usb_dev_endp); } else @@ -832,6 +838,12 @@ __attribute__((interrupt("WCH-Interrupt-fast"))) void USBHS_IRQHandler(void) } else if (usb_pid == PID_OUT) { + // WCH569 will trigger an interrupt for a DATA packet, even if RX_CTRL was set to NAK + // discard this packet, as even though data has been received it shouldn't be taken into account + if (*usb2_get_rx_endpoint_ctrl_reg(usb_dev_endp) & (UEP_R_RES_NAK | UEP_R_RES_STALL)) + { + break; + } usb2_out_transfer_handler(usb_dev_endp); } break;