2021-06-02 16:34:37 +02:00
|
|
|
#![macro_use]
|
|
|
|
|
2021-05-27 09:50:11 +02:00
|
|
|
use core::mem::MaybeUninit;
|
2021-06-14 10:48:14 +02:00
|
|
|
|
2022-06-12 22:15:44 +02:00
|
|
|
use crate::time::Hertz;
|
|
|
|
|
2022-02-14 02:12:06 +01:00
|
|
|
#[cfg_attr(rcc_f0, path = "f0.rs")]
|
2022-06-26 23:52:38 +02:00
|
|
|
#[cfg_attr(any(rcc_f1, rcc_f100, rcc_f1cl), path = "f1.rs")]
|
2022-03-27 17:40:49 +02:00
|
|
|
#[cfg_attr(rcc_f2, path = "f2.rs")]
|
2022-01-04 19:25:50 +01:00
|
|
|
#[cfg_attr(rcc_f3, path = "f3.rs")]
|
|
|
|
#[cfg_attr(any(rcc_f4, rcc_f410), path = "f4.rs")]
|
|
|
|
#[cfg_attr(rcc_f7, path = "f7.rs")]
|
2023-01-17 18:54:23 +01:00
|
|
|
#[cfg_attr(rcc_c0, path = "c0.rs")]
|
2022-01-04 19:25:50 +01:00
|
|
|
#[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")]
|
2022-04-08 02:57:48 +02:00
|
|
|
#[cfg_attr(rcc_l5, path = "l5.rs")]
|
2022-01-04 19:25:50 +01:00
|
|
|
#[cfg_attr(rcc_u5, path = "u5.rs")]
|
|
|
|
#[cfg_attr(rcc_wb, path = "wb.rs")]
|
2022-04-08 03:40:51 +02:00
|
|
|
#[cfg_attr(any(rcc_wl5, rcc_wle), path = "wl.rs")]
|
2023-04-06 18:53:51 +02:00
|
|
|
#[cfg_attr(any(rcc_h5, rcc_h50), path = "h5.rs")]
|
2022-01-04 19:25:50 +01:00
|
|
|
mod _version;
|
|
|
|
pub use _version::*;
|
|
|
|
|
2023-01-20 16:31:04 +01:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub struct Clocks {
|
|
|
|
pub sys: Hertz,
|
2021-07-30 22:48:13 +02:00
|
|
|
|
2022-02-14 02:12:06 +01:00
|
|
|
// APB
|
2021-06-14 10:48:14 +02:00
|
|
|
pub apb1: Hertz,
|
2021-07-30 22:48:13 +02:00
|
|
|
pub apb1_tim: Hertz,
|
2023-01-17 18:54:23 +01:00
|
|
|
#[cfg(not(any(rcc_c0, rcc_g0)))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub apb2: Hertz,
|
2023-01-17 18:54:23 +01:00
|
|
|
#[cfg(not(any(rcc_c0, rcc_g0)))]
|
2021-07-30 22:48:13 +02:00
|
|
|
pub apb2_tim: Hertz,
|
2023-04-06 18:53:51 +02:00
|
|
|
#[cfg(any(rcc_wl5, rcc_wle, rcc_h5, rcc_h50, rcc_u5))]
|
2021-08-19 22:51:41 +02:00
|
|
|
pub apb3: Hertz,
|
2022-02-24 05:59:42 +01:00
|
|
|
#[cfg(any(rcc_h7, rcc_h7ab))]
|
2022-02-14 02:12:06 +01:00
|
|
|
pub apb4: Hertz,
|
2021-06-23 01:07:48 +02:00
|
|
|
|
2022-02-14 02:12:06 +01:00
|
|
|
// AHB
|
2021-06-14 10:48:14 +02:00
|
|
|
pub ahb1: Hertz,
|
2022-01-24 00:50:35 +01:00
|
|
|
#[cfg(any(
|
2023-04-06 18:53:51 +02:00
|
|
|
rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h5, rcc_h50, rcc_h7, rcc_h7ab, rcc_g4, rcc_u5, rcc_wb,
|
|
|
|
rcc_wl5, rcc_wle
|
2022-01-24 00:50:35 +01:00
|
|
|
))]
|
2021-06-14 10:48:14 +02:00
|
|
|
pub ahb2: Hertz,
|
2022-02-24 05:59:42 +01:00
|
|
|
#[cfg(any(
|
2023-04-06 18:53:51 +02:00
|
|
|
rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h5, rcc_h50, rcc_h7, rcc_h7ab, rcc_u5, rcc_wb, rcc_wl5,
|
|
|
|
rcc_wle
|
2022-02-24 05:59:42 +01:00
|
|
|
))]
|
2021-06-14 11:41:02 +02:00
|
|
|
pub ahb3: Hertz,
|
2023-04-06 18:53:51 +02:00
|
|
|
#[cfg(any(rcc_h5, rcc_h50, rcc_h7, rcc_h7ab))]
|
2021-07-09 15:33:17 +02:00
|
|
|
pub ahb4: Hertz,
|
|
|
|
|
2022-04-26 19:33:57 +02:00
|
|
|
#[cfg(any(rcc_f2, rcc_f4, rcc_f410, rcc_f7))]
|
2021-07-28 04:09:48 +02:00
|
|
|
pub pll48: Option<Hertz>,
|
2021-12-30 10:50:28 +01:00
|
|
|
|
2023-04-15 04:28:27 +02:00
|
|
|
#[cfg(all(rcc_f4, not(stm32f410)))]
|
2023-04-14 23:30:36 +02:00
|
|
|
pub plli2s: Option<Hertz>,
|
|
|
|
|
2023-04-15 04:28:27 +02:00
|
|
|
#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479))]
|
|
|
|
pub pllsai: Option<Hertz>,
|
|
|
|
|
2022-05-08 21:37:37 +02:00
|
|
|
#[cfg(stm32f1)]
|
2021-12-30 10:50:28 +01:00
|
|
|
pub adc: Hertz,
|
2022-03-19 11:05:00 +01:00
|
|
|
|
2023-04-06 18:53:51 +02:00
|
|
|
#[cfg(any(rcc_h5, rcc_h50, rcc_h7, rcc_h7ab))]
|
2022-03-19 11:05:00 +01:00
|
|
|
pub adc: 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.
|
2022-01-04 19:25:50 +01:00
|
|
|
pub(crate) unsafe fn set_freqs(freqs: Clocks) {
|
2023-01-20 16:31:04 +01:00
|
|
|
debug!("rcc: {:?}", freqs);
|
2023-07-04 23:29:46 +02:00
|
|
|
CLOCK_FREQS = MaybeUninit::new(freqs);
|
2021-05-27 09:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Safety: Reads a mutable global.
|
2022-01-04 19:25:50 +01:00
|
|
|
pub(crate) unsafe fn get_freqs() -> &'static Clocks {
|
2023-07-04 23:29:46 +02:00
|
|
|
CLOCK_FREQS.assume_init_ref()
|
2021-05-27 09:50:11 +02:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:38:12 +01:00
|
|
|
#[cfg(feature = "unstable-pac")]
|
|
|
|
pub mod low_level {
|
|
|
|
pub use super::sealed::*;
|
|
|
|
}
|
|
|
|
|
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 {}
|