Skip to content

Commit

Permalink
make the example compile again
Browse files Browse the repository at this point in the history
  • Loading branch information
japaric authored and fnafnio committed May 12, 2021
1 parent 272cb5c commit 004e5ad
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions examples/usb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use nrf52840_hal::gpio::{p0, p1, Level};
use nrf52840_hal::prelude::*;
use nrf52840_hal::timer::{OneShot, Timer};
use nrf52840_hal::usbd::Usbd;
use nrf52840_hal::clocks::Clocks;
use nrf52840_pac::{interrupt, Peripherals, TIMER0};
use usb_device::device::{UsbDeviceBuilder, UsbDeviceState, UsbVidPid};
use usbd_serial::{SerialPort, USB_CLASS_CDC};
Expand All @@ -21,7 +22,7 @@ fn TIMER0() {

#[entry]
fn main() -> ! {
static mut EP_BUF: [u8; 256] = [0; 256];
static mut EP_BUF: [u8; 512] = [0; 512];

let core = cortex_m::Peripherals::take().unwrap();
let periph = Peripherals::take().unwrap();
Expand All @@ -33,6 +34,18 @@ fn main() -> ! {
.is_vbus_present()
{}

// wait until USB 3.3V supply is stable
while !periph
.POWER
.events_usbpwrrdy
.read()
.events_usbpwrrdy()
.bit_is_clear()
{}

let clocks = Clocks::new(periph.CLOCK);
let clocks = clocks.enable_ext_hfosc();

let mut nvic = core.NVIC;
let mut timer = Timer::one_shot(periph.TIMER0);
let usbd = periph.USBD;
Expand All @@ -48,12 +61,13 @@ fn main() -> ! {

led.set_low().unwrap();

let usb_bus = Usbd::new_alloc(usbd, EP_BUF);
let usb_bus = Usbd::new_alloc(usbd, EP_BUF, &clocks);
let mut serial = SerialPort::new(&usb_bus);

let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
.product("nRF52840 Serial Port Demo")
.device_class(USB_CLASS_CDC)
.max_packet_size_0(64) // (makes control transfers 8x faster)
.build();

hprintln!("<start>").ok();
Expand Down

0 comments on commit 004e5ad

Please sign in to comment.