diff options
Diffstat (limited to 'embassy-stm32/src/lib.rs')
| -rw-r--r-- | embassy-stm32/src/lib.rs | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 226293a9d..7e0f7884e 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -87,7 +87,7 @@ pub mod hsem; | |||
| 87 | pub mod hspi; | 87 | pub mod hspi; |
| 88 | #[cfg(i2c)] | 88 | #[cfg(i2c)] |
| 89 | pub mod i2c; | 89 | pub mod i2c; |
| 90 | #[cfg(any(all(spi_v1, rcc_f4), spi_v3))] | 90 | #[cfg(any(spi_v1_i2s, spi_v2_i2s, spi_v3_i2s, spi_v4_i2s, spi_v5_i2s))] |
| 91 | pub mod i2s; | 91 | pub mod i2s; |
| 92 | #[cfg(stm32wb)] | 92 | #[cfg(stm32wb)] |
| 93 | pub mod ipcc; | 93 | pub mod ipcc; |
| @@ -125,6 +125,8 @@ pub mod uid; | |||
| 125 | pub mod usart; | 125 | pub mod usart; |
| 126 | #[cfg(any(usb, otg))] | 126 | #[cfg(any(usb, otg))] |
| 127 | pub mod usb; | 127 | pub mod usb; |
| 128 | #[cfg(vrefbuf)] | ||
| 129 | pub mod vrefbuf; | ||
| 128 | #[cfg(iwdg)] | 130 | #[cfg(iwdg)] |
| 129 | pub mod wdg; | 131 | pub mod wdg; |
| 130 | #[cfg(xspi)] | 132 | #[cfg(xspi)] |
| @@ -163,18 +165,22 @@ pub use crate::_generated::interrupt; | |||
| 163 | /// ```rust,ignore | 165 | /// ```rust,ignore |
| 164 | /// use embassy_stm32::{bind_interrupts, i2c, peripherals}; | 166 | /// use embassy_stm32::{bind_interrupts, i2c, peripherals}; |
| 165 | /// | 167 | /// |
| 166 | /// bind_interrupts!(struct Irqs { | 168 | /// bind_interrupts!( |
| 167 | /// I2C1 => i2c::EventInterruptHandler<peripherals::I2C1>, i2c::ErrorInterruptHandler<peripherals::I2C1>; | 169 | /// /// Binds the I2C interrupts. |
| 168 | /// I2C2_3 => i2c::EventInterruptHandler<peripherals::I2C2>, i2c::ErrorInterruptHandler<peripherals::I2C2>, | 170 | /// struct Irqs { |
| 169 | /// i2c::EventInterruptHandler<peripherals::I2C3>, i2c::ErrorInterruptHandler<peripherals::I2C3>; | 171 | /// I2C1 => i2c::EventInterruptHandler<peripherals::I2C1>, i2c::ErrorInterruptHandler<peripherals::I2C1>; |
| 170 | /// }); | 172 | /// I2C2_3 => i2c::EventInterruptHandler<peripherals::I2C2>, i2c::ErrorInterruptHandler<peripherals::I2C2>, |
| 173 | /// i2c::EventInterruptHandler<peripherals::I2C3>, i2c::ErrorInterruptHandler<peripherals::I2C3>; | ||
| 174 | /// } | ||
| 175 | /// ); | ||
| 171 | /// ``` | 176 | /// ``` |
| 172 | 177 | ||
| 173 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. | 178 | // developer note: this macro can't be in `embassy-hal-internal` due to the use of `$crate`. |
| 174 | #[macro_export] | 179 | #[macro_export] |
| 175 | macro_rules! bind_interrupts { | 180 | macro_rules! bind_interrupts { |
| 176 | ($vis:vis struct $name:ident { | 181 | ($(#[$outer:meta])* $vis:vis struct $name:ident { |
| 177 | $( | 182 | $( |
| 183 | $(#[doc = $doc:literal])* | ||
| 178 | $(#[cfg($cond_irq:meta)])? | 184 | $(#[cfg($cond_irq:meta)])? |
| 179 | $irq:ident => $( | 185 | $irq:ident => $( |
| 180 | $(#[cfg($cond_handler:meta)])? | 186 | $(#[cfg($cond_handler:meta)])? |
| @@ -183,18 +189,22 @@ macro_rules! bind_interrupts { | |||
| 183 | )* | 189 | )* |
| 184 | }) => { | 190 | }) => { |
| 185 | #[derive(Copy, Clone)] | 191 | #[derive(Copy, Clone)] |
| 192 | $(#[$outer])* | ||
| 186 | $vis struct $name; | 193 | $vis struct $name; |
| 187 | 194 | ||
| 188 | $( | 195 | $( |
| 189 | #[allow(non_snake_case)] | 196 | #[allow(non_snake_case)] |
| 190 | #[no_mangle] | 197 | #[no_mangle] |
| 191 | $(#[cfg($cond_irq)])? | 198 | $(#[cfg($cond_irq)])? |
| 199 | $(#[doc = $doc])* | ||
| 192 | unsafe extern "C" fn $irq() { | 200 | unsafe extern "C" fn $irq() { |
| 193 | $( | 201 | unsafe { |
| 194 | $(#[cfg($cond_handler)])? | 202 | $( |
| 195 | <$handler as $crate::interrupt::typelevel::Handler<$crate::interrupt::typelevel::$irq>>::on_interrupt(); | 203 | $(#[cfg($cond_handler)])? |
| 204 | <$handler as $crate::interrupt::typelevel::Handler<$crate::interrupt::typelevel::$irq>>::on_interrupt(); | ||
| 196 | 205 | ||
| 197 | )* | 206 | )* |
| 207 | } | ||
| 198 | } | 208 | } |
| 199 | 209 | ||
| 200 | $(#[cfg($cond_irq)])? | 210 | $(#[cfg($cond_irq)])? |
| @@ -236,12 +246,12 @@ pub struct Config { | |||
| 236 | #[cfg(dbgmcu)] | 246 | #[cfg(dbgmcu)] |
| 237 | pub enable_debug_during_sleep: bool, | 247 | pub enable_debug_during_sleep: bool, |
| 238 | 248 | ||
| 239 | /// On low-power boards (eg. `stm32l4`, `stm32l5` and `stm32u5`), | 249 | /// On low-power boards (eg. `stm32l4`, `stm32l5`, `stm32wba` and `stm32u5`), |
| 240 | /// some GPIO pins are powered by an auxiliary, independent power supply (`VDDIO2`), | 250 | /// some GPIO pins are powered by an auxiliary, independent power supply (`VDDIO2`), |
| 241 | /// which needs to be enabled before these pins can be used. | 251 | /// which needs to be enabled before these pins can be used. |
| 242 | /// | 252 | /// |
| 243 | /// May increase power consumption. Defaults to true. | 253 | /// May increase power consumption. Defaults to true. |
| 244 | #[cfg(any(stm32l4, stm32l5, stm32u5))] | 254 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba))] |
| 245 | pub enable_independent_io_supply: bool, | 255 | pub enable_independent_io_supply: bool, |
| 246 | 256 | ||
| 247 | /// On the U5 series all analog peripherals are powered by a separate supply. | 257 | /// On the U5 series all analog peripherals are powered by a separate supply. |
| @@ -285,7 +295,7 @@ impl Default for Config { | |||
| 285 | rcc: Default::default(), | 295 | rcc: Default::default(), |
| 286 | #[cfg(dbgmcu)] | 296 | #[cfg(dbgmcu)] |
| 287 | enable_debug_during_sleep: true, | 297 | enable_debug_during_sleep: true, |
| 288 | #[cfg(any(stm32l4, stm32l5, stm32u5))] | 298 | #[cfg(any(stm32l4, stm32l5, stm32u5, stm32wba))] |
| 289 | enable_independent_io_supply: true, | 299 | enable_independent_io_supply: true, |
| 290 | #[cfg(stm32u5)] | 300 | #[cfg(stm32u5)] |
| 291 | enable_independent_analog_supply: true, | 301 | enable_independent_analog_supply: true, |
| @@ -516,7 +526,7 @@ fn init_hw(config: Config) -> Peripherals { | |||
| 516 | } | 526 | } |
| 517 | }); | 527 | }); |
| 518 | 528 | ||
| 519 | #[cfg(not(any(stm32f1, stm32wb, stm32wl)))] | 529 | #[cfg(not(any(stm32f1, stm32wb, stm32wl, stm32h7rs)))] |
| 520 | rcc::enable_and_reset_with_cs::<peripherals::SYSCFG>(cs); | 530 | rcc::enable_and_reset_with_cs::<peripherals::SYSCFG>(cs); |
| 521 | #[cfg(not(any(stm32h5, stm32h7, stm32h7rs, stm32wb, stm32wl)))] | 531 | #[cfg(not(any(stm32h5, stm32h7, stm32h7rs, stm32wb, stm32wl)))] |
| 522 | rcc::enable_and_reset_with_cs::<peripherals::PWR>(cs); | 532 | rcc::enable_and_reset_with_cs::<peripherals::PWR>(cs); |
| @@ -534,6 +544,17 @@ fn init_hw(config: Config) -> Peripherals { | |||
| 534 | w.set_iosv(config.enable_independent_io_supply); | 544 | w.set_iosv(config.enable_independent_io_supply); |
| 535 | }); | 545 | }); |
| 536 | } | 546 | } |
| 547 | #[cfg(stm32wba)] | ||
| 548 | { | ||
| 549 | use crate::pac::pwr::vals; | ||
| 550 | crate::pac::PWR.svmcr().modify(|w| { | ||
| 551 | w.set_io2sv(if config.enable_independent_io_supply { | ||
| 552 | vals::Io2sv::B_0X1 | ||
| 553 | } else { | ||
| 554 | vals::Io2sv::B_0X0 | ||
| 555 | }); | ||
| 556 | }); | ||
| 557 | } | ||
| 537 | #[cfg(stm32u5)] | 558 | #[cfg(stm32u5)] |
| 538 | { | 559 | { |
| 539 | crate::pac::PWR.svmcr().modify(|w| { | 560 | crate::pac::PWR.svmcr().modify(|w| { |
| @@ -600,17 +621,7 @@ fn init_hw(config: Config) -> Peripherals { | |||
| 600 | #[cfg(feature = "exti")] | 621 | #[cfg(feature = "exti")] |
| 601 | exti::init(cs); | 622 | exti::init(cs); |
| 602 | 623 | ||
| 603 | rcc::init(config.rcc); | 624 | 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 | } | 625 | } |
| 615 | 626 | ||
| 616 | p | 627 | p |
