Skip to content

Commit 6186d11

Browse files
authored
Merge pull request #4287 from dlaw/main
Add public function to get current clock configuration
2 parents 141c170 + c10688c commit 6186d11

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

embassy-stm32/src/rcc/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ pub(crate) unsafe fn get_freqs() -> &'static Clocks {
9595
unwrap!(CLOCK_FREQS_PTR.load(core::sync::atomic::Ordering::SeqCst).as_ref()).assume_init_ref()
9696
}
9797

98+
/// Get the current clock configuration of the chip.
99+
pub fn clocks<'a>(_rcc: &'a crate::Peri<'a, crate::peripherals::RCC>) -> &'a Clocks {
100+
// Safety: the existence of a `Peri<RCC>` means that `rcc::init()`
101+
// has already been called, so `CLOCK_FREQS` must be initialized.
102+
// The clocks could be modified again by `reinit()`, but reinit
103+
// (for this reason) requires an exclusive reference to `Peri<RCC>`.
104+
unsafe { get_freqs() }
105+
}
106+
98107
pub(crate) trait SealedRccPeripheral {
99108
fn frequency() -> Hertz;
100109
#[allow(dead_code)]
@@ -381,7 +390,7 @@ pub fn disable<T: RccPeripheral>() {
381390
///
382391
/// This should only be called after `init`.
383392
#[cfg(not(feature = "_dual-core"))]
384-
pub fn reinit(config: Config) {
393+
pub fn reinit<'a>(config: Config, _rcc: &'a mut crate::Peri<'a, crate::peripherals::RCC>) {
385394
critical_section::with(|cs| init_rcc(cs, config))
386395
}
387396

0 commit comments

Comments
 (0)