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,
+ 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) => {