diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs index 51cfe4a24..b7af877b7 100644 --- a/embassy-stm32/src/ucpd.rs +++ b/embassy-stm32/src/ucpd.rs @@ -24,6 +24,7 @@ use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; use crate::dma::{AnyChannel, Request, Transfer, TransferOptions}; use crate::interrupt; +use crate::interrupt::typelevel::Interrupt; use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode}; pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, TypecVstateCc as CcVState}; use crate::rcc::RccPeripheral; @@ -93,10 +94,13 @@ impl<'d, T: Instance> Ucpd<'d, T> { /// Creates a new UCPD driver instance. pub fn new( _peri: impl Peripheral

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

> + 'd, _cc2: impl Peripheral

> + 'd, ) -> Self { T::enable_and_reset(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; let r = T::REGS; r.cfgr1().write(|w| { @@ -206,6 +210,7 @@ impl<'d, T: Instance> Drop for CcPhy<'d, T> { } else { r.cfgr1().write(|w| w.set_ucpden(false)); T::disable(); + T::Interrupt::disable(); } } } @@ -323,6 +328,7 @@ impl<'d, T: Instance> Drop for PdPhy<'d, T> { } else { r.cfgr1().write(|w| w.set_ucpden(false)); T::disable(); + T::Interrupt::disable(); } } } diff --git a/examples/stm32g4/src/bin/usb_c_pd.rs b/examples/stm32g4/src/bin/usb_c_pd.rs index 0e80840df..c850b2753 100644 --- a/examples/stm32g4/src/bin/usb_c_pd.rs +++ b/examples/stm32g4/src/bin/usb_c_pd.rs @@ -4,10 +4,14 @@ use defmt::{error, info, Format}; use embassy_executor::Spawner; use embassy_stm32::ucpd::{self, CcPhy, CcPull, CcSel, CcVState, Ucpd}; -use embassy_stm32::Config; +use embassy_stm32::{bind_interrupts, peripherals, Config}; use embassy_time::{with_timeout, Duration}; use {defmt_rtt as _, panic_probe as _}; +bind_interrupts!(struct Irqs { + UCPD1 => ucpd::InterruptHandler; +}); + #[derive(Debug, Format)] enum CableOrientation { Normal, @@ -50,7 +54,7 @@ async fn main(_spawner: Spawner) { info!("Hello World!"); - let mut ucpd = Ucpd::new(p.UCPD1, p.PB6, p.PB4); + let mut ucpd = Ucpd::new(p.UCPD1, Irqs {}, p.PB6, p.PB4); ucpd.cc_phy().set_pull(CcPull::Sink); info!("Waiting for USB connection...");