File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ cortex-m-rt = "0.6.10"
31
31
nb = " 0.1.2"
32
32
rand_core = " 0.5.1"
33
33
stm32f4 = " 0.11"
34
- synopsys-usb-otg = { version = " 0.1 .0" , features = [" cortex-m" ], optional = true }
34
+ synopsys-usb-otg = { version = " 0.2 .0" , features = [" cortex-m" ], optional = true }
35
35
36
36
[dependencies .bare-metal ]
37
37
version = " 0.2.5"
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ fn main() -> ! {
18
18
19
19
let rcc = dp. RCC . constrain ( ) ;
20
20
21
- rcc. cfgr
21
+ let clocks = rcc. cfgr
22
22
. use_hse ( 25 . mhz ( ) )
23
23
. sysclk ( 48 . mhz ( ) )
24
24
. require_pll48clk ( )
@@ -32,6 +32,7 @@ fn main() -> ! {
32
32
usb_pwrclk : dp. OTG_FS_PWRCLK ,
33
33
pin_dm : gpioa. pa11 . into_alternate_af10 ( ) ,
34
34
pin_dp : gpioa. pa12 . into_alternate_af10 ( ) ,
35
+ hclk : clocks. hclk ( ) ,
35
36
} ;
36
37
37
38
let usb_bus = UsbBus :: new ( usb, unsafe { & mut EP_MEMORY } ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ use crate::gpio::{
9
9
gpioa:: { PA11 , PA12 } ,
10
10
Alternate , AF10 ,
11
11
} ;
12
+ use crate :: time:: Hertz ;
12
13
13
14
pub use synopsys_usb_otg:: UsbBus ;
14
15
use synopsys_usb_otg:: UsbPeripheral ;
@@ -19,6 +20,7 @@ pub struct USB {
19
20
pub usb_pwrclk : stm32:: OTG_FS_PWRCLK ,
20
21
pub pin_dm : PA11 < Alternate < AF10 > > ,
21
22
pub pin_dp : PA12 < Alternate < AF10 > > ,
23
+ pub hclk : Hertz ,
22
24
}
23
25
24
26
unsafe impl Sync for USB { }
@@ -29,6 +31,21 @@ unsafe impl UsbPeripheral for USB {
29
31
const HIGH_SPEED : bool = false ;
30
32
const FIFO_DEPTH_WORDS : usize = 320 ;
31
33
34
+ #[ cfg( any(
35
+ feature = "stm32f401" ,
36
+ feature = "stm32f405" ,
37
+ feature = "stm32f407" ,
38
+ feature = "stm32f415" ,
39
+ feature = "stm32f417" ,
40
+ feature = "stm32f427" ,
41
+ feature = "stm32f429" ,
42
+ feature = "stm32f437" ,
43
+ feature = "stm32f439" ,
44
+ ) ) ]
45
+ const ENDPOINT_COUNT : usize = 4 ;
46
+ #[ cfg( feature = "stm32f446" ) ]
47
+ const ENDPOINT_COUNT : usize = 6 ;
48
+
32
49
fn enable ( ) {
33
50
let rcc = unsafe { & * stm32:: RCC :: ptr ( ) } ;
34
51
@@ -41,6 +58,10 @@ unsafe impl UsbPeripheral for USB {
41
58
rcc. ahb2rstr . modify ( |_, w| w. otgfsrst ( ) . clear_bit ( ) ) ;
42
59
} ) ;
43
60
}
61
+
62
+ fn ahb_frequency_hz ( & self ) -> u32 {
63
+ self . hclk . 0
64
+ }
44
65
}
45
66
46
67
pub type UsbBusType = UsbBus < USB > ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ use crate::gpio::{
12
12
gpiob:: { PB14 , PB15 } ,
13
13
Alternate , AF12 ,
14
14
} ;
15
+ use crate :: time:: Hertz ;
15
16
16
17
pub use synopsys_usb_otg:: UsbBus ;
17
18
use synopsys_usb_otg:: UsbPeripheral ;
@@ -22,6 +23,7 @@ pub struct USB {
22
23
pub usb_pwrclk : stm32:: OTG_HS_PWRCLK ,
23
24
pub pin_dm : PB14 < Alternate < AF12 > > ,
24
25
pub pin_dp : PB15 < Alternate < AF12 > > ,
26
+ pub hclk : Hertz ,
25
27
}
26
28
27
29
unsafe impl Sync for USB { }
@@ -32,6 +34,20 @@ unsafe impl UsbPeripheral for USB {
32
34
const HIGH_SPEED : bool = true ;
33
35
const FIFO_DEPTH_WORDS : usize = 1024 ;
34
36
37
+ #[ cfg( any(
38
+ feature = "stm32f405" ,
39
+ feature = "stm32f407" ,
40
+ feature = "stm32f415" ,
41
+ feature = "stm32f417" ,
42
+ feature = "stm32f427" ,
43
+ feature = "stm32f429" ,
44
+ feature = "stm32f437" ,
45
+ feature = "stm32f439" ,
46
+ ) ) ]
47
+ const ENDPOINT_COUNT : usize = 6 ;
48
+ #[ cfg( feature = "stm32f446" ) ]
49
+ const ENDPOINT_COUNT : usize = 9 ;
50
+
35
51
fn enable ( ) {
36
52
let rcc = unsafe { & * stm32:: RCC :: ptr ( ) } ;
37
53
@@ -44,6 +60,10 @@ unsafe impl UsbPeripheral for USB {
44
60
rcc. ahb1rstr . modify ( |_, w| w. otghsrst ( ) . clear_bit ( ) ) ;
45
61
} ) ;
46
62
}
63
+
64
+ fn ahb_frequency_hz ( & self ) -> u32 {
65
+ self . hclk . 0
66
+ }
47
67
}
48
68
49
69
pub type UsbBusType = UsbBus < USB > ;
You can’t perform that action at this time.
0 commit comments