@@ -10,6 +10,7 @@ use nrf52840_hal::gpio::{p0, p1, Level};
10
10
use nrf52840_hal:: prelude:: * ;
11
11
use nrf52840_hal:: timer:: { OneShot , Timer } ;
12
12
use nrf52840_hal:: usbd:: Usbd ;
13
+ use nrf52840_hal:: clocks:: Clocks ;
13
14
use nrf52840_pac:: { interrupt, Peripherals , TIMER0 } ;
14
15
use usb_device:: device:: { UsbDeviceBuilder , UsbDeviceState , UsbVidPid } ;
15
16
use usbd_serial:: { SerialPort , USB_CLASS_CDC } ;
@@ -21,7 +22,7 @@ fn TIMER0() {
21
22
22
23
#[ entry]
23
24
fn main ( ) -> ! {
24
- static mut EP_BUF : [ u8 ; 256 ] = [ 0 ; 256 ] ;
25
+ static mut EP_BUF : [ u8 ; 512 ] = [ 0 ; 512 ] ;
25
26
26
27
let core = cortex_m:: Peripherals :: take ( ) . unwrap ( ) ;
27
28
let periph = Peripherals :: take ( ) . unwrap ( ) ;
@@ -33,6 +34,18 @@ fn main() -> ! {
33
34
. is_vbus_present ( )
34
35
{ }
35
36
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
+
36
49
let mut nvic = core. NVIC ;
37
50
let mut timer = Timer :: one_shot ( periph. TIMER0 ) ;
38
51
let usbd = periph. USBD ;
@@ -48,12 +61,13 @@ fn main() -> ! {
48
61
49
62
led. set_low ( ) . unwrap ( ) ;
50
63
51
- let usb_bus = Usbd :: new_alloc ( usbd, EP_BUF ) ;
64
+ let usb_bus = Usbd :: new_alloc ( usbd, EP_BUF , & clocks ) ;
52
65
let mut serial = SerialPort :: new ( & usb_bus) ;
53
66
54
67
let mut usb_dev = UsbDeviceBuilder :: new ( & usb_bus, UsbVidPid ( 0x16c0 , 0x27dd ) )
55
68
. product ( "nRF52840 Serial Port Demo" )
56
69
. device_class ( USB_CLASS_CDC )
70
+ . max_packet_size_0 ( 64 ) // (makes control transfers 8x faster)
57
71
. build ( ) ;
58
72
59
73
hprintln ! ( "<start>" ) . ok ( ) ;
0 commit comments