30 lines
1.1 KiB
Rust
30 lines
1.1 KiB
Rust
//! STM32F722 Pll216 clock-source assembly.
|
|
|
|
use super::peripherals::{DwtMicrosecondClock, select_pll216_profile};
|
|
use kaptan_err_reportable::KaptanError;
|
|
use stm32f7::stm32f722;
|
|
|
|
/// Core frequency in whole megahertz after selecting the PLL216 board profile.
|
|
const CORE_CLOCK_MHZ: u32 = 216;
|
|
|
|
/// A failure while establishing the board's clock tree or monotonic clock.
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, KaptanError)]
|
|
pub(crate) enum ClockInitializationError {
|
|
#[kaptan_error(id = 11801)]
|
|
Profile,
|
|
#[kaptan_error(id = 11802)]
|
|
Monotonic,
|
|
}
|
|
|
|
/// Selects the F722 Pll216 profile and starts its monotonic microsecond clock.
|
|
pub(crate) fn initialize(
|
|
core: &mut cortex_m::Peripherals,
|
|
device: &stm32f722::Peripherals,
|
|
) -> Result<DwtMicrosecondClock, ClockInitializationError> {
|
|
select_pll216_profile(&device.RCC, &device.PWR, &device.FLASH)
|
|
.map_err(|_| ClockInitializationError::Profile)?;
|
|
core.SCB.disable_dcache(&mut core.CPUID);
|
|
DwtMicrosecondClock::start::<CORE_CLOCK_MHZ>(&mut core.DCB, &mut core.DWT)
|
|
.map_err(|_| ClockInitializationError::Monotonic)
|
|
}
|