forked from stm32-rs/stm32h7xx-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractional-pll.rs
57 lines (46 loc) · 1.54 KB
/
fractional-pll.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#![deny(warnings)]
#![no_main]
#![no_std]
#[macro_use]
mod utilities;
use cortex_m_rt::entry;
use log::info;
use stm32h7xx_hal::rcc;
use stm32h7xx_hal::{gpio::Speed, pac, prelude::*};
#[entry]
fn main() -> ! {
utilities::logger::init();
let dp = pac::Peripherals::take().unwrap();
// Constrain and Freeze power
info!("Setup PWR... ");
let pwr = dp.PWR.constrain();
let pwrcfg = example_power!(pwr).freeze();
// Constrain and Freeze clock
info!("Setup RCC... ");
let rcc = dp.RCC.constrain();
let ccdr = rcc
.sys_ck(100.MHz())
.pll2_strategy(rcc::PllConfigStrategy::FractionalNotLess)
.pll2_p_ck(12_288_000.Hz())
.pll2_q_ck(6_144_000.Hz())
.pll2_r_ck((48_000 * 63).Hz())
// pll2_p / 2 --> mco2
.mco2_from_pll2_p_ck(7.MHz())
.freeze(pwrcfg, &dp.SYSCFG);
// Enable MCO2 output pin
let gpioc = dp.GPIOC.split(ccdr.peripheral.GPIOC);
let _mco2_pin = gpioc.pc9.into_alternate::<0>().speed(Speed::High);
info!("");
info!("stm32h7xx-hal example - Fractional PLL");
info!("");
// SYS_CK
info!("sys_ck = {} MHz", ccdr.clocks.sys_ck().raw() as f32 / 1e6);
assert_eq!(ccdr.clocks.sys_ck().raw(), 400_000_000);
info!("pll2_p_ck = {}", ccdr.clocks.pll2_p_ck().unwrap());
info!("pll2_q_ck = {}", ccdr.clocks.pll2_q_ck().unwrap());
info!("pll2_r_ck = {}", ccdr.clocks.pll2_r_ck().unwrap());
let _mco2_ck = ccdr.clocks.mco2_ck().unwrap().raw();
loop {
cortex_m::asm::nop()
}
}