embassy/examples/stm32f2/src/bin/pll.rs

53 lines
1.6 KiB
Rust
Raw Normal View History

2022-04-29 17:13:59 +02:00
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use core::convert::TryFrom;
2022-06-12 22:15:44 +02:00
2022-04-29 17:13:59 +02:00
use defmt::*;
use embassy_executor::Spawner;
2022-06-12 22:15:44 +02:00
use embassy_stm32::rcc::{
2023-10-09 02:48:22 +02:00
APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLLConfig, PLLMul, PLLPDiv, PLLPreDiv, PLLQDiv, PLLSrc,
2022-04-29 17:13:59 +02:00
};
2022-06-12 22:15:44 +02:00
use embassy_stm32::time::Hertz;
use embassy_stm32::Config;
use embassy_time::Timer;
2022-06-12 22:15:44 +02:00
use {defmt_rtt as _, panic_probe as _};
2022-04-29 17:13:59 +02:00
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
// Example config for maximum performance on a NUCLEO-F207ZG board
2022-04-29 17:13:59 +02:00
let mut config = Config::default();
// By default, HSE on the board comes from a 8 MHz clock signal (not a crystal)
config.rcc.hse = Some(HSEConfig {
frequency: Hertz(8_000_000),
source: HSESrc::Bypass,
});
// PLL uses HSE as the clock source
config.rcc.pll_mux = PLLSrc::HSE;
config.rcc.pll = PLLConfig {
// 8 MHz clock source / 8 = 1 MHz PLL input
2022-04-30 10:41:17 +02:00
pre_div: unwrap!(PLLPreDiv::try_from(8)),
2022-04-29 17:13:59 +02:00
// 1 MHz PLL input * 240 = 240 MHz PLL VCO
2022-04-30 10:41:17 +02:00
mul: unwrap!(PLLMul::try_from(240)),
2022-04-29 17:13:59 +02:00
// 240 MHz PLL VCO / 2 = 120 MHz main PLL output
2023-10-09 02:48:22 +02:00
p_div: PLLPDiv::DIV2,
2022-04-29 17:13:59 +02:00
// 240 MHz PLL VCO / 5 = 48 MHz PLL48 output
2023-10-09 02:48:22 +02:00
q_div: PLLQDiv::DIV5,
2022-04-29 17:13:59 +02:00
};
// System clock comes from PLL (= the 120 MHz main PLL output)
config.rcc.mux = ClockSrc::PLL;
// 120 MHz / 4 = 30 MHz APB1 frequency
config.rcc.apb1_pre = APBPrescaler::DIV4;
2022-04-29 17:13:59 +02:00
// 120 MHz / 2 = 60 MHz APB2 frequency
config.rcc.apb2_pre = APBPrescaler::DIV2;
2022-04-29 17:13:59 +02:00
let _p = embassy_stm32::init(config);
2022-04-29 17:13:59 +02:00
loop {
Timer::after_millis(1000).await;
2022-04-29 17:13:59 +02:00
info!("1s elapsed");
}
}