stm32/otg: fix OTG_HS in FS mode.

This commit is contained in:
Dario Nieuwenhuis 2024-04-12 03:19:42 +02:00
parent 2a157585d1
commit 499c6e84a3

View file

@ -562,51 +562,29 @@ impl<'d, T: Instance> Bus<'d, T> {
fn init(&mut self) { fn init(&mut self) {
super::common_init::<T>(); super::common_init::<T>();
#[cfg(stm32f7)] // Enable ULPI clock if external PHY is used
{ let _ulpien = !self.phy_type.internal();
// Enable ULPI clock if external PHY is used
let ulpien = !self.phy_type.internal();
critical_section::with(|_| {
crate::pac::RCC.ahb1enr().modify(|w| {
if T::HIGH_SPEED {
w.set_usb_otg_hsulpien(ulpien);
} else {
w.set_usb_otg_hsen(ulpien);
}
});
// Low power mode #[cfg(any(stm32f2, stm32f4, stm32f7))]
crate::pac::RCC.ahb1lpenr().modify(|w| { if T::HIGH_SPEED {
if T::HIGH_SPEED { critical_section::with(|_| {
w.set_usb_otg_hsulpilpen(ulpien); let rcc = crate::pac::RCC;
} else { rcc.ahb1enr().modify(|w| w.set_usb_otg_hsulpien(_ulpien));
w.set_usb_otg_hslpen(ulpien); rcc.ahb1lpenr().modify(|w| w.set_usb_otg_hsulpilpen(_ulpien));
}
});
}); });
} }
#[cfg(stm32h7)] #[cfg(stm32h7)]
{ critical_section::with(|_| {
// Enable ULPI clock if external PHY is used let rcc = crate::pac::RCC;
let ulpien = !self.phy_type.internal(); if T::HIGH_SPEED {
critical_section::with(|_| { rcc.ahb1enr().modify(|w| w.set_usb_otg_hs_ulpien(_ulpien));
crate::pac::RCC.ahb1enr().modify(|w| { rcc.ahb1lpenr().modify(|w| w.set_usb_otg_hs_ulpilpen(_ulpien));
if T::HIGH_SPEED { } else {
w.set_usb_otg_hs_ulpien(ulpien); rcc.ahb1enr().modify(|w| w.set_usb_otg_fs_ulpien(_ulpien));
} else { rcc.ahb1lpenr().modify(|w| w.set_usb_otg_fs_ulpilpen(_ulpien));
w.set_usb_otg_fs_ulpien(ulpien); }
} });
});
crate::pac::RCC.ahb1lpenr().modify(|w| {
if T::HIGH_SPEED {
w.set_usb_otg_hs_ulpilpen(ulpien);
} else {
w.set_usb_otg_fs_ulpilpen(ulpien);
}
});
});
}
let r = T::regs(); let r = T::regs();
let core_id = r.cid().read().0; let core_id = r.cid().read().0;