2021-06-02 16:34:37 +02:00
|
|
|
#![macro_use]
|
|
|
|
|
|
|
|
use crate::peripherals;
|
2021-06-14 10:48:14 +02:00
|
|
|
use crate::time::Hertz;
|
2021-05-27 09:50:11 +02:00
|
|
|
use core::mem::MaybeUninit;
|
2021-06-14 11:24:09 +02:00
|
|
|
mod types;
|
2021-06-14 10:48:14 +02:00
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub struct Clocks {
|
|
|
|
pub sys: Hertz,
|
2021-07-30 22:48:13 +02:00
|
|
|
|
|
|
|
#[cfg(rcc_g0)]
|
|
|
|
pub apb: Hertz,
|
|
|
|
#[cfg(rcc_g0)]
|
|
|
|
pub apb_tim: Hertz,
|
|
|
|
|
|
|
|
#[cfg(not(rcc_g0))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub apb1: Hertz,
|
2021-07-30 22:48:13 +02:00
|
|
|
#[cfg(not(rcc_g0))]
|
|
|
|
pub apb1_tim: Hertz,
|
|
|
|
|
|
|
|
#[cfg(not(rcc_g0))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub apb2: Hertz,
|
2021-07-30 22:48:13 +02:00
|
|
|
#[cfg(not(rcc_g0))]
|
|
|
|
pub apb2_tim: Hertz,
|
|
|
|
|
2021-08-19 22:51:41 +02:00
|
|
|
#[cfg(rcc_wl5)]
|
|
|
|
pub apb3: Hertz,
|
2021-06-23 01:07:48 +02:00
|
|
|
|
2021-09-26 17:08:22 +02:00
|
|
|
#[cfg(any(rcc_l0, rcc_l1, rcc_f0, rcc_f1, rcc_f0x0, rcc_g0))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub ahb: Hertz,
|
|
|
|
|
2021-10-19 15:36:41 +02:00
|
|
|
#[cfg(any(rcc_l4, rcc_f4, rcc_f7, rcc_h7, rcc_wb, rcc_wl5))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub ahb1: Hertz,
|
|
|
|
|
2021-10-19 15:36:41 +02:00
|
|
|
#[cfg(any(rcc_l4, rcc_f4, rcc_f7, rcc_h7, rcc_wb, rcc_wl5))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub ahb2: Hertz,
|
|
|
|
|
2021-10-19 15:36:41 +02:00
|
|
|
#[cfg(any(rcc_l4, rcc_f4, rcc_f7, rcc_h7, rcc_wb, rcc_wl5))]
|
2021-06-14 11:41:02 +02:00
|
|
|
pub ahb3: Hertz,
|
|
|
|
|
2021-07-09 15:33:17 +02:00
|
|
|
#[cfg(any(rcc_h7))]
|
|
|
|
pub ahb4: Hertz,
|
|
|
|
|
2021-06-14 10:48:14 +02:00
|
|
|
#[cfg(any(rcc_h7))]
|
|
|
|
pub apb4: Hertz,
|
2021-07-28 04:09:48 +02:00
|
|
|
|
|
|
|
#[cfg(rcc_f4)]
|
|
|
|
pub pll48: Option<Hertz>,
|
2021-06-14 10:48:14 +02:00
|
|
|
}
|
2021-05-27 09:50:11 +02:00
|
|
|
|
|
|
|
/// Frozen clock frequencies
|
|
|
|
///
|
|
|
|
/// The existence of this value indicates that the clock configuration can no longer be changed
|
|
|
|
static mut CLOCK_FREQS: MaybeUninit<Clocks> = MaybeUninit::uninit();
|
|
|
|
|
|
|
|
/// Sets the clock frequencies
|
|
|
|
///
|
|
|
|
/// Safety: Sets a mutable global.
|
|
|
|
pub unsafe fn set_freqs(freqs: Clocks) {
|
|
|
|
CLOCK_FREQS.as_mut_ptr().write(freqs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Safety: Reads a mutable global.
|
|
|
|
pub unsafe fn get_freqs() -> &'static Clocks {
|
|
|
|
&*CLOCK_FREQS.as_ptr()
|
|
|
|
}
|
|
|
|
|
2021-05-25 13:30:42 +02:00
|
|
|
cfg_if::cfg_if! {
|
2021-05-25 04:17:24 +02:00
|
|
|
if #[cfg(rcc_h7)] {
|
2021-05-25 13:30:42 +02:00
|
|
|
mod h7;
|
|
|
|
pub use h7::*;
|
2021-05-25 04:17:24 +02:00
|
|
|
} else if #[cfg(rcc_l0)] {
|
2021-05-25 13:30:42 +02:00
|
|
|
mod l0;
|
|
|
|
pub use l0::*;
|
2021-09-21 13:42:27 +02:00
|
|
|
} else if #[cfg(rcc_l1)] {
|
|
|
|
mod l1;
|
|
|
|
pub use l1::*;
|
2021-06-11 17:45:07 +02:00
|
|
|
} else if #[cfg(rcc_l4)] {
|
2021-06-14 10:48:14 +02:00
|
|
|
mod l4;
|
|
|
|
pub use l4::*;
|
2021-09-26 17:08:22 +02:00
|
|
|
} else if #[cfg(rcc_f1)] {
|
|
|
|
mod f1;
|
|
|
|
pub use f1::*;
|
2021-06-11 17:45:07 +02:00
|
|
|
} else if #[cfg(rcc_f4)] {
|
2021-06-14 10:48:14 +02:00
|
|
|
mod f4;
|
|
|
|
pub use f4::*;
|
2021-10-19 15:36:41 +02:00
|
|
|
} else if #[cfg(rcc_f7)] {
|
|
|
|
mod f7;
|
|
|
|
pub use f7::*;
|
2021-08-19 22:17:45 +02:00
|
|
|
} else if #[cfg(rcc_wb)] {
|
|
|
|
mod wb;
|
|
|
|
pub use wb::*;
|
|
|
|
} else if #[cfg(rcc_wl5)] {
|
2021-06-16 16:07:21 +02:00
|
|
|
mod wl5x;
|
|
|
|
pub use wl5x::*;
|
2021-06-23 01:07:48 +02:00
|
|
|
} else if #[cfg(any(rcc_f0, rcc_f0x0))] {
|
|
|
|
mod f0;
|
|
|
|
pub use f0::*;
|
2021-07-30 22:48:13 +02:00
|
|
|
} else if #[cfg(any(rcc_g0))] {
|
|
|
|
mod g0;
|
|
|
|
pub use g0::*;
|
2021-05-25 13:30:42 +02:00
|
|
|
}
|
|
|
|
}
|
2021-06-02 16:34:37 +02:00
|
|
|
|
|
|
|
pub(crate) mod sealed {
|
|
|
|
pub trait RccPeripheral {
|
2021-06-11 09:19:02 +02:00
|
|
|
fn frequency() -> crate::time::Hertz;
|
2021-06-02 16:34:37 +02:00
|
|
|
fn reset();
|
|
|
|
fn enable();
|
|
|
|
fn disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait RccPeripheral: sealed::RccPeripheral + 'static {}
|
|
|
|
|
|
|
|
crate::pac::peripheral_rcc!(
|
2021-06-11 09:19:02 +02:00
|
|
|
($inst:ident, $clk:ident, $enable:ident, $reset:ident, $perien:ident, $perirst:ident) => {
|
2021-06-02 16:34:37 +02:00
|
|
|
impl sealed::RccPeripheral for peripherals::$inst {
|
2021-06-11 09:19:02 +02:00
|
|
|
fn frequency() -> crate::time::Hertz {
|
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
|
|
|
let freqs = get_freqs();
|
|
|
|
freqs.$clk
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-06-02 16:34:37 +02:00
|
|
|
fn enable() {
|
2021-06-08 13:10:40 +02:00
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
|
|
|
crate::pac::RCC.$enable().modify(|w| w.$perien(true));
|
|
|
|
}
|
|
|
|
})
|
2021-06-02 16:34:37 +02:00
|
|
|
}
|
|
|
|
fn disable() {
|
2021-06-08 13:10:40 +02:00
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
|
|
|
crate::pac::RCC.$enable().modify(|w| w.$perien(false));
|
|
|
|
}
|
|
|
|
})
|
2021-06-02 16:34:37 +02:00
|
|
|
}
|
|
|
|
fn reset() {
|
2021-06-08 13:10:40 +02:00
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
|
|
|
crate::pac::RCC.$reset().modify(|w| w.$perirst(true));
|
|
|
|
crate::pac::RCC.$reset().modify(|w| w.$perirst(false));
|
|
|
|
}
|
|
|
|
})
|
2021-06-02 16:34:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 18:25:51 +02:00
|
|
|
impl RccPeripheral for peripherals::$inst {}
|
|
|
|
};
|
|
|
|
($inst:ident, $clk:ident, $enable:ident, $perien:ident) => {
|
|
|
|
impl sealed::RccPeripheral for peripherals::$inst {
|
|
|
|
fn frequency() -> crate::time::Hertz {
|
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
|
|
|
let freqs = get_freqs();
|
|
|
|
freqs.$clk
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
fn enable() {
|
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
|
|
|
crate::pac::RCC.$enable().modify(|w| w.$perien(true));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
fn disable() {
|
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
|
|
|
crate::pac::RCC.$enable().modify(|w| w.$perien(false));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
fn reset() {}
|
|
|
|
}
|
|
|
|
|
2021-06-02 16:34:37 +02:00
|
|
|
impl RccPeripheral for peripherals::$inst {}
|
|
|
|
};
|
|
|
|
);
|