Skip to content

Commit 2949c8d

Browse files
committed
set ulpi pin speed to VeryHigh
1 parent 9469cf4 commit 2949c8d

File tree

1 file changed

+54
-13
lines changed

1 file changed

+54
-13
lines changed

src/usb_hs.rs

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::gpio::{
1515
gpiob::{PB0, PB1, PB10, PB11, PB12, PB13, PB5},
1616
gpioc::{PC0, PC2, PC3},
1717
gpioh::PH4,
18-
Alternate, AF10,
18+
Alternate, Speed, AF10,
1919
};
2020

2121
#[cfg(not(feature = "rm0468"))]
@@ -184,6 +184,20 @@ pub enum Usb1UlpiDirPin {
184184
PI11(PI11<Alternate<AF10>>),
185185
}
186186

187+
impl Usb1UlpiDirPin {
188+
fn set_speed(self, speed: Speed) -> Usb1UlpiDirPin {
189+
match self {
190+
Usb1UlpiDirPin::PC2(pin) => {
191+
Usb1UlpiDirPin::PC2(pin.set_speed(speed))
192+
}
193+
#[cfg(not(feature = "rm0468"))]
194+
Usb1UlpiDirPin::PI11(pin) => {
195+
Usb1UlpiDirPin::PI11(pin.set_speed(speed))
196+
}
197+
}
198+
}
199+
}
200+
187201
#[cfg(not(feature = "rm0468"))]
188202
impl From<PI11<Alternate<AF10>>> for Usb1UlpiDirPin {
189203
fn from(v: PI11<Alternate<AF10>>) -> Self {
@@ -202,6 +216,20 @@ pub enum Usb1UlpiNxtPin {
202216
PH4(PH4<Alternate<AF10>>),
203217
}
204218

219+
impl Usb1UlpiNxtPin {
220+
fn set_speed(self, speed: Speed) -> Usb1UlpiNxtPin {
221+
match self {
222+
Usb1UlpiNxtPin::PC3(pin) => {
223+
Usb1UlpiNxtPin::PC3(pin.set_speed(speed))
224+
}
225+
#[cfg(not(feature = "rm0468"))]
226+
Usb1UlpiNxtPin::PH4(pin) => {
227+
Usb1UlpiNxtPin::PH4(pin.set_speed(speed))
228+
}
229+
}
230+
}
231+
}
232+
205233
impl From<PH4<Alternate<AF10>>> for Usb1UlpiNxtPin {
206234
fn from(v: PH4<Alternate<AF10>>) -> Self {
207235
Usb1UlpiNxtPin::PH4(v)
@@ -215,25 +243,38 @@ impl From<PC3<Alternate<AF10>>> for Usb1UlpiNxtPin {
215243
}
216244

217245
impl USB1_ULPI {
246+
/// Automatically sets all upli pins to gpio speed VeryHigh
218247
pub fn new(
219248
usb_global: stm32::OTG1_HS_GLOBAL,
220249
usb_device: stm32::OTG1_HS_DEVICE,
221250
usb_pwrclk: stm32::OTG1_HS_PWRCLK,
222-
_ulpi_clk: PA5<Alternate<AF10>>,
223-
_ulpi_dir: impl Into<Usb1UlpiDirPin>,
224-
_ulpi_nxt: impl Into<Usb1UlpiNxtPin>,
225-
_ulpi_stp: PC0<Alternate<AF10>>,
226-
_ulpi_d0: PA3<Alternate<AF10>>,
227-
_ulpi_d1: PB0<Alternate<AF10>>,
228-
_ulpi_d2: PB1<Alternate<AF10>>,
229-
_ulpi_d3: PB10<Alternate<AF10>>,
230-
_ulpi_d4: PB11<Alternate<AF10>>,
231-
_ulpi_d5: PB12<Alternate<AF10>>,
232-
_ulpi_d6: PB13<Alternate<AF10>>,
233-
_ulpi_d7: PB5<Alternate<AF10>>,
251+
ulpi_clk: PA5<Alternate<AF10>>,
252+
ulpi_dir: impl Into<Usb1UlpiDirPin>,
253+
ulpi_nxt: impl Into<Usb1UlpiNxtPin>,
254+
ulpi_stp: PC0<Alternate<AF10>>,
255+
ulpi_d0: PA3<Alternate<AF10>>,
256+
ulpi_d1: PB0<Alternate<AF10>>,
257+
ulpi_d2: PB1<Alternate<AF10>>,
258+
ulpi_d3: PB10<Alternate<AF10>>,
259+
ulpi_d4: PB11<Alternate<AF10>>,
260+
ulpi_d5: PB12<Alternate<AF10>>,
261+
ulpi_d6: PB13<Alternate<AF10>>,
262+
ulpi_d7: PB5<Alternate<AF10>>,
234263
prec: rcc::rec::Usb1Otg,
235264
clocks: &rcc::CoreClocks,
236265
) -> Self {
266+
ulpi_clk.set_speed(Speed::VeryHigh);
267+
ulpi_dir.into().set_speed(Speed::VeryHigh);
268+
ulpi_nxt.into().set_speed(Speed::VeryHigh);
269+
ulpi_stp.set_speed(Speed::VeryHigh);
270+
ulpi_d0.set_speed(Speed::VeryHigh);
271+
ulpi_d1.set_speed(Speed::VeryHigh);
272+
ulpi_d2.set_speed(Speed::VeryHigh);
273+
ulpi_d3.set_speed(Speed::VeryHigh);
274+
ulpi_d4.set_speed(Speed::VeryHigh);
275+
ulpi_d5.set_speed(Speed::VeryHigh);
276+
ulpi_d6.set_speed(Speed::VeryHigh);
277+
ulpi_d7.set_speed(Speed::VeryHigh);
237278
Self::new_unchecked(usb_global, usb_device, usb_pwrclk, prec, clocks)
238279
}
239280
pub fn new_unchecked(

0 commit comments

Comments
 (0)