aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-05-13 20:57:33 +0000
committerGitHub <[email protected]>2025-05-13 20:57:33 +0000
commit5caa4ac51bacb8444ca6b3caafb7d0ba66e39310 (patch)
treed670e202eac7fd2597c1be99d2b69a3b7644082d /embassy-stm32
parent438c7e923a2f92f79a66cf7c5435402ff7d61f8d (diff)
parenta94cc79b9b5e01f7b207947a1dfa30432e508a9c (diff)
Merge pull request #4124 from mickem/allow_stm32_to_re_init_rcc
Add function to allow re-init rcc config for stm32
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/src/lib.rs12
-rw-r--r--embassy-stm32/src/rcc/mod.rs29
2 files changed, 30 insertions, 11 deletions
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 226293a9d..3e84d3386 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -600,17 +600,7 @@ fn init_hw(config: Config) -> Peripherals {
600 #[cfg(feature = "exti")] 600 #[cfg(feature = "exti")]
601 exti::init(cs); 601 exti::init(cs);
602 602
603 rcc::init(config.rcc); 603 rcc::init_rcc(cs, config.rcc);
604
605 // must be after rcc init
606 #[cfg(feature = "_time-driver")]
607 time_driver::init(cs);
608
609 #[cfg(feature = "low-power")]
610 {
611 crate::rcc::REFCOUNT_STOP2 = 0;
612 crate::rcc::REFCOUNT_STOP1 = 0;
613 }
614 } 604 }
615 605
616 p 606 p
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index 150daa4a7..3733fed56 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -371,3 +371,32 @@ pub fn enable_and_reset<T: RccPeripheral>() {
371pub fn disable<T: RccPeripheral>() { 371pub fn disable<T: RccPeripheral>() {
372 T::RCC_INFO.disable(); 372 T::RCC_INFO.disable();
373} 373}
374
375/// Re-initialize the `embassy-stm32` clock configuration with the provided configuration.
376///
377/// This is useful when you need to alter the CPU clock after configuring peripherals.
378/// For instance, configure an external clock via spi or i2c.
379///
380/// Please not this only re-configures the rcc and the time driver (not GPIO, EXTI, etc).
381///
382/// This should only be called after `init`.
383#[cfg(not(feature = "_dual-core"))]
384pub fn reinit(config: Config) {
385 critical_section::with(|cs| init_rcc(cs, config))
386}
387
388pub(crate) fn init_rcc(_cs: CriticalSection, config: Config) {
389 unsafe {
390 init(config);
391
392 // must be after rcc init
393 #[cfg(feature = "_time-driver")]
394 crate::time_driver::init(_cs);
395
396 #[cfg(feature = "low-power")]
397 {
398 REFCOUNT_STOP2 = 0;
399 REFCOUNT_STOP1 = 0;
400 }
401 }
402}