-
Notifications
You must be signed in to change notification settings - Fork 1
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
rcc: Calculate PLL clocks and implement core clock configuration logic #13
Conversation
b4b0156
to
35c582a
Compare
9375aa5
to
21b6790
Compare
9db330c
to
b6a314f
Compare
let output_q = vco_ck_achieved as f32 / pll_x_q as f32; | ||
println!("Q Divider {}", pll_x_q); | ||
println!("==> Output Q {} MHz", output_q / 1e6); | ||
println!(); |
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.
Ideally there would be an assert!
statements to check the values here
This is by necessity quite complex and error-prone logic, and at a first review it looks good! The two options for |
Looking back at the patch I originally made to address the error I found, it looks like because the H7 VCO derivation chooses the maximum output frequency for the VCO (see here), it looks like if a high enough frequency is chosen for the system clock, which is then derived from PLL1, it's not possible to select frequencies in the low megahertz range on a different PLL (divider is >128). For instance, the It looks like the patch I made (last year, so my memory is a bit fuzzy) ended up becoming quite a bit more extensive than just addressing that, so the VCO setup here is quite a bit different than the H7 code. |
Aha, I ignored the use case of PLL outputs with frequencies of the (max VCO frequency/128) or less. Nice that you've improved that. Thanks for adding the tests. |
0a405b4
to
5da38aa
Compare
5da38aa
to
ed0f200
Compare
This implements the PLL and clock configuration logic for the processor using the RCC peripheral.
pll
module is responsible for configuring the VCOs and setting up the PLL dividers for the desired frequencyfreeze
method in thercc
module does the heavy lifting for making sure that the processor clocks are configured in the desired mannerNote: This is largely copied from the implementation in stm32h7xx-hal, although it significantly refactors and modifies the PLL configuration in the
pll
module. This was mostly due to the differences in the register definitions used by the calculation and the fact that the H5 family (and especially the H503 MCU) is quite a bit simpler than the H7 family. I made significant changes to the the PLL configuration due to the stm32h7xx-hal crate being a bit bugged: it calculates values for Q and R outputs that are invalid for fractional PLL configurations.