Skip to content

Commit 81f94ad

Browse files
elagilferris
authored andcommitted
feat: add optional USB SOF output
1 parent feea757 commit 81f94ad

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

embassy-stm32/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ fn main() {
876876
(("ltdc", "B7"), quote!(crate::ltdc::B7Pin)),
877877
(("usb", "DP"), quote!(crate::usb::DpPin)),
878878
(("usb", "DM"), quote!(crate::usb::DmPin)),
879+
(("usb", "SOF"), quote!(crate::usb::SofPin)),
879880
(("otg", "DP"), quote!(crate::usb::DpPin)),
880881
(("otg", "DM"), quote!(crate::usb::DmPin)),
881882
(("otg", "ULPI_CK"), quote!(crate::usb::UlpiClkPin)),

embassy-stm32/src/usb/usb.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,26 @@ pub struct Driver<'d, T: Instance> {
292292
}
293293

294294
impl<'d, T: Instance> Driver<'d, T> {
295+
/// Create a new USB driver with start-of-frame (SOF) output.
296+
pub fn new_with_sof(
297+
_usb: impl Peripheral<P = T> + 'd,
298+
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
299+
dp: impl Peripheral<P = impl DpPin<T>> + 'd,
300+
dm: impl Peripheral<P = impl DmPin<T>> + 'd,
301+
sof: impl Peripheral<P = impl SofPin<T>> + 'd,
302+
) -> Self {
303+
into_ref!(sof);
304+
#[cfg(not(stm32l1))]
305+
{
306+
use crate::gpio::{AfType, OutputType, Speed};
307+
sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh));
308+
}
309+
#[cfg(stm32l1)]
310+
let _ = sof; // suppress "unused" warning.
311+
312+
Self::new(_usb, _irq, dp, dm)
313+
}
314+
295315
/// Create a new USB driver.
296316
pub fn new(
297317
_usb: impl Peripheral<P = T> + 'd,
@@ -1221,6 +1241,7 @@ pub trait Instance: SealedInstance + RccPeripheral + 'static {
12211241
// Internal PHY pins
12221242
pin_trait!(DpPin, Instance);
12231243
pin_trait!(DmPin, Instance);
1244+
pin_trait!(SofPin, Instance);
12241245

12251246
foreach_interrupt!(
12261247
($inst:ident, usb, $block:ident, LP, $irq:ident) => {

0 commit comments

Comments
 (0)