Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/machine/machine_rp2040_usb_fix_usb_device_enumeration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package machine

import (
"device/arm"
"device/rp"
)

Expand Down Expand Up @@ -87,6 +88,7 @@ func hw_enumeration_fix_force_ls_j() {
rp.USBCTRL_REGS.USB_MUXING.Set(rp.USBCTRL_REGS_USB_MUXING_TO_DIGITAL_PAD | rp.USBCTRL_REGS_USB_MUXING_SOFTCON)

// LS_J is now forced but while loop here just to check
waitCycles(125000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiteCycles() should be added to the line above hw_enumeration_fix_finish().
As much as possible, it should be in the same form as the pico-sdk.

https://github.com/raspberrypi/pico-sdk/blob/6a7db34ff63345a7badec79ebea3aaef1712f374/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c#L130

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, waitCycle(125000) waits for about 6ms.
It might be better to use a shorter value of about 125000 / 5.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CPU clock constant?


// if timer pool disabled, or no timer available, have to busy wait.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment become broken in two parts

hw_enumeration_fix_finish()
Expand All @@ -109,3 +111,10 @@ func hw_enumeration_fix_finish() {
// Restore the pad ctrl value
padsBank0.io[dp].Set(padCtrlPrev)
}

func waitCycles(n int) {
for n > 0 {
arm.Asm("nop")
n--
}
}