diff options
| author | David Lawrence <[email protected]> | 2025-06-06 13:01:11 -0400 |
|---|---|---|
| committer | David Lawrence <[email protected]> | 2025-06-06 13:05:35 -0400 |
| commit | c10688cd40d5ffdc181446f304e833ec880b25f0 (patch) | |
| tree | 37d7f13885afbedb3db716281feac25e94d343f6 | |
| parent | 141c170db426404444a454c063c2eec07c74a1c3 (diff) | |
Add public function to get current clock configuration
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 3733fed56..c41f81816 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -95,6 +95,15 @@ pub(crate) unsafe fn get_freqs() -> &'static Clocks { | |||
| 95 | unwrap!(CLOCK_FREQS_PTR.load(core::sync::atomic::Ordering::SeqCst).as_ref()).assume_init_ref() | 95 | unwrap!(CLOCK_FREQS_PTR.load(core::sync::atomic::Ordering::SeqCst).as_ref()).assume_init_ref() |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 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 | |||
| 98 | pub(crate) trait SealedRccPeripheral { | 107 | pub(crate) trait SealedRccPeripheral { |
| 99 | fn frequency() -> Hertz; | 108 | fn frequency() -> Hertz; |
| 100 | #[allow(dead_code)] | 109 | #[allow(dead_code)] |
| @@ -381,7 +390,7 @@ pub fn disable<T: RccPeripheral>() { | |||
| 381 | /// | 390 | /// |
| 382 | /// This should only be called after `init`. | 391 | /// This should only be called after `init`. |
| 383 | #[cfg(not(feature = "_dual-core"))] | 392 | #[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>) { |
| 385 | critical_section::with(|cs| init_rcc(cs, config)) | 394 | critical_section::with(|cs| init_rcc(cs, config)) |
| 386 | } | 395 | } |
| 387 | 396 | ||
