aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-04-30 21:08:43 +0000
committerGitHub <[email protected]>2022-04-30 21:08:43 +0000
commitd600f392608ebebe97d1e7461789d0a724afc9ef (patch)
treef57df320554eb534c7aba15e4d09e5929deb8e96 /examples
parentc474682ea97add6ae8d448e8472ee0444c3cc366 (diff)
parente88559c5ca2450bbcfd6fe65e73fe0fe47465680 (diff)
Merge #743
743: Add PLL config support for F2 r=Dirbaio a=Gekkio - minor changes to make the F2 RCC API a bit more flexible - low-level PLL config with assertions based on datasheet specs. It shouldn't be very difficult to later add a "reverse API" where you pass the clocks you want to a function and it generates a `PLLConfig` struct for you - PLL API tested on my custom board with 12 MHz HSE as source for PLL to generate max clocks for SYSCLK/AHB/APB/APB1/PLL48 - the example *should* work but is untested since I don't have the Nucleo board :disappointed: Co-authored-by: Joonas Javanainen <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f2/src/bin/pll.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs
new file mode 100644
index 000000000..4bd74f0bd
--- /dev/null
+++ b/examples/stm32f2/src/bin/pll.rs
@@ -0,0 +1,56 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use core::convert::TryFrom;
6use defmt::*;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::{
10 rcc::{
11 APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul,
12 PLLPreDiv, PLLSrc,
13 },
14 time::Hertz,
15 Config, Peripherals,
16};
17
18use defmt_rtt as _; // global logger
19use panic_probe as _;
20
21// Example config for maximum performance on a NUCLEO-F207ZG board
22fn config() -> Config {
23 let mut config = Config::default();
24 // By default, HSE on the board comes from a 8 MHz clock signal (not a crystal)
25 config.rcc.hse = Some(HSEConfig {
26 frequency: Hertz(8_000_000),
27 source: HSESrc::Bypass,
28 });
29 // PLL uses HSE as the clock source
30 config.rcc.pll_mux = PLLSrc::HSE;
31 config.rcc.pll = PLLConfig {
32 // 8 MHz clock source / 8 = 1 MHz PLL input
33 pre_div: unwrap!(PLLPreDiv::try_from(8)),
34 // 1 MHz PLL input * 240 = 240 MHz PLL VCO
35 mul: unwrap!(PLLMul::try_from(240)),
36 // 240 MHz PLL VCO / 2 = 120 MHz main PLL output
37 main_div: PLLMainDiv::Div2,
38 // 240 MHz PLL VCO / 5 = 48 MHz PLL48 output
39 pll48_div: unwrap!(PLL48Div::try_from(5)),
40 };
41 // System clock comes from PLL (= the 120 MHz main PLL output)
42 config.rcc.mux = ClockSrc::PLL;
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 config
48}
49
50#[embassy::main(config = "config()")]
51async fn main(_spawner: Spawner, _p: Peripherals) {
52 loop {
53 Timer::after(Duration::from_millis(1000)).await;
54 info!("1s elapsed");
55 }
56}