diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-03-26 16:29:45 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-26 16:29:45 +0000 |
| commit | f3a0bcb15eb7f7d1b2f9d948f8d487b76a4308fe (patch) | |
| tree | 116aa9a8b9c756dc3dcf634ab3c1d86354436c4e | |
| parent | cdd1c671e941798d30b05349190eddd63b15379b (diff) | |
| parent | 402def86ee6a1d8695fc0a4cf157d1ffca7550d9 (diff) | |
Merge pull request #2737 from adri326/adri326/add-iosv-option
Add a config option to make the VDDIO2 supply line valid
| -rw-r--r-- | embassy-stm32/src/gpio.rs | 7 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 28 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/spe_adin1110_http_server.rs | 6 | ||||
| -rw-r--r-- | tests/stm32/src/common.rs | 7 |
4 files changed, 28 insertions, 20 deletions
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 33f22f676..214813a42 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -779,13 +779,6 @@ pub(crate) unsafe fn init(_cs: CriticalSection) { | |||
| 779 | <crate::peripherals::AFIO as crate::rcc::SealedRccPeripheral>::enable_and_reset_with_cs(_cs); | 779 | <crate::peripherals::AFIO as crate::rcc::SealedRccPeripheral>::enable_and_reset_with_cs(_cs); |
| 780 | 780 | ||
| 781 | crate::_generated::init_gpio(); | 781 | crate::_generated::init_gpio(); |
| 782 | |||
| 783 | // Setting this bit is mandatory to use PG[15:2]. | ||
| 784 | #[cfg(stm32u5)] | ||
| 785 | crate::pac::PWR.svmcr().modify(|w| { | ||
| 786 | w.set_io2sv(true); | ||
| 787 | w.set_io2vmen(true); | ||
| 788 | }); | ||
| 789 | } | 782 | } |
| 790 | 783 | ||
| 791 | impl<'d> embedded_hal_02::digital::v2::InputPin for Input<'d> { | 784 | impl<'d> embedded_hal_02::digital::v2::InputPin for Input<'d> { |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 6a3d1c463..ab6ef8ef4 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -172,6 +172,14 @@ pub struct Config { | |||
| 172 | #[cfg(dbgmcu)] | 172 | #[cfg(dbgmcu)] |
| 173 | pub enable_debug_during_sleep: bool, | 173 | pub enable_debug_during_sleep: bool, |
| 174 | 174 | ||
| 175 | /// On low-power boards (eg. `stm32l4`, `stm32l5` and `stm32u5`), | ||
| 176 | /// some GPIO pins are powered by an auxiliary, independent power supply (`VDDIO2`), | ||
| 177 | /// which needs to be enabled before these pins can be used. | ||
| 178 | /// | ||
| 179 | /// May increase power consumption. Defaults to true. | ||
| 180 | #[cfg(any(stm32l4, stm32l5, stm32u5))] | ||
| 181 | pub enable_independent_io_supply: bool, | ||
| 182 | |||
| 175 | /// BDMA interrupt priority. | 183 | /// BDMA interrupt priority. |
| 176 | /// | 184 | /// |
| 177 | /// Defaults to P0 (highest). | 185 | /// Defaults to P0 (highest). |
| @@ -209,6 +217,8 @@ impl Default for Config { | |||
| 209 | rcc: Default::default(), | 217 | rcc: Default::default(), |
| 210 | #[cfg(dbgmcu)] | 218 | #[cfg(dbgmcu)] |
| 211 | enable_debug_during_sleep: true, | 219 | enable_debug_during_sleep: true, |
| 220 | #[cfg(any(stm32l4, stm32l5, stm32u5))] | ||
| 221 | enable_independent_io_supply: true, | ||
| 212 | #[cfg(bdma)] | 222 | #[cfg(bdma)] |
| 213 | bdma_interrupt_priority: Priority::P0, | 223 | bdma_interrupt_priority: Priority::P0, |
| 214 | #[cfg(dma)] | 224 | #[cfg(dma)] |
| @@ -270,6 +280,24 @@ pub fn init(config: Config) -> Peripherals { | |||
| 270 | #[cfg(not(any(stm32f2, stm32f4, stm32f7, stm32l0, stm32h5, stm32h7)))] | 280 | #[cfg(not(any(stm32f2, stm32f4, stm32f7, stm32l0, stm32h5, stm32h7)))] |
| 271 | peripherals::FLASH::enable_and_reset_with_cs(cs); | 281 | peripherals::FLASH::enable_and_reset_with_cs(cs); |
| 272 | 282 | ||
| 283 | // Enable the VDDIO2 power supply on chips that have it. | ||
| 284 | // Note that this requires the PWR peripheral to be enabled first. | ||
| 285 | #[cfg(any(stm32l4, stm32l5))] | ||
| 286 | { | ||
| 287 | crate::pac::PWR.cr2().modify(|w| { | ||
| 288 | // The official documentation states that we should ideally enable VDDIO2 | ||
| 289 | // through the PVME2 bit, but it looks like this isn't required, | ||
| 290 | // and CubeMX itself skips this step. | ||
| 291 | w.set_iosv(config.enable_independent_io_supply); | ||
| 292 | }); | ||
| 293 | } | ||
| 294 | #[cfg(stm32u5)] | ||
| 295 | { | ||
| 296 | crate::pac::PWR.svmcr().modify(|w| { | ||
| 297 | w.set_io2sv(config.enable_independent_io_supply); | ||
| 298 | }); | ||
| 299 | } | ||
| 300 | |||
| 273 | // dead battery functionality is still present on these | 301 | // dead battery functionality is still present on these |
| 274 | // chips despite them not having UCPD- disable it | 302 | // chips despite them not having UCPD- disable it |
| 275 | #[cfg(any(stm32g070, stm32g0b0))] | 303 | #[cfg(any(stm32g070, stm32g0b0))] |
diff --git a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs index 343e09e68..77aa929ab 100644 --- a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs +++ b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs | |||
| @@ -93,12 +93,6 @@ async fn main(spawner: Spawner) { | |||
| 93 | 93 | ||
| 94 | let dp = embassy_stm32::init(config); | 94 | let dp = embassy_stm32::init(config); |
| 95 | 95 | ||
| 96 | // RM0432rev9, 5.1.2: Independent I/O supply rail | ||
| 97 | // After reset, the I/Os supplied by VDDIO2 are logically and electrically isolated and | ||
| 98 | // therefore are not available. The isolation must be removed before using any I/O from | ||
| 99 | // PG[15:2], by setting the IOSV bit in the PWR_CR2 register, once the VDDIO2 supply is present | ||
| 100 | pac::PWR.cr2().modify(|w| w.set_iosv(true)); | ||
| 101 | |||
| 102 | let reset_status = pac::RCC.bdcr().read().0; | 96 | let reset_status = pac::RCC.bdcr().read().0; |
| 103 | defmt::println!("bdcr before: 0x{:X}", reset_status); | 97 | defmt::println!("bdcr before: 0x{:X}", reset_status); |
| 104 | 98 | ||
diff --git a/tests/stm32/src/common.rs b/tests/stm32/src/common.rs index c379863a8..0e555efc8 100644 --- a/tests/stm32/src/common.rs +++ b/tests/stm32/src/common.rs | |||
| @@ -251,13 +251,6 @@ define_peris!( | |||
| 251 | ); | 251 | ); |
| 252 | 252 | ||
| 253 | pub fn config() -> Config { | 253 | pub fn config() -> Config { |
| 254 | // Setting this bit is mandatory to use PG[15:2]. | ||
| 255 | #[cfg(feature = "stm32u5a5zj")] | ||
| 256 | embassy_stm32::pac::PWR.svmcr().modify(|w| { | ||
| 257 | w.set_io2sv(true); | ||
| 258 | w.set_io2vmen(true); | ||
| 259 | }); | ||
| 260 | |||
| 261 | #[allow(unused_mut)] | 254 | #[allow(unused_mut)] |
| 262 | let mut config = Config::default(); | 255 | let mut config = Config::default(); |
| 263 | 256 | ||
