From f1db070f78ddbef92c8e14db43b4422b9a14c926 Mon Sep 17 00:00:00 2001 From: elagil Date: Wed, 12 Mar 2025 23:18:34 +0100 Subject: [PATCH 1/2] feat: add optional USB SOF output --- embassy-stm32/build.rs | 1 + embassy-stm32/src/usb/usb.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 83a836fb2..b35fd0300 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -876,6 +876,7 @@ fn main() { (("ltdc", "B7"), quote!(crate::ltdc::B7Pin)), (("usb", "DP"), quote!(crate::usb::DpPin)), (("usb", "DM"), quote!(crate::usb::DmPin)), + (("usb", "SOF"), quote!(crate::usb::SofPin)), (("otg", "DP"), quote!(crate::usb::DpPin)), (("otg", "DM"), quote!(crate::usb::DmPin)), (("otg", "ULPI_CK"), quote!(crate::usb::UlpiClkPin)), diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index b9a16bbf1..af639fc9b 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -287,6 +287,26 @@ pub struct Driver<'d, T: Instance> { } impl<'d, T: Instance> Driver<'d, T> { + /// Create a new USB driver with start-of-frame (SOF) output. + pub fn new_with_sof( + _usb: impl Peripheral

+ 'd, + _irq: impl interrupt::typelevel::Binding> + 'd, + dp: impl Peripheral

> + 'd, + dm: impl Peripheral

> + 'd, + sof: impl Peripheral

> + 'd, + ) -> Self { + into_ref!(sof); + #[cfg(not(stm32l1))] + { + use crate::gpio::{AfType, OutputType, Speed}; + sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); + } + #[cfg(stm32l1)] + let _ = sof; // suppress "unused" warning. + + Self::new(_usb, _irq, dp, dm) + } + /// Create a new USB driver. pub fn new( _usb: impl Peripheral

+ 'd, @@ -1208,6 +1228,7 @@ pub trait Instance: SealedInstance + RccPeripheral + 'static { // Internal PHY pins pin_trait!(DpPin, Instance); pin_trait!(DmPin, Instance); +pin_trait!(SofPin, Instance); foreach_interrupt!( ($inst:ident, usb, $block:ident, LP, $irq:ident) => { From 63f7a5da09b150de5077c02c5b1394af4d012676 Mon Sep 17 00:00:00 2001 From: elagil Date: Sun, 16 Mar 2025 22:02:43 +0100 Subject: [PATCH 2/2] fix: disable `new_with_sof` for STM32L1 --- embassy-stm32/src/usb/usb.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index af639fc9b..64ab3b669 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -288,6 +288,7 @@ pub struct Driver<'d, T: Instance> { impl<'d, T: Instance> Driver<'d, T> { /// Create a new USB driver with start-of-frame (SOF) output. + #[cfg(not(stm32l1))] pub fn new_with_sof( _usb: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -296,13 +297,10 @@ impl<'d, T: Instance> Driver<'d, T> { sof: impl Peripheral

> + 'd, ) -> Self { into_ref!(sof); - #[cfg(not(stm32l1))] { use crate::gpio::{AfType, OutputType, Speed}; sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); } - #[cfg(stm32l1)] - let _ = sof; // suppress "unused" warning. Self::new(_usb, _irq, dp, dm) }