-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
rp2: Fix USB PLL glitch during wake from light sleep. #15301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rp2: Fix USB PLL glitch during wake from light sleep. #15301
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #15301 +/- ##
=======================================
Coverage 98.42% 98.42%
=======================================
Files 161 161
Lines 21248 21248
=======================================
Hits 20914 20914
Misses 334 334 ☔ View full report in Codecov by Sentry. |
Code size report:
|
Maybe we should report this to pico-sdk, and potentially they can add this argument to But for now, patching it here is OK. Can you please split out the addition of our copy of |
Adapts pico-sdk clocks_init() into clocks_init_optional_usb() which takes an argument to initialise USB clocks or not. To avoid a code size increase the SDK clocks_init() function is linker wrapped to become clocks_init_optional_usb(true). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Follow-up to a84c7a0, this commit works most of the time but has an intermittent bug where USB doesn't resume as expected after waking from light sleep. Turns out waking calls clocks_init() which will re-initialise the USB PLL. Most of the time this is OK but occasionally it seems like the clock glitches the USB peripheral and it stops working until the next hard reset. Adds a machine.lightsleep() test that consistently hangs in the first two dozen iterations on rp2 without this fix. Passed over 100 times in a row with this fix. The test is currently rp2-only as it seems similar lightsleep USB issues exist on other ports (both pyboard and ESP32-S3 native USB don't send any data to the host after waking, until they receive something from the host first.) This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
c1fa5e3
to
068d9bf
Compare
No worries, done. PTAL! |
In this mode, XOSC is stopped so can't really keep the USB PLL enabled. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Added one more small commit to always disable USB if going to DORMANT mode with no external oscillator. Have also raised a feature request with pico-sdk, see link above. |
All looks good, thank you! |
Follow-up to #15111, that change works most of the time but has an intermittent bug where USB doesn't resume as expected after waking from light sleep. Thanks to @GitHubsSilverBullet who reported it here: https://github.com/orgs/micropython/discussions/14401#discussioncomment-9675017
Turns out waking calls
clocks_init()
which will re-initialise the USB PLL. Most of the time this is OK but occasionally it seems like the clock glitches the USB peripheral and it stops working until the next hard reset.Adds a
machine.lightsleep()
test that consistently hangs in the first two dozen iterations of a single test run on rp2 without this fix. Passed over 100 full test runs in a row with this fix.The test is currently rp2-only as it seems similar lightsleep USB issues exist on other ports (both pyboard and ESP32-S3 native USB don't send any data to the host after waking, until they receive something from the host first.)
EDIT: Added one more small commit to always disable USB if there is no timeout (i.e. entering DORMANT mode where the external oscillator is disabled.)
This work was funded through GitHub Sponsors.