Skip to content

Commit c4de195

Browse files
committed
machine/rp2040: always use the USB device enum fix, even in chips that supposedly have the HW fix.
Additionally, correct the amount of time spent waiting after USB reset, based on advice from @sago35 Signed-off-by: deadprogram <[email protected]>
1 parent 75aca0f commit c4de195

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/machine/machine_rp2040_usb_fix_usb_device_enumeration.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ import (
88
)
99

1010
// https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c
11+
// According to errata RP2040-E5:
12+
// "It is safe (and inexpensive) to enable the software workaround even when using versions of RP2040
13+
// which include the fix in hardware."
14+
// So let us always use the software fix.
1115
func fixRP2040UsbDeviceEnumeration() {
12-
13-
// Actually check for B0/B1 h/w
14-
if ChipVersion() == 1 {
15-
// After coming out of reset, the hardware expects 800us of LS_J (linestate J) time
16-
// before it will move to the connected state. However on a hub that broadcasts packets
17-
// for other devices this isn't the case. The plan here is to wait for the end of the bus
18-
// reset, force an LS_J for 1ms and then switch control back to the USB phy. Unfortunately
19-
// this requires us to use GPIO15 as there is no other way to force the input path.
20-
// We only need to force DP as DM can be left at zero. It will be gated off by GPIO
21-
// logic if it isn't func selected.
22-
23-
// Wait SE0 phase will call force ls_j phase which will call finish phase
24-
hw_enumeration_fix_wait_se0()
25-
}
16+
// After coming out of reset, the hardware expects 800us of LS_J (linestate J) time
17+
// before it will move to the connected state. However on a hub that broadcasts packets
18+
// for other devices this isn't the case. The plan here is to wait for the end of the bus
19+
// reset, force an LS_J for 1ms and then switch control back to the USB phy. Unfortunately
20+
// this requires us to use GPIO15 as there is no other way to force the input path.
21+
// We only need to force DP as DM can be left at zero. It will be gated off by GPIO
22+
// logic if it isn't func selected.
23+
24+
// Wait SE0 phase will call force ls_j phase which will call finish phase
25+
hw_enumeration_fix_wait_se0()
2626
}
2727

2828
func hw_enumeration_fix_wait_se0() {
@@ -87,8 +87,8 @@ func hw_enumeration_fix_force_ls_j() {
8787
// Switch to GPIO phy with LS_J forced
8888
rp.USBCTRL_REGS.USB_MUXING.Set(rp.USBCTRL_REGS_USB_MUXING_TO_DIGITAL_PAD | rp.USBCTRL_REGS_USB_MUXING_SOFTCON)
8989

90-
// LS_J is now forced but while loop here just to check
91-
waitCycles(125000)
90+
// LS_J is now forced but while loop to wait ~800us here just to check
91+
waitCycles(25000)
9292

9393
// if timer pool disabled, or no timer available, have to busy wait.
9494
hw_enumeration_fix_finish()

0 commit comments

Comments
 (0)