diff options
| author | Kevin <[email protected]> | 2024-09-22 01:11:32 +0200 |
|---|---|---|
| committer | Kevin <[email protected]> | 2024-09-22 01:11:32 +0200 |
| commit | 85b7c8957cce3fef6011e63d7cb6ff85912ccb50 (patch) | |
| tree | d0983ad3d288521b1ae5547d367dc78a9afd619b | |
| parent | 6d9af8304cf88dbfa3713acfef4d89ba3a95c2d8 (diff) | |
Add presence check for OTG_HS peripheral on STM32H7R/S series
| -rw-r--r-- | embassy-stm32/build.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/h.rs | 14 |
2 files changed, 10 insertions, 8 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 19cf193d9..28c619c6b 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -55,7 +55,7 @@ fn main() { | |||
| 55 | let mut singletons: Vec<String> = Vec::new(); | 55 | let mut singletons: Vec<String> = Vec::new(); |
| 56 | for p in METADATA.peripherals { | 56 | for p in METADATA.peripherals { |
| 57 | if let Some(r) = &p.registers { | 57 | if let Some(r) = &p.registers { |
| 58 | if r.kind == "adccommon" || r.kind == "sai" || r.kind == "ucpd" { | 58 | if r.kind == "adccommon" || r.kind == "sai" || r.kind == "ucpd" || r.kind == "otg" { |
| 59 | // TODO: should we emit this for all peripherals? if so, we will need a list of all | 59 | // TODO: should we emit this for all peripherals? if so, we will need a list of all |
| 60 | // possible peripherals across all chips, so that we can declare the configs | 60 | // possible peripherals across all chips, so that we can declare the configs |
| 61 | // (replacing the hard-coded list of `peri_*` cfgs below) | 61 | // (replacing the hard-coded list of `peri_*` cfgs below) |
| @@ -111,6 +111,8 @@ fn main() { | |||
| 111 | "peri_sai4", | 111 | "peri_sai4", |
| 112 | "peri_ucpd1", | 112 | "peri_ucpd1", |
| 113 | "peri_ucpd2", | 113 | "peri_ucpd2", |
| 114 | "peri_usb_otg_fs", | ||
| 115 | "peri_usb_otg_hs", | ||
| 114 | ]); | 116 | ]); |
| 115 | cfgs.declare_all(&["mco", "mco1", "mco2"]); | 117 | cfgs.declare_all(&["mco", "mco1", "mco2"]); |
| 116 | 118 | ||
diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs index cd1c10407..55fe8ca9d 100644 --- a/embassy-stm32/src/rcc/h.rs +++ b/embassy-stm32/src/rcc/h.rs | |||
| @@ -34,11 +34,10 @@ pub enum VoltageScale { | |||
| 34 | Scale2, | 34 | Scale2, |
| 35 | Scale3, | 35 | Scale3, |
| 36 | } | 36 | } |
| 37 | #[cfg(any(stm32h7rs))] | 37 | #[cfg(stm32h7rs)] |
| 38 | pub use crate::pac::{ | 38 | pub use crate::pac::pwr::vals::Vos as VoltageScale; |
| 39 | pwr::vals::Vos as VoltageScale, | 39 | #[cfg(all(stm32h7rs, peri_usb_otg_hs))] |
| 40 | rcc::vals::{Usbphycsel, Usbrefcksel}, | 40 | pub use crate::pac::rcc::vals::{Usbphycsel, Usbrefcksel}; |
| 41 | }; | ||
| 42 | 41 | ||
| 43 | #[derive(Clone, Copy, Eq, PartialEq)] | 42 | #[derive(Clone, Copy, Eq, PartialEq)] |
| 44 | pub enum HseMode { | 43 | pub enum HseMode { |
| @@ -560,14 +559,14 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 560 | 559 | ||
| 561 | let rtc = config.ls.init(); | 560 | let rtc = config.ls.init(); |
| 562 | 561 | ||
| 563 | #[cfg(stm32h7rs)] | 562 | #[cfg(all(stm32h7rs, peri_usb_otg_hs))] |
| 564 | let usb_refck = match config.mux.usbphycsel { | 563 | let usb_refck = match config.mux.usbphycsel { |
| 565 | Usbphycsel::HSE => hse, | 564 | Usbphycsel::HSE => hse, |
| 566 | Usbphycsel::HSE_DIV_2 => hse.map(|hse_val| hse_val / 2u8), | 565 | Usbphycsel::HSE_DIV_2 => hse.map(|hse_val| hse_val / 2u8), |
| 567 | Usbphycsel::PLL3_Q => pll3.q, | 566 | Usbphycsel::PLL3_Q => pll3.q, |
| 568 | _ => None, | 567 | _ => None, |
| 569 | }; | 568 | }; |
| 570 | #[cfg(stm32h7rs)] | 569 | #[cfg(all(stm32h7rs, peri_usb_otg_hs))] |
| 571 | let usb_refck_sel = match usb_refck { | 570 | let usb_refck_sel = match usb_refck { |
| 572 | Some(clk_val) => match clk_val { | 571 | Some(clk_val) => match clk_val { |
| 573 | Hertz(16_000_000) => Usbrefcksel::MHZ16, | 572 | Hertz(16_000_000) => Usbrefcksel::MHZ16, |
| @@ -618,6 +617,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 618 | w.set_ppre5(config.apb5_pre); | 617 | w.set_ppre5(config.apb5_pre); |
| 619 | }); | 618 | }); |
| 620 | 619 | ||
| 620 | #[cfg(peri_usb_otg_hs)] | ||
| 621 | RCC.ahbperckselr().modify(|w| { | 621 | RCC.ahbperckselr().modify(|w| { |
| 622 | w.set_usbrefcksel(usb_refck_sel); | 622 | w.set_usbrefcksel(usb_refck_sel); |
| 623 | }); | 623 | }); |
