Skip to content

Commit

Permalink
Wait until the device mode change takes effect in init_bus()
Browse files Browse the repository at this point in the history
This fixes occasional initialization errors where we could attempt to
access dctl before the mode change has taken effect, triggering a mode
mismatch interrupt and causing our configuration changes not to have
taken effect.

The STMicro docs indicate that the mode change may take up to 25ms to
take effect.
  • Loading branch information
simpkins committed Apr 16, 2024
1 parent 4bab7dc commit 0093878
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ impl<'d> State<'d> {
unsafe { w.usbtrdtim().bits(5) }
});

// Setting the forcedevmode() flag in gusbcfg may take up to 25ms to take effect.
// Loop until we see the correct mode reflected in gintsts.
// If we don't wait here, we will get a modemis interrupt later when we try to update dctl.
while self.usb0.gintsts().read().curmod_int().bit_is_set() {}

// Clear overrides in the OTG configuration
self.usb0.gotgctl().modify(|_, w| {
w.bvalidovval()
Expand Down

0 comments on commit 0093878

Please sign in to comment.