diff options
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/usb/mod.rs | 28 | ||||
| -rw-r--r-- | embassy-stm32/src/usb/otg.rs | 21 |
3 files changed, 46 insertions, 7 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index c086fbbcf..c28636dc8 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -81,7 +81,7 @@ futures-util = { version = "0.3.30", default-features = false } | |||
| 81 | sdio-host = "0.9.0" | 81 | sdio-host = "0.9.0" |
| 82 | critical-section = "1.1" | 82 | critical-section = "1.1" |
| 83 | #stm32-metapac = { version = "16" } | 83 | #stm32-metapac = { version = "16" } |
| 84 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-019a3ce0ea3b5bd832ec2ad53465a0d80b0f4e0a" } | 84 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-60582dd866b34e690f156cd72b91300a9a8057c0" } |
| 85 | 85 | ||
| 86 | vcell = "0.1.3" | 86 | vcell = "0.1.3" |
| 87 | nb = "1.0.0" | 87 | nb = "1.0.0" |
| @@ -110,7 +110,7 @@ proc-macro2 = "1.0.36" | |||
| 110 | quote = "1.0.15" | 110 | quote = "1.0.15" |
| 111 | 111 | ||
| 112 | #stm32-metapac = { version = "16", default-features = false, features = ["metadata"]} | 112 | #stm32-metapac = { version = "16", default-features = false, features = ["metadata"]} |
| 113 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-019a3ce0ea3b5bd832ec2ad53465a0d80b0f4e0a", default-features = false, features = ["metadata"] } | 113 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-60582dd866b34e690f156cd72b91300a9a8057c0", default-features = false, features = ["metadata"] } |
| 114 | 114 | ||
| 115 | [features] | 115 | [features] |
| 116 | default = ["rt"] | 116 | default = ["rt"] |
diff --git a/embassy-stm32/src/usb/mod.rs b/embassy-stm32/src/usb/mod.rs index ae5963420..692897b59 100644 --- a/embassy-stm32/src/usb/mod.rs +++ b/embassy-stm32/src/usb/mod.rs | |||
| @@ -15,7 +15,7 @@ fn common_init<T: Instance>() { | |||
| 15 | let freq = T::frequency(); | 15 | let freq = T::frequency(); |
| 16 | 16 | ||
| 17 | // On the H7RS, the USBPHYC embeds a PLL accepting one of the input frequencies listed below and providing 48MHz to OTG_FS and 60MHz to OTG_HS internally | 17 | // On the H7RS, the USBPHYC embeds a PLL accepting one of the input frequencies listed below and providing 48MHz to OTG_FS and 60MHz to OTG_HS internally |
| 18 | #[cfg(any(stm32h7rs, all(stm32u5, peri_usb_otg_hs)))] | 18 | #[cfg(any(stm32h7rs, all(stm32u5, peri_usb_otg_hs), all(stm32wba, peri_usb_otg_hs)))] |
| 19 | if ![16_000_000, 19_200_000, 20_000_000, 24_000_000, 26_000_000, 32_000_000].contains(&freq.0) { | 19 | if ![16_000_000, 19_200_000, 20_000_000, 24_000_000, 26_000_000, 32_000_000].contains(&freq.0) { |
| 20 | panic!( | 20 | panic!( |
| 21 | "USB clock should be one of 16, 19.2, 20, 24, 26, 32Mhz but is {} Hz. Please double-check your RCC settings.", | 21 | "USB clock should be one of 16, 19.2, 20, 24, 26, 32Mhz but is {} Hz. Please double-check your RCC settings.", |
| @@ -25,7 +25,7 @@ fn common_init<T: Instance>() { | |||
| 25 | // Check frequency is within the 0.25% tolerance allowed by the spec. | 25 | // Check frequency is within the 0.25% tolerance allowed by the spec. |
| 26 | // Clock might not be exact 48Mhz due to rounding errors in PLL calculation, or if the user | 26 | // Clock might not be exact 48Mhz due to rounding errors in PLL calculation, or if the user |
| 27 | // has tight clock restrictions due to something else (like audio). | 27 | // has tight clock restrictions due to something else (like audio). |
| 28 | #[cfg(not(any(stm32h7rs, all(stm32u5, peri_usb_otg_hs))))] | 28 | #[cfg(not(any(stm32h7rs, all(stm32u5, peri_usb_otg_hs), all(stm32wba, peri_usb_otg_hs))))] |
| 29 | if freq.0.abs_diff(48_000_000) > 120_000 { | 29 | if freq.0.abs_diff(48_000_000) > 120_000 { |
| 30 | panic!( | 30 | panic!( |
| 31 | "USB clock should be 48Mhz but is {} Hz. Please double-check your RCC settings.", | 31 | "USB clock should be 48Mhz but is {} Hz. Please double-check your RCC settings.", |
| @@ -102,6 +102,30 @@ fn common_init<T: Instance>() { | |||
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | #[cfg(stm32wba)] | ||
| 106 | { | ||
| 107 | // Enable USB power | ||
| 108 | critical_section::with(|_| { | ||
| 109 | crate::pac::PWR.svmcr().modify(|w| { | ||
| 110 | w.set_usv(crate::pac::pwr::vals::Usv::B_0X1); | ||
| 111 | // w.set_uvmen(true); | ||
| 112 | }) | ||
| 113 | }); | ||
| 114 | |||
| 115 | // Wait for USB power to stabilize | ||
| 116 | while !crate::pac::PWR.vosr().read().vdd11usbrdy() {} | ||
| 117 | |||
| 118 | // Now set up transceiver power if it's a OTG-HS | ||
| 119 | #[cfg(peri_usb_otg_hs)] | ||
| 120 | { | ||
| 121 | crate::pac::PWR.vosr().modify(|w| { | ||
| 122 | w.set_usbpwren(true); | ||
| 123 | w.set_usbboosten(true); | ||
| 124 | }); | ||
| 125 | while !crate::pac::PWR.vosr().read().usbboostrdy() {} | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 105 | T::Interrupt::unpend(); | 129 | T::Interrupt::unpend(); |
| 106 | unsafe { T::Interrupt::enable() }; | 130 | unsafe { T::Interrupt::enable() }; |
| 107 | 131 | ||
diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs index 590d1a427..d664709d3 100644 --- a/embassy-stm32/src/usb/otg.rs +++ b/embassy-stm32/src/usb/otg.rs | |||
| @@ -105,7 +105,7 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 105 | config: Config, | 105 | config: Config, |
| 106 | ) -> Self { | 106 | ) -> Self { |
| 107 | // For STM32U5 High speed pins need to be left in analog mode | 107 | // For STM32U5 High speed pins need to be left in analog mode |
| 108 | #[cfg(not(all(stm32u5, peri_usb_otg_hs)))] | 108 | #[cfg(not(any(all(stm32u5, peri_usb_otg_hs),all(stm32wba, peri_usb_otg_hs))))] |
| 109 | { | 109 | { |
| 110 | _dp.set_as_af(_dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 110 | _dp.set_as_af(_dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 111 | _dm.set_as_af(_dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 111 | _dm.set_as_af(_dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| @@ -323,6 +323,20 @@ impl<'d, T: Instance> Bus<'d, T> { | |||
| 323 | }); | 323 | }); |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | #[cfg(all(stm32wba, peri_usb_otg_hs))] | ||
| 327 | { | ||
| 328 | crate::pac::SYSCFG.otghsphycr().modify(|w| { | ||
| 329 | w.set_en(true); | ||
| 330 | }); | ||
| 331 | |||
| 332 | critical_section::with(|_| { | ||
| 333 | crate::pac::RCC.ahb2enr().modify(|w| { | ||
| 334 | w.set_otgen(true); | ||
| 335 | w.set_otghsphyen(true); | ||
| 336 | }); | ||
| 337 | }); | ||
| 338 | } | ||
| 339 | |||
| 326 | let r = T::regs(); | 340 | let r = T::regs(); |
| 327 | let core_id = r.cid().read().0; | 341 | let core_id = r.cid().read().0; |
| 328 | trace!("Core id {:08x}", core_id); | 342 | trace!("Core id {:08x}", core_id); |
| @@ -464,6 +478,7 @@ foreach_interrupt!( | |||
| 464 | stm32f7, | 478 | stm32f7, |
| 465 | stm32l4, | 479 | stm32l4, |
| 466 | stm32u5, | 480 | stm32u5, |
| 481 | stm32wba, | ||
| 467 | ))] { | 482 | ))] { |
| 468 | const FIFO_DEPTH_WORDS: u16 = 320; | 483 | const FIFO_DEPTH_WORDS: u16 = 320; |
| 469 | const ENDPOINT_COUNT: usize = 6; | 484 | const ENDPOINT_COUNT: usize = 6; |
| @@ -473,7 +488,7 @@ foreach_interrupt!( | |||
| 473 | } else if #[cfg(any(stm32h7, stm32h7rs))] { | 488 | } else if #[cfg(any(stm32h7, stm32h7rs))] { |
| 474 | const FIFO_DEPTH_WORDS: u16 = 1024; | 489 | const FIFO_DEPTH_WORDS: u16 = 1024; |
| 475 | const ENDPOINT_COUNT: usize = 9; | 490 | const ENDPOINT_COUNT: usize = 9; |
| 476 | } else if #[cfg(stm32u5)] { | 491 | } else if #[cfg(any(stm32wba, stm32u5))] { |
| 477 | const FIFO_DEPTH_WORDS: u16 = 320; | 492 | const FIFO_DEPTH_WORDS: u16 = 320; |
| 478 | const ENDPOINT_COUNT: usize = 6; | 493 | const ENDPOINT_COUNT: usize = 6; |
| 479 | } else { | 494 | } else { |
| @@ -523,7 +538,7 @@ foreach_interrupt!( | |||
| 523 | ))] { | 538 | ))] { |
| 524 | const FIFO_DEPTH_WORDS: u16 = 1024; | 539 | const FIFO_DEPTH_WORDS: u16 = 1024; |
| 525 | const ENDPOINT_COUNT: usize = 9; | 540 | const ENDPOINT_COUNT: usize = 9; |
| 526 | } else if #[cfg(stm32u5)] { | 541 | } else if #[cfg(any(stm32wba, stm32u5))] { |
| 527 | const FIFO_DEPTH_WORDS: u16 = 1024; | 542 | const FIFO_DEPTH_WORDS: u16 = 1024; |
| 528 | const ENDPOINT_COUNT: usize = 9; | 543 | const ENDPOINT_COUNT: usize = 9; |
| 529 | } else { | 544 | } else { |
