diff --git a/hal/src/peripherals/usb/d5x/bus.rs b/hal/src/peripherals/usb/d5x/bus.rs index 1441ff780dc2..9cf265b6ca19 100644 --- a/hal/src/peripherals/usb/d5x/bus.rs +++ b/hal/src/peripherals/usb/d5x/bus.rs @@ -8,6 +8,8 @@ use super::Descriptors; use crate::calibration::{usb_transn_cal, usb_transp_cal, usb_trim_cal}; use crate::clock; +use crate::clock::v2::pclk::{Pclk, PclkSourceId}; +use crate::clock::v2::types::Usb as UsbClk; use crate::gpio::{AlternateH, AnyPin, Pin, PA24, PA25}; use crate::pac; use crate::pac::usb::Device; @@ -549,6 +551,31 @@ impl UsbBus { inner: Mutex::new(RefCell::new(inner)), } } + + pub fn new_with_v2_clock( + _pclk: Pclk, + mclk: &mut Mclk, + dm_pad: impl AnyPin, + dp_pad: impl AnyPin, + _usb: Usb, + ) -> Self { + mclk.ahbmask().modify(|_, w| w.usb_().set_bit()); + mclk.apbbmask().modify(|_, w| w.usb_().set_bit()); + + let desc = RefCell::new(Descriptors::new()); + + let inner = Inner { + _dm_pad: dm_pad.into().into_mode::(), + _dp_pad: dp_pad.into().into_mode::(), + desc, + buffers: RefCell::new(BufferAllocator::new()), + endpoints: RefCell::new(AllEndpoints::new()), + }; + + Self { + inner: Mutex::new(RefCell::new(inner)), + } + } } impl Inner {