diff options
| author | Michael Medin <[email protected]> | 2025-04-28 09:14:56 +0200 |
|---|---|---|
| committer | Michael Medin <[email protected]> | 2025-04-28 09:14:56 +0200 |
| commit | 74cb84eb4e4be75859deb6fa4896efae5345eacb (patch) | |
| tree | 7697d7f250050d577af60f1b871fb461cb23e9e5 /embassy-stm32/src | |
| parent | 584066e209141ce92d882ceb6e7525c980833689 (diff) | |
Moved functions to rcc module (this is a bit awkward as we now have two init functions in rcc: `rcc::init`and `rcc::init_rcc`)
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/lib.rs | 32 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 30 |
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 |
| 215 | pub use _generated::{peripherals, Peripherals}; | 215 | pub use _generated::{peripherals, Peripherals}; |
| 216 | use critical_section::CriticalSection; | ||
| 217 | pub use embassy_hal_internal::{Peri, PeripheralType}; | 216 | pub use embassy_hal_internal::{Peri, PeripheralType}; |
| 218 | #[cfg(feature = "unstable-pac")] | 217 | #[cfg(feature = "unstable-pac")] |
| 219 | pub use stm32_metapac as pac; | 218 | pub 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"))] | ||
| 620 | pub fn reinit(config: rcc::Config) { | ||
| 621 | critical_section::with(|cs| init_rcc(cs, config)) | ||
| 622 | } | ||
| 623 | |||
| 624 | fn 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::*; | |||
| 34 | use stm32_metapac::RCC; | 34 | use stm32_metapac::RCC; |
| 35 | 35 | ||
| 36 | pub use crate::_generated::{mux, Clocks}; | 36 | pub use crate::_generated::{mux, Clocks}; |
| 37 | use crate::rcc; | ||
| 37 | use crate::time::Hertz; | 38 | use 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>() { | |||
| 369 | pub fn disable<T: RccPeripheral>() { | 370 | pub 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"))] | ||
| 383 | pub fn reinit(config: Config) { | ||
| 384 | critical_section::with(|cs| init_rcc(cs, config)) | ||
| 385 | } | ||
| 386 | |||
| 387 | fn 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 | } | ||
