Skip to content

Instantly share code, notes, and snippets.

@spookyvision
Created December 27, 2021 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spookyvision/02e02f30ff12f982f2463a58c9be1787 to your computer and use it in GitHub Desktop.
Save spookyvision/02e02f30ff12f982f2463a58c9be1787 to your computer and use it in GitHub Desktop.
static mut USB_SERIAL: Option<usbd_serial::SerialPort<UsbBusType>> = None;
static mut USB_DEVICE: Option<UsbDevice<UsbBusType>> = None;
#[entry]
fn main() -> ! {
if let (Some(dp), Some(mut cp)) = (pac::Peripherals::take(), Peripherals::take()) {
// ...
unsafe {
let bus = UsbBus::new(usb);
USB_BUS = Some(bus);
USB_SERIAL = Some(SerialPort::new(USB_BUS.as_ref().unwrap()));
USB_DEVICE = Some( /* ... */ );
// ...
}
}
#[interrupt]
fn USB_HP_CAN_TX() {
usb_interrupt();
}
#[interrupt]
fn USB_LP_CAN_RX0() {
usb_interrupt();
}
fn usb_interrupt() {
let usb_dev = unsafe { USB_DEVICE.as_mut().unwrap() };
cortex_m::interrupt::free(|_| unsafe {
// ... use it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment