stm32f1xx_hal/
usb.rs

1//! USB peripheral
2//!
3//! Requires the `stm32-usbd` feature.
4//! See [https://github.com/stm32-rs/stm32f1xx-hal/tree/master/examples]
5//! for usage examples.
6
7use crate::pac::{RCC, USB};
8use crate::rcc::{Enable, Reset};
9use stm32_usbd::UsbPeripheral;
10
11use crate::gpio::gpioa::{PA11, PA12};
12use crate::gpio::{Floating, Input};
13pub use stm32_usbd::UsbBus;
14
15pub struct Peripheral {
16    pub usb: USB,
17    pub pin_dm: PA11<Input<Floating>>,
18    pub pin_dp: PA12<Input<Floating>>,
19}
20
21unsafe impl Sync for Peripheral {}
22
23unsafe impl UsbPeripheral for Peripheral {
24    const REGISTERS: *const () = USB::ptr() as *const ();
25    const DP_PULL_UP_FEATURE: bool = false;
26    const EP_MEMORY: *const () = 0x4000_6000 as _;
27    const EP_MEMORY_SIZE: usize = 512;
28    const EP_MEMORY_ACCESS_2X16: bool = false;
29
30    fn enable() {
31        unsafe {
32            let rcc = &*RCC::ptr();
33
34            // Enable USB peripheral
35            USB::enable(rcc);
36            // Reset USB peripheral
37            USB::reset(rcc);
38        }
39    }
40
41    fn startup_delay() {
42        // There is a chip specific startup delay. For STM32F103xx it's 1µs and this should wait for
43        // at least that long.
44        cortex_m::asm::delay(72);
45    }
46}
47
48pub type UsbBusType = UsbBus<Peripheral>;