aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/lib.rs32
-rw-r--r--embassy-stm32/src/rcc/mod.rs30
2 files changed, 31 insertions, 31 deletions
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 444d14f28..3e84d3386 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -213,7 +213,6 @@ macro_rules! bind_interrupts {
213 213
214// Reexports 214// Reexports
215pub use _generated::{peripherals, Peripherals}; 215pub use _generated::{peripherals, Peripherals};
216use critical_section::CriticalSection;
217pub use embassy_hal_internal::{Peri, PeripheralType}; 216pub use embassy_hal_internal::{Peri, PeripheralType};
218#[cfg(feature = "unstable-pac")] 217#[cfg(feature = "unstable-pac")]
219pub use stm32_metapac as pac; 218pub use stm32_metapac as pac;
@@ -601,38 +600,9 @@ fn init_hw(config: Config) -> Peripherals {
601 #[cfg(feature = "exti")] 600 #[cfg(feature = "exti")]
602 exti::init(cs); 601 exti::init(cs);
603 602
604 init_rcc(cs, config.rcc); 603 rcc::init_rcc(cs, config.rcc);
605 } 604 }
606 605
607 p 606 p
608 }) 607 })
609} 608}
610
611/// Re-initialize the `embassy-stm32` clock configuration with the provided configuration.
612///
613/// This is useful when you need to alter the CPU clock after configuring peripherals.
614/// For instance, configure an external clock via spi or i2c.
615///
616/// Please not this only re-configures the rcc and the time driver (not GPIO, EXTI, etc).
617///
618/// This should only be called after `init`.
619#[cfg(not(feature = "_dual-core"))]
620pub fn reinit(config: rcc::Config) {
621 critical_section::with(|cs| init_rcc(cs, config))
622}
623
624fn init_rcc(_cs: CriticalSection, config: rcc::Config) {
625 unsafe {
626 rcc::init(config);
627
628 // must be after rcc init
629 #[cfg(feature = "_time-driver")]
630 time_driver::init(_cs);
631
632 #[cfg(feature = "low-power")]
633 {
634 crate::rcc::REFCOUNT_STOP2 = 0;
635 crate::rcc::REFCOUNT_STOP1 = 0;
636 }
637 }
638}
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}