diff options
| author | Scott Mabin <[email protected]> | 2023-07-30 01:00:50 +0100 |
|---|---|---|
| committer | Scott Mabin <[email protected]> | 2023-07-30 01:00:53 +0100 |
| commit | e0ce7fcde7906fc219d294e858388e62ab107ec3 (patch) | |
| tree | 1fef483aa7a72fed8223d11c18166cc84eec4dd1 | |
| parent | fcbfd224a729c38d5ff94d94a25321a819254630 (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.rs | 2 |
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 { | |||
| 58 | impl PLLConfig { | 58 | impl 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 { |
