1use crate::rcc::{Enable, Reset};
9use crate::stm32::USB;
10use stm32_usbd::UsbPeripheral;
11
12use crate::gpio::gpioa::{PA11, PA12};
13use crate::gpio::{Alternate, PushPull};
14pub use stm32_usbd::UsbBus;
15
16pub struct Peripheral {
17 pub usb: USB,
18 pub pin_dm: PA11<Alternate<PushPull, 10>>,
19 pub pin_dp: PA12<Alternate<PushPull, 10>>,
20}
21
22unsafe impl Sync for Peripheral {}
23
24unsafe impl UsbPeripheral for Peripheral {
25 const REGISTERS: *const () = USB::ptr() as *const ();
26 const DP_PULL_UP_FEATURE: bool = true;
27 const EP_MEMORY: *const () = 0x4000_6c00 as _;
28 const EP_MEMORY_SIZE: usize = 1024;
29 const EP_MEMORY_ACCESS_2X16: bool = true;
30
31 fn enable() {
32 cortex_m::interrupt::free(|_| unsafe {
33 USB::enable_unchecked();
35
36 USB::reset_unchecked();
38 });
39 }
40
41 fn startup_delay() {
42 cortex_m::asm::delay(72);
45 }
46}
47
48pub type UsbBusType = UsbBus<Peripheral>;