-
Notifications
You must be signed in to change notification settings - Fork 219
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
Disable peripherals when unused #2544
Conversation
@@ -220,8 +221,8 @@ where | |||
channel.runtime_ensure_compatible(&i2s); | |||
let channel = channel.degrade(); | |||
|
|||
PeripheralClockControl::reset(i2s.peripheral()); | |||
PeripheralClockControl::enable(i2s.peripheral()); | |||
let guard = PeripheralGuard::new(i2s.peripheral()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems at one point the PeripheralGuard won over manually managing clocks. Would you consider updating AES/ADC, too?
In general, I like the idea of PeripheralGuard. I'd prefer it to be generic and zero-sized, but I don't see that happening with type erased peripherals. Maybe we could have two variants, one for ZST peripherals and one for erased ones. Looking closely at the code, I can see that this PR was done mostly mechanically, there are a few places where a guard isn't necessary (RMT, and some others), or some where it looks not entirely correct to my eyes (PARL_IO). |
.with_mosi(miso_mosi) | ||
.with_miso(miso) | ||
.with_miso(miso) // order matters | ||
.with_mosi(miso_mosi) // order matters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Orthogonal to the PR but is this something we can fix @bugadani? Seems like would be hard to spot without knowing the internals of GPIO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually addressed in #2557 I believe. Because with_miso
in that PR only sets the input signal, this won't be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well now that PR is closed, the problem is back with us 🥲
@@ -112,7 +112,8 @@ mod tests { | |||
) | |||
.map_err(|e| e.0) | |||
.unwrap(); | |||
transfer.wait(); | |||
// dropping SPI would make us see an additional edge - so let's keep SPI alive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we reset the peripheral, we also reset CTRL.D_POL ( to 1) so MOSI is idle-high
So, it looks like this:
See how MOSI is set to high after resetting (near the marker)
BTW we can also see that effect on main
before the initial transaction
There we see MOSI shows a "bump" between reset and setting D_POL to 0
f00a3c9
to
2cd70ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM, but will wait for @MabezDev to approve before merging since he had requested changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
Closes #1382
Supercedes #2484
This disables most peripherals when their driver gets fully dropped.
There are some peripherals which don't get touched
others which we currently don't explicitly enable (some of them for reasons, but not all)
Additionally, peripherals are disabled in
init
- gives us a ~ 5mA advantage when not using themTesting