-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add support for HSE bypass and CSS #156
Conversation
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.
Hey thanks for stepping forward and trying to fix this issue.
I'm not sure if we should use a use_hse_crystal()
and a use_hse_bypass()
, which both accept a frequency. These options are mutually exclusive.
I would prefer use_hse().bypass_crystal()
maybe? Or something similar.
Thank you for the comparison to the different stm32 APIs!
As an ad hoc solution I would prefer the one from 'h7xx'.
A bit off-topic for this PR:
But I think an API rework has to be done for the rcc pll
configuration.
For example, wrong configurations are resulting into panics (which I'm trying to address in #153).
But this is not an ideal solution. I would also like to prefer an API, which lets us easily create / calculate the PLL configuration in a separate function, which potentially could be executed in a const
context (when const fn
has enough stable features available).
In conclusion:
For this PR, the h7xx
-solution is sufficient.
But for a major API rework I would prefer the g0xx, g4xx
approach, even though it looks ugly. Maybe the 'f7xx' approach as an alternative, which doesn't seem as flexible, but looks cleaner.
I'll have to investigate.
Thanks for the documentation improvements! They are much appreciated, as they are easily overlooked.
} | ||
|
||
/// Enable CSS (Clock Security System). | ||
/// No effect if HSE is not enabled. |
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.
Maybe add a note, that a CSS Event can be catched via CSSI (RM0316 9.2.7)?
src/rcc.rs
Outdated
/// Enable HSE (external clock) in bypass mode. | ||
/// Uses user provided clock instead of HSI (internal RC oscillator) as the clock source. | ||
/// Will result in a hang if an external clock source is not connected. | ||
pub fn use_hse_bypass<F>(mut self, freq: F) -> Self |
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.
Maybe make it more clear, what the purpose of the bypass mode is?
I had to google to understand, what hse_bypass is for.
HSE crystal oscillator bypassed with external clock
is used for the documentation of the bypass flag.
Maybe:
/// Enable HSE (external clock) in bypass mode. | |
/// Uses user provided clock instead of HSI (internal RC oscillator) as the clock source. | |
/// Will result in a hang if an external clock source is not connected. | |
pub fn use_hse_bypass<F>(mut self, freq: F) -> Self | |
/// Enable HSE (external clock) in bypass mode. | |
/// Uses user provided clock instead of a crystal oscillator. | |
/// Will result in a hang if an external clock source is not connected. | |
pub fn use_hse_bypass<F>(mut self, freq: F) -> Self |
Which makes it more clear, that with bypass mode enabled, the microcontroller won't drive the XTAL pins anymore, as it would do, if an external crystal would be present and (bypass mode inactive).
I don't like the word crystal, since there are alternative oscillators like MEMS. Given most people won't have bypass enabled, and things work fine if you're using a bypassable oscillator but don't set the bypass (Consequence is not freeing up the pin for GPIO, and extra power use), I don't think we should force an explicit specification. Eg I like a method with concise syntax like |
See #159 |
What alternatvie would you suggest to differentiate between oscillators, which have to be driven and active clocks (for which the bypass mode is used)? |
|
815de37
to
d10a122
Compare
Updated to h7xx style as a temporal solution. I agree that more explicit APIs (such as g0xx, g4xx approach and #159) would be better. |
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.
Will merge after CI is all green (rustfmt)
d10a122
to
bd9f858
Compare
Fixed. However, IDK why rustfmt is complaining about Lines 604 to 607 in d10a122
while Lines 257 to 264 in 92d9357
is allowed. |
I'd suggest using an auto linter and just let it do its thing so one gets used to the default style. |
|
Fix #142.
However, APIs for the same thing are vary in all stm32-rs HALs... Are there any suggestions?