Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion boards/atsame54_xpro/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,6 @@ pub fn usb_allocator(
let usb_gclk = clocks.get_gclk(Genselect::Gclk2).unwrap();
let usb_clock = &clocks.usb(&usb_gclk).unwrap();
let (dm, dp) = (dm.into(), dp.into());
UsbBusAllocator::new(UsbBus::new(usb_clock, mclk, dm, dp, usb))
/// Safety - V1 clocking API forces a 48Mhz USB clock
UsbBusAllocator::new(UsbBus::new(usb_clock, mclk, dm, dp, usb).unwrap())
}
3 changes: 2 additions & 1 deletion boards/feather_m4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,6 @@ pub fn usb_allocator(
let usb_gclk = clocks.get_gclk(Genselect::Gclk2).unwrap();
let usb_clock = &clocks.usb(&usb_gclk).unwrap();
let (dm, dp) = (dm.into(), dp.into());
UsbBusAllocator::new(UsbBus::new(usb_clock, mclk, dm, dp, usb))
/// Safety - V1 clocking API forces a 48Mhz USB clock
UsbBusAllocator::new(UsbBus::new(usb_clock, mclk, dm, dp, usb).unwrap())
}
3 changes: 2 additions & 1 deletion boards/metro_m4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,6 @@ pub fn usb_allocator(
let usb_gclk = clocks.get_gclk(Genselect::Gclk2).unwrap();
let usb_clock = &clocks.usb(&usb_gclk).unwrap();
let (dm, dp) = (dm.into(), dp.into());
UsbBusAllocator::new(UsbBus::new(usb_clock, mclk, dm, dp, usb))
/// Safety - V1 clocking API forces a 48Mhz USB clock
UsbBusAllocator::new(UsbBus::new(usb_clock, mclk, dm, dp, usb).unwrap())
}
3 changes: 2 additions & 1 deletion boards/pygamer/src/pins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ impl USB {
let usb_gclk = clocks.get_gclk(Genselect::Gclk2).unwrap();
let usb_clock = &clocks.usb(&usb_gclk).unwrap();
let (dm, dp): (UsbDm, UsbDp) = (self.dm.into(), self.dp.into());
UsbBusAllocator::new(UsbBus::new(usb_clock, mclk, dm, dp, usb))
/// Safety - V1 clocking API forces a 48Mhz USB clock
UsbBusAllocator::new(UsbBus::new(usb_clock, mclk, dm, dp, usb).unwrap())
}
}

Expand Down
3 changes: 3 additions & 0 deletions hal/src/peripherals/usb/d11/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ impl UsbBus {
dp_pad: impl AnyPin<Id = PA25>,
_usb: Usb,
) -> Self {
// Note for Clock V2 implementation - Check that USB
// Freq is 48Mhz and error out if it is not - Check
// the D5X implementation
pm.apbbmask().modify(|_, w| w.usb_().set_bit());

let desc = RefCell::new(Descriptors::new());
Expand Down
33 changes: 32 additions & 1 deletion hal/src/peripherals/usb/d5x/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,44 @@ impl Inner {
}
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum UsbBusErr {
/// USB clock freq is not valid for a stable connection
InvalidClockFreq,
}

impl UsbBus {
/// Create a new USB Bus, checking the clock frequency of the USB clock for
/// a stable USB link to most hosts. The `clock` freq must be 48Mhz, otherwise
/// [`UsbBusErr::InvalidClockFreq`] will be returned
pub fn new(
_clock: &clock::UsbClock,
clock: &clock::UsbClock,
mclk: &mut Mclk,
dm_pad: impl AnyPin<Id = PA24>,
dp_pad: impl AnyPin<Id = PA25>,
_usb: Usb,
) -> Result<Self, UsbBusErr> {
if clock.freq().to_Hz() != 48_000_000 {
Err(UsbBusErr::InvalidClockFreq)
} else {
let res = unsafe { Self::new_unchecked(clock, mclk, dm_pad, dp_pad) };
Ok(res)
}
}

/// Creates a new USB Bus, but does NOT perform the USB clock frequency check.
///
/// SAFETY: For a SAMx to PC connection, the USB clock must be 48Mhz for stability.
/// This function allows you to bypass this check however if you intend to connect multiple SAM chips
/// together with faster running USB clocks for a boost in transfer rate.
///
/// Consult the datasheet for GCLK_USB absolute maximums
pub unsafe fn new_unchecked(
_clock: &clock::UsbClock,
mclk: &mut Mclk,
dm_pad: impl AnyPin<Id = PA24>,
dp_pad: impl AnyPin<Id = PA25>,
) -> Self {
mclk.ahbmask().modify(|_, w| w.usb_().set_bit());
mclk.apbbmask().modify(|_, w| w.usb_().set_bit());
Expand Down
Loading