3
3
#![ no_main]
4
4
#![ no_std]
5
5
#![ allow( non_snake_case) ]
6
+ #![ deny( unsafe_code) ]
6
7
7
8
use panic_semihosting as _;
8
9
@@ -22,10 +23,8 @@ mod app {
22
23
#[ local]
23
24
struct Local { }
24
25
25
- #[ init]
26
+ #[ init( local = [ usb_bus : Option <usb_device :: bus :: UsbBusAllocator < UsbBusType >> = None ] ) ]
26
27
fn init ( cx : init:: Context ) -> ( Shared , Local , init:: Monotonics ) {
27
- static mut USB_BUS : Option < usb_device:: bus:: UsbBusAllocator < UsbBusType > > = None ;
28
-
29
28
let mut flash = cx. device . FLASH . constrain ( ) ;
30
29
let rcc = cx. device . RCC . constrain ( ) ;
31
30
@@ -57,23 +56,18 @@ mod app {
57
56
pin_dp : usb_dp,
58
57
} ;
59
58
60
- unsafe {
61
- USB_BUS . replace ( UsbBus :: new ( usb) ) ;
62
- }
63
-
64
- let serial = usbd_serial:: SerialPort :: new ( unsafe { USB_BUS . as_ref ( ) . unwrap ( ) } ) ;
65
-
66
- let usb_dev = UsbDeviceBuilder :: new (
67
- unsafe { USB_BUS . as_ref ( ) . unwrap ( ) } ,
68
- UsbVidPid ( 0x16c0 , 0x27dd ) ,
69
- )
70
- . device_class ( usbd_serial:: USB_CLASS_CDC )
71
- . strings ( & [ StringDescriptors :: default ( )
72
- . manufacturer ( "Fake Company" )
73
- . product ( "Serial port" )
74
- . serial_number ( "TEST" ) ] )
75
- . unwrap ( )
76
- . build ( ) ;
59
+ cx. local . usb_bus . replace ( UsbBus :: new ( usb) ) ;
60
+ let usb_bus = cx. local . usb_bus . as_ref ( ) . unwrap ( ) ;
61
+
62
+ let serial = usbd_serial:: SerialPort :: new ( usb_bus) ;
63
+ let usb_dev = UsbDeviceBuilder :: new ( usb_bus, UsbVidPid ( 0x16c0 , 0x27dd ) )
64
+ . device_class ( usbd_serial:: USB_CLASS_CDC )
65
+ . strings ( & [ StringDescriptors :: default ( )
66
+ . manufacturer ( "Fake Company" )
67
+ . product ( "Serial port" )
68
+ . serial_number ( "TEST" ) ] )
69
+ . unwrap ( )
70
+ . build ( ) ;
77
71
78
72
( Shared { usb_dev, serial } , Local { } , init:: Monotonics ( ) )
79
73
}
0 commit comments