aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelagil <[email protected]>2025-03-12 23:18:34 +0100
committerelagil <[email protected]>2025-03-12 23:18:34 +0100
commitf1db070f78ddbef92c8e14db43b4422b9a14c926 (patch)
tree634312bf63403872ee54ac6d4631f53039293b87
parent38f26137fc67beb874aa73c9a7ab2150d9f3d372 (diff)
feat: add optional USB SOF output
-rw-r--r--embassy-stm32/build.rs1
-rw-r--r--embassy-stm32/src/usb/usb.rs21
2 files changed, 22 insertions, 0 deletions
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() {
876 (("ltdc", "B7"), quote!(crate::ltdc::B7Pin)), 876 (("ltdc", "B7"), quote!(crate::ltdc::B7Pin)),
877 (("usb", "DP"), quote!(crate::usb::DpPin)), 877 (("usb", "DP"), quote!(crate::usb::DpPin)),
878 (("usb", "DM"), quote!(crate::usb::DmPin)), 878 (("usb", "DM"), quote!(crate::usb::DmPin)),
879 (("usb", "SOF"), quote!(crate::usb::SofPin)),
879 (("otg", "DP"), quote!(crate::usb::DpPin)), 880 (("otg", "DP"), quote!(crate::usb::DpPin)),
880 (("otg", "DM"), quote!(crate::usb::DmPin)), 881 (("otg", "DM"), quote!(crate::usb::DmPin)),
881 (("otg", "ULPI_CK"), quote!(crate::usb::UlpiClkPin)), 882 (("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> {
287} 287}
288 288
289impl<'d, T: Instance> Driver<'d, T> { 289impl<'d, T: Instance> Driver<'d, T> {
290 /// Create a new USB driver with start-of-frame (SOF) output.
291 pub fn new_with_sof(
292 _usb: impl Peripheral<P = T> + 'd,
293 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
294 dp: impl Peripheral<P = impl DpPin<T>> + 'd,
295 dm: impl Peripheral<P = impl DmPin<T>> + 'd,
296 sof: impl Peripheral<P = impl SofPin<T>> + 'd,
297 ) -> Self {
298 into_ref!(sof);
299 #[cfg(not(stm32l1))]
300 {
301 use crate::gpio::{AfType, OutputType, Speed};
302 sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
303 }
304 #[cfg(stm32l1)]
305 let _ = sof; // suppress "unused" warning.
306
307 Self::new(_usb, _irq, dp, dm)
308 }
309
290 /// Create a new USB driver. 310 /// Create a new USB driver.
291 pub fn new( 311 pub fn new(
292 _usb: impl Peripheral<P = T> + 'd, 312 _usb: impl Peripheral<P = T> + 'd,
@@ -1208,6 +1228,7 @@ pub trait Instance: SealedInstance + RccPeripheral + 'static {
1208// Internal PHY pins 1228// Internal PHY pins
1209pin_trait!(DpPin, Instance); 1229pin_trait!(DpPin, Instance);
1210pin_trait!(DmPin, Instance); 1230pin_trait!(DmPin, Instance);
1231pin_trait!(SofPin, Instance);
1211 1232
1212foreach_interrupt!( 1233foreach_interrupt!(
1213 ($inst:ident, usb, $block:ident, LP, $irq:ident) => { 1234 ($inst:ident, usb, $block:ident, LP, $irq:ident) => {