aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/rcc
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/rcc')
-rw-r--r--embassy-stm32/src/rcc/mod.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index 4f43d3748..cf88cfad6 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -34,6 +34,7 @@ pub use _version::*;
34use stm32_metapac::RCC; 34use stm32_metapac::RCC;
35 35
36pub use crate::_generated::{mux, Clocks}; 36pub use crate::_generated::{mux, Clocks};
37use crate::rcc;
37use crate::time::Hertz; 38use crate::time::Hertz;
38 39
39#[cfg(feature = "low-power")] 40#[cfg(feature = "low-power")]
@@ -369,3 +370,32 @@ pub fn enable_and_reset<T: RccPeripheral>() {
369pub fn disable<T: RccPeripheral>() { 370pub fn disable<T: RccPeripheral>() {
370 T::RCC_INFO.disable(); 371 T::RCC_INFO.disable();
371} 372}
373
374/// Re-initialize the `embassy-stm32` clock configuration with the provided configuration.
375///
376/// This is useful when you need to alter the CPU clock after configuring peripherals.
377/// For instance, configure an external clock via spi or i2c.
378///
379/// Please not this only re-configures the rcc and the time driver (not GPIO, EXTI, etc).
380///
381/// This should only be called after `init`.
382#[cfg(not(feature = "_dual-core"))]
383pub fn reinit(config: Config) {
384 critical_section::with(|cs| init_rcc(cs, config))
385}
386
387fn init_rcc(_cs: CriticalSection, config: Config) {
388 unsafe {
389 init(config);
390
391 // must be after rcc init
392 #[cfg(feature = "_time-driver")]
393 crate::time_driver::init(_cs);
394
395 #[cfg(feature = "low-power")]
396 {
397 REFCOUNT_STOP2 = 0;
398 REFCOUNT_STOP1 = 0;
399 }
400 }
401}