Skip to content

Commit 1184c7b

Browse files
committed
fix(rp2): process USB IN completions before OUT transfers
Without the mscStateStatusSent shortcut in the MSC state machine, the CSW IN-completion must be observed before the next CBW OUT packet. When both land in the same BUFF_STATUS snapshot the OUT-first loop delivered the CBW while the state machine was still in StatusSent, silently dropping it and wedging the host. Process IN completions first, mirroring the nrf52840 EPDATA handler ordering.
1 parent 80c62ec commit 1184c7b

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/machine/machine_rp2040_usb.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,21 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
9292
s2 := rp.USBCTRL_REGS.BUFF_STATUS.Get()
9393
rp.USBCTRL_REGS.BUFF_STATUS.Set(s2)
9494

95-
// OUT (PC -> rp2040)
95+
// IN (rp2040 -> PC)
9696
for i := 0; i < 16; i++ {
97-
if s2&(1<<(i*2+1)) > 0 {
98-
buf := handleEndpointRx(uint32(i))
99-
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
100-
AckUsbOutTransfer(uint32(i))
97+
if s2&(1<<(i*2)) > 0 {
98+
if usbTxHandler[i] != nil {
99+
usbTxHandler[i]()
101100
}
102101
}
103102
}
104103

105-
// IN (rp2040 -> PC)
104+
// OUT (PC -> rp2040)
106105
for i := 0; i < 16; i++ {
107-
if s2&(1<<(i*2)) > 0 {
108-
if usbTxHandler[i] != nil {
109-
usbTxHandler[i]()
106+
if s2&(1<<(i*2+1)) > 0 {
107+
buf := handleEndpointRx(uint32(i))
108+
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
109+
AckUsbOutTransfer(uint32(i))
110110
}
111111
}
112112
}

src/machine/machine_rp2350_usb.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,21 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
9595
s2 := rp.USB.BUFF_STATUS.Get()
9696
rp.USB.BUFF_STATUS.Set(s2)
9797

98-
// OUT (PC -> rp2350)
98+
// IN (rp2350 -> PC)
9999
for i := 0; i < 16; i++ {
100-
if s2&(1<<(i*2+1)) > 0 {
101-
buf := handleEndpointRx(uint32(i))
102-
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
103-
AckUsbOutTransfer(uint32(i))
100+
if s2&(1<<(i*2)) > 0 {
101+
if usbTxHandler[i] != nil {
102+
usbTxHandler[i]()
104103
}
105104
}
106105
}
107106

108-
// IN (rp2350 -> PC)
107+
// OUT (PC -> rp2350)
109108
for i := 0; i < 16; i++ {
110-
if s2&(1<<(i*2)) > 0 {
111-
if usbTxHandler[i] != nil {
112-
usbTxHandler[i]()
109+
if s2&(1<<(i*2+1)) > 0 {
110+
buf := handleEndpointRx(uint32(i))
111+
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
112+
AckUsbOutTransfer(uint32(i))
113113
}
114114
}
115115
}

0 commit comments

Comments
 (0)