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 10:48:14 +02:00
|
|
|
|
2022-01-04 19:25:50 +01:00
|
|
|
#[cfg_attr(any(rcc_f0, rcc_f0x0), path = "f0.rs")]
|
|
|
|
#[cfg_attr(rcc_f1, path = "f1.rs")]
|
|
|
|
#[cfg_attr(rcc_f3, path = "f3.rs")]
|
|
|
|
#[cfg_attr(any(rcc_f4, rcc_f410), path = "f4.rs")]
|
|
|
|
#[cfg_attr(rcc_f7, path = "f7.rs")]
|
|
|
|
#[cfg_attr(rcc_g0, path = "g0.rs")]
|
|
|
|
#[cfg_attr(rcc_g4, path = "g4.rs")]
|
|
|
|
#[cfg_attr(any(rcc_h7, rcc_h7ab), path = "h7.rs")]
|
|
|
|
#[cfg_attr(rcc_l0, path = "l0.rs")]
|
|
|
|
#[cfg_attr(rcc_l1, path = "l1.rs")]
|
|
|
|
#[cfg_attr(rcc_l4, path = "l4.rs")]
|
|
|
|
#[cfg_attr(rcc_u5, path = "u5.rs")]
|
|
|
|
#[cfg_attr(rcc_wb, path = "wb.rs")]
|
|
|
|
#[cfg_attr(rcc_wl5, path = "wl5.rs")]
|
|
|
|
mod _version;
|
|
|
|
pub use _version::*;
|
|
|
|
|
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-11-02 17:03:56 +01:00
|
|
|
#[cfg(any(rcc_wl5, rcc_u5))]
|
2021-08-19 22:51:41 +02:00
|
|
|
pub apb3: Hertz,
|
2021-06-23 01:07:48 +02:00
|
|
|
|
2021-12-10 07:10:03 +01:00
|
|
|
#[cfg(any(rcc_l0, rcc_l1, rcc_f0, rcc_f1, rcc_f3, rcc_f0x0, rcc_g0))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub ahb: Hertz,
|
|
|
|
|
2021-11-27 02:21:53 +01:00
|
|
|
#[cfg(any(rcc_l4, rcc_f4, rcc_f7, rcc_h7, rcc_g4, rcc_u5, rcc_wb, rcc_wl5))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub ahb1: Hertz,
|
|
|
|
|
2021-11-27 02:21:53 +01:00
|
|
|
#[cfg(any(rcc_l4, rcc_f4, rcc_f7, rcc_h7, rcc_g4, rcc_u5, rcc_wb, rcc_wl5))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub ahb2: Hertz,
|
|
|
|
|
2021-11-02 17:03:56 +01:00
|
|
|
#[cfg(any(rcc_l4, rcc_f4, rcc_f7, rcc_h7, rcc_u5, 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-12-30 10:50:28 +01:00
|
|
|
|
|
|
|
#[cfg(rcc_f1)]
|
|
|
|
pub adc: 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.
|
2022-01-04 19:25:50 +01:00
|
|
|
pub(crate) unsafe fn set_freqs(freqs: Clocks) {
|
2021-05-27 09:50:11 +02:00
|
|
|
CLOCK_FREQS.as_mut_ptr().write(freqs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Safety: Reads a mutable global.
|
2022-01-04 19:25:50 +01:00
|
|
|
pub(crate) unsafe fn get_freqs() -> &'static Clocks {
|
2021-05-27 09:50:11 +02:00
|
|
|
&*CLOCK_FREQS.as_ptr()
|
|
|
|
}
|
|
|
|
|
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-11-29 02:10:06 +01:00
|
|
|
($inst:ident, gpio, GPIO, $clk:ident, $en:tt, $rst:tt) => {};
|
|
|
|
($inst:ident, $module:ident, $block:ident, $clk:ident, ($en_reg:ident, $en_field:ident, $en_set_field:ident), ($rst_reg:ident, $rst_field:ident, $rst_set_field: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(|_| {
|
2021-11-29 02:10:06 +01:00
|
|
|
unsafe { get_freqs().$clk }
|
2021-06-11 09:19:02 +02:00
|
|
|
})
|
|
|
|
}
|
2021-06-02 16:34:37 +02:00
|
|
|
fn enable() {
|
2021-06-08 13:10:40 +02:00
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
2021-11-29 02:10:06 +01:00
|
|
|
crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(true));
|
2021-06-08 13:10:40 +02:00
|
|
|
}
|
|
|
|
})
|
2021-06-02 16:34:37 +02:00
|
|
|
}
|
|
|
|
fn disable() {
|
2021-06-08 13:10:40 +02:00
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
2021-11-29 02:10:06 +01:00
|
|
|
crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(false));
|
2021-06-08 13:10:40 +02:00
|
|
|
}
|
|
|
|
})
|
2021-06-02 16:34:37 +02:00
|
|
|
}
|
|
|
|
fn reset() {
|
2021-06-08 13:10:40 +02:00
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
2021-11-29 02:10:06 +01:00
|
|
|
crate::pac::RCC.$rst_reg().modify(|w| w.$rst_set_field(true));
|
|
|
|
crate::pac::RCC.$rst_reg().modify(|w| w.$rst_set_field(false));
|
2021-06-08 13:10:40 +02:00
|
|
|
}
|
|
|
|
})
|
2021-06-02 16:34:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 18:25:51 +02:00
|
|
|
impl RccPeripheral for peripherals::$inst {}
|
|
|
|
};
|
2021-11-29 02:10:06 +01:00
|
|
|
($inst:ident, $module:ident, $block:ident, $clk:ident, ($en_reg:ident, $en_field:ident, $en_set_field:ident), _) => {
|
2021-07-15 18:25:51 +02:00
|
|
|
impl sealed::RccPeripheral for peripherals::$inst {
|
|
|
|
fn frequency() -> crate::time::Hertz {
|
|
|
|
critical_section::with(|_| {
|
2021-11-29 02:10:06 +01:00
|
|
|
unsafe { get_freqs().$clk }
|
2021-07-15 18:25:51 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
fn enable() {
|
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
2021-11-29 02:10:06 +01:00
|
|
|
crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(true));
|
2021-07-15 18:25:51 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
fn disable() {
|
|
|
|
critical_section::with(|_| {
|
|
|
|
unsafe {
|
2021-11-29 02:10:06 +01:00
|
|
|
crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(false));
|
2021-07-15 18:25:51 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
fn reset() {}
|
|
|
|
}
|
|
|
|
|
2021-06-02 16:34:37 +02:00
|
|
|
impl RccPeripheral for peripherals::$inst {}
|
|
|
|
};
|
|
|
|
);
|