aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Mabin <[email protected]>2023-07-30 01:00:50 +0100
committerScott Mabin <[email protected]>2023-07-30 01:00:53 +0100
commite0ce7fcde7906fc219d294e858388e62ab107ec3 (patch)
tree1fef483aa7a72fed8223d11c18166cc84eec4dd1
parentfcbfd224a729c38d5ff94d94a25321a819254630 (diff)
stm32f2 pll overflow with crystal
With a large enough HSE input frequency, the vco clock calculation will overflow a u32. Therefore, in this specific case we have to use the inner value and cast to u64 to ensure the mul isn't clipped before applying the divider.
-rw-r--r--embassy-stm32/src/rcc/f2.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/embassy-stm32/src/rcc/f2.rs b/embassy-stm32/src/rcc/f2.rs
index 1525cc3c3..bc240fcb1 100644
--- a/embassy-stm32/src/rcc/f2.rs
+++ b/embassy-stm32/src/rcc/f2.rs
@@ -58,7 +58,7 @@ impl Default for PLLConfig {
58impl PLLConfig { 58impl PLLConfig {
59 pub fn clocks(&self, src_freq: Hertz) -> PLLClocks { 59 pub fn clocks(&self, src_freq: Hertz) -> PLLClocks {
60 let in_freq = src_freq / self.pre_div; 60 let in_freq = src_freq / self.pre_div;
61 let vco_freq = src_freq * self.mul / self.pre_div; 61 let vco_freq = Hertz((src_freq.0 as u64 * self.mul.0 as u64 / self.pre_div.0 as u64) as u32);
62 let main_freq = vco_freq / self.main_div; 62 let main_freq = vco_freq / self.main_div;
63 let pll48_freq = vco_freq / self.pll48_div; 63 let pll48_freq = vco_freq / self.pll48_div;
64 PLLClocks { 64 PLLClocks {