Skip to content

Commit 2dcb6fe

Browse files
japaricWez Furlong
authored andcommitted
make the example compile again
1 parent 8da1a9c commit 2dcb6fe

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

examples/usb/src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use nrf52840_hal::gpio::{p0, p1, Level};
1010
use nrf52840_hal::prelude::*;
1111
use nrf52840_hal::timer::{OneShot, Timer};
1212
use nrf52840_hal::usbd::Usbd;
13+
use nrf52840_hal::clocks::Clocks;
1314
use nrf52840_pac::{interrupt, Peripherals, TIMER0};
1415
use usb_device::device::{UsbDeviceBuilder, UsbDeviceState, UsbVidPid};
1516
use usbd_serial::{SerialPort, USB_CLASS_CDC};
@@ -21,7 +22,7 @@ fn TIMER0() {
2122

2223
#[entry]
2324
fn main() -> ! {
24-
static mut EP_BUF: [u8; 256] = [0; 256];
25+
static mut EP_BUF: [u8; 512] = [0; 512];
2526

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

37+
// wait until USB 3.3V supply is stable
38+
while !periph
39+
.POWER
40+
.events_usbpwrrdy
41+
.read()
42+
.events_usbpwrrdy()
43+
.bit_is_clear()
44+
{}
45+
46+
let clocks = Clocks::new(periph.CLOCK);
47+
let clocks = clocks.enable_ext_hfosc();
48+
3649
let mut nvic = core.NVIC;
3750
let mut timer = Timer::one_shot(periph.TIMER0);
3851
let usbd = periph.USBD;
@@ -48,12 +61,13 @@ fn main() -> ! {
4861

4962
led.set_low().unwrap();
5063

51-
let usb_bus = Usbd::new_alloc(usbd, EP_BUF);
64+
let usb_bus = Usbd::new_alloc(usbd, EP_BUF, &clocks);
5265
let mut serial = SerialPort::new(&usb_bus);
5366

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

5973
hprintln!("<start>").ok();

0 commit comments

Comments
 (0)