Skip to content

Commit 8d9a40b

Browse files
committed
Update synopsys-usb-otg dependency to v0.2.0
1 parent 7db793f commit 8d9a40b

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cortex-m-rt = "0.6.10"
3131
nb = "0.1.2"
3232
rand_core = "0.5.1"
3333
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 }
3535

3636
[dependencies.bare-metal]
3737
version = "0.2.5"

examples/usb_serial.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() -> ! {
1818

1919
let rcc = dp.RCC.constrain();
2020

21-
rcc.cfgr
21+
let clocks = rcc.cfgr
2222
.use_hse(25.mhz())
2323
.sysclk(48.mhz())
2424
.require_pll48clk()
@@ -32,6 +32,7 @@ fn main() -> ! {
3232
usb_pwrclk: dp.OTG_FS_PWRCLK,
3333
pin_dm: gpioa.pa11.into_alternate_af10(),
3434
pin_dp: gpioa.pa12.into_alternate_af10(),
35+
hclk: clocks.hclk(),
3536
};
3637

3738
let usb_bus = UsbBus::new(usb, unsafe { &mut EP_MEMORY });

src/otg_fs.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::gpio::{
99
gpioa::{PA11, PA12},
1010
Alternate, AF10,
1111
};
12+
use crate::time::Hertz;
1213

1314
pub use synopsys_usb_otg::UsbBus;
1415
use synopsys_usb_otg::UsbPeripheral;
@@ -19,6 +20,7 @@ pub struct USB {
1920
pub usb_pwrclk: stm32::OTG_FS_PWRCLK,
2021
pub pin_dm: PA11<Alternate<AF10>>,
2122
pub pin_dp: PA12<Alternate<AF10>>,
23+
pub hclk: Hertz,
2224
}
2325

2426
unsafe impl Sync for USB {}
@@ -29,6 +31,21 @@ unsafe impl UsbPeripheral for USB {
2931
const HIGH_SPEED: bool = false;
3032
const FIFO_DEPTH_WORDS: usize = 320;
3133

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+
3249
fn enable() {
3350
let rcc = unsafe { &*stm32::RCC::ptr() };
3451

@@ -41,6 +58,10 @@ unsafe impl UsbPeripheral for USB {
4158
rcc.ahb2rstr.modify(|_, w| w.otgfsrst().clear_bit());
4259
});
4360
}
61+
62+
fn ahb_frequency_hz(&self) -> u32 {
63+
self.hclk.0
64+
}
4465
}
4566

4667
pub type UsbBusType = UsbBus<USB>;

src/otg_hs.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::gpio::{
1212
gpiob::{PB14, PB15},
1313
Alternate, AF12,
1414
};
15+
use crate::time::Hertz;
1516

1617
pub use synopsys_usb_otg::UsbBus;
1718
use synopsys_usb_otg::UsbPeripheral;
@@ -22,6 +23,7 @@ pub struct USB {
2223
pub usb_pwrclk: stm32::OTG_HS_PWRCLK,
2324
pub pin_dm: PB14<Alternate<AF12>>,
2425
pub pin_dp: PB15<Alternate<AF12>>,
26+
pub hclk: Hertz,
2527
}
2628

2729
unsafe impl Sync for USB {}
@@ -32,6 +34,20 @@ unsafe impl UsbPeripheral for USB {
3234
const HIGH_SPEED: bool = true;
3335
const FIFO_DEPTH_WORDS: usize = 1024;
3436

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+
3551
fn enable() {
3652
let rcc = unsafe { &*stm32::RCC::ptr() };
3753

@@ -44,6 +60,10 @@ unsafe impl UsbPeripheral for USB {
4460
rcc.ahb1rstr.modify(|_, w| w.otghsrst().clear_bit());
4561
});
4662
}
63+
64+
fn ahb_frequency_hz(&self) -> u32 {
65+
self.hclk.0
66+
}
4767
}
4868

4969
pub type UsbBusType = UsbBus<USB>;

0 commit comments

Comments
 (0)