diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-11-13 01:56:28 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-11-13 01:59:33 +0100 |
| commit | ace52210802a18a551f506bc3ad163703e3f9efa (patch) | |
| tree | 69cd68e35968cf0a5da5000308e338bdbad3724a /examples | |
| parent | 2376b3bdfa573027c1ee4d66f8fdd6ca422a0fdd (diff) | |
stm32/rcc: unify f2 into f4/f7.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f2/src/bin/pll.rs | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs index feec90016..aae7637dc 100644 --- a/examples/stm32f2/src/bin/pll.rs +++ b/examples/stm32f2/src/bin/pll.rs | |||
| @@ -6,9 +6,6 @@ use core::convert::TryFrom; | |||
| 6 | 6 | ||
| 7 | use defmt::*; | 7 | use defmt::*; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::rcc::{ | ||
| 10 | APBPrescaler, ClockSrc, HSEConfig, HSESrc, Pll, PllMul, PllPDiv, PllPreDiv, PllQDiv, PllSource, | ||
| 11 | }; | ||
| 12 | use embassy_stm32::time::Hertz; | 9 | use embassy_stm32::time::Hertz; |
| 13 | use embassy_stm32::Config; | 10 | use embassy_stm32::Config; |
| 14 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| @@ -19,29 +16,35 @@ async fn main(_spawner: Spawner) { | |||
| 19 | // Example config for maximum performance on a NUCLEO-F207ZG board | 16 | // Example config for maximum performance on a NUCLEO-F207ZG board |
| 20 | 17 | ||
| 21 | let mut config = Config::default(); | 18 | let mut config = Config::default(); |
| 22 | // By default, HSE on the board comes from a 8 MHz clock signal (not a crystal) | 19 | |
| 23 | config.rcc.hse = Some(HSEConfig { | 20 | { |
| 24 | frequency: Hertz(8_000_000), | 21 | use embassy_stm32::rcc::*; |
| 25 | source: HSESrc::Bypass, | 22 | |
| 26 | }); | 23 | // By default, HSE on the board comes from a 8 MHz clock signal (not a crystal) |
| 27 | // PLL uses HSE as the clock source | 24 | config.rcc.hse = Some(Hse { |
| 28 | config.rcc.pll_mux = PllSource::HSE; | 25 | freq: Hertz(8_000_000), |
| 29 | config.rcc.pll = Pll { | 26 | mode: HseMode::Bypass, |
| 30 | // 8 MHz clock source / 8 = 1 MHz PLL input | 27 | }); |
| 31 | pre_div: unwrap!(PllPreDiv::try_from(8)), | 28 | // PLL uses HSE as the clock source |
| 32 | // 1 MHz PLL input * 240 = 240 MHz PLL VCO | 29 | config.rcc.pll_src = PllSource::HSE; |
| 33 | mul: unwrap!(PllMul::try_from(240)), | 30 | config.rcc.pll = Some(Pll { |
| 34 | // 240 MHz PLL VCO / 2 = 120 MHz main PLL output | 31 | // 8 MHz clock source / 8 = 1 MHz PLL input |
| 35 | divp: PllPDiv::DIV2, | 32 | prediv: unwrap!(PllPreDiv::try_from(8)), |
| 36 | // 240 MHz PLL VCO / 5 = 48 MHz PLL48 output | 33 | // 1 MHz PLL input * 240 = 240 MHz PLL VCO |
| 37 | divq: PllQDiv::DIV5, | 34 | mul: unwrap!(PllMul::try_from(240)), |
| 38 | }; | 35 | // 240 MHz PLL VCO / 2 = 120 MHz main PLL output |
| 39 | // System clock comes from PLL (= the 120 MHz main PLL output) | 36 | divp: Some(PllPDiv::DIV2), |
| 40 | config.rcc.mux = ClockSrc::PLL; | 37 | // 240 MHz PLL VCO / 5 = 48 MHz PLL48 output |
| 41 | // 120 MHz / 4 = 30 MHz APB1 frequency | 38 | divq: Some(PllQDiv::DIV5), |
| 42 | config.rcc.apb1_pre = APBPrescaler::DIV4; | 39 | divr: None, |
| 43 | // 120 MHz / 2 = 60 MHz APB2 frequency | 40 | }); |
| 44 | config.rcc.apb2_pre = APBPrescaler::DIV2; | 41 | // System clock comes from PLL (= the 120 MHz main PLL output) |
| 42 | config.rcc.sys = Sysclk::PLL1_P; | ||
| 43 | // 120 MHz / 4 = 30 MHz APB1 frequency | ||
| 44 | config.rcc.apb1_pre = APBPrescaler::DIV4; | ||
| 45 | // 120 MHz / 2 = 60 MHz APB2 frequency | ||
| 46 | config.rcc.apb2_pre = APBPrescaler::DIV2; | ||
| 47 | } | ||
| 45 | 48 | ||
| 46 | let _p = embassy_stm32::init(config); | 49 | let _p = embassy_stm32::init(config); |
| 47 | 50 | ||
