Skip to content

Commit 16dd749

Browse files
committed
dcd/dwc2: cleanup previous pending EP0 IN transfer if a SETUP packet is received
Signed-off-by: Mengsk <[email protected]>
1 parent fedcdef commit 16dd749

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ static void edpt_disable(uint8_t rhport, uint8_t ep_addr, bool stall) {
282282
dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum];
283283

284284
if (dir == TUSB_DIR_IN) {
285-
// Only disable currently enabled non-control endpoint
286-
if ((epnum == 0) || !(dep->diepctl & DIEPCTL_EPENA)) {
285+
if (!(dep->diepctl & DIEPCTL_EPENA)) {
287286
dep->diepctl |= DIEPCTL_SNAK | (stall ? DIEPCTL_STALL : 0);
288287
} else {
289288
// Stop transmitting packets and NAK IN xfers.
@@ -841,6 +840,11 @@ static void handle_rxflvl_irq(uint8_t rhport) {
841840

842841
static void handle_epout_slave(uint8_t rhport, uint8_t epnum, dwc2_doepint_t doepint_bm) {
843842
if (doepint_bm.setup_phase_done) {
843+
// Cleanup previous pending EP0 IN transfer if any
844+
dwc2_dep_t* epin0 = &DWC2_REG(rhport)->epin[0];
845+
if (epin0->diepctl & DIEPCTL_EPENA) {
846+
edpt_disable(rhport, 0x80, false);
847+
}
844848
dcd_event_setup_received(rhport, _dcd_usbbuf.setup_packet, true);
845849
return;
846850
}
@@ -919,6 +923,11 @@ static void handle_epout_dma(uint8_t rhport, uint8_t epnum, dwc2_doepint_t doepi
919923
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
920924

921925
if (doepint_bm.setup_phase_done) {
926+
// Cleanup previous pending EP0 IN transfer if any
927+
dwc2_dep_t* epin0 = &DWC2_REG(rhport)->epin[0];
928+
if (epin0->diepctl & DIEPCTL_EPENA) {
929+
edpt_disable(rhport, 0x80, false);
930+
}
922931
dma_setup_prepare(rhport);
923932
dcd_dcache_invalidate(_dcd_usbbuf.setup_packet, 8);
924933
dcd_event_setup_received(rhport, _dcd_usbbuf.setup_packet, true);

0 commit comments

Comments
 (0)