Skip to content

Commit 4328d19

Browse files
author
rdon
committed
fix(rp2350): port USB SetAddressRequest using hardware timer to rp2350
1 parent 7f9e352 commit 4328d19

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/machine/machine_rp2350_usb.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,20 @@ func initEndpoint(ep, config uint32) {
172172
}
173173

174174
func handleUSBSetAddress(setup usb.Setup) bool {
175+
rp.USB.SIE_STATUS.Set(rp.USB_SIE_STATUS_ACK_REC)
175176
sendUSBPacket(0, []byte{}, 0)
176177

177-
// last, set the device address to that requested by host
178-
// wait for transfer to complete
179-
timeout := 3000
180-
rp.USB.SIE_STATUS.Set(rp.USB_SIE_STATUS_ACK_REC)
181-
for (rp.USB.SIE_STATUS.Get() & rp.USB_SIE_STATUS_ACK_REC) == 0 {
182-
timeout--
183-
if timeout == 0 {
184-
return true
185-
}
178+
// Wait for transfer to complete with a timeout.
179+
// Using 570μs timeout which is exactly the same as SAMD21.
180+
181+
if !timer.waitUntil(func() bool {
182+
return (rp.USB.SIE_STATUS.Get() & rp.USB_SIE_STATUS_ACK_REC) != 0
183+
}, 570) {
184+
return false
186185
}
187186

187+
// Set the device address to that requested by host.
188188
rp.USB.ADDR_ENDP.Set(uint32(setup.WValueL) & rp.USB_ADDR_ENDP_ADDRESS_Msk)
189-
190189
return true
191190
}
192191

0 commit comments

Comments
 (0)