aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-04-12 03:19:42 +0200
committerDario Nieuwenhuis <[email protected]>2024-04-12 03:33:20 +0200
commit499c6e84a3d007e52de25104d658dd98724a2d5a (patch)
tree0f19668ef9bd612f31e14753e8dd0306128002d7
parent2a157585d158077c8ce4bb7bcb809cd9d4572deb (diff)
stm32/otg: fix OTG_HS in FS mode.
-rw-r--r--embassy-stm32/src/usb/otg.rs58
1 files changed, 18 insertions, 40 deletions
diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs
index 1e88b6959..cabc06367 100644
--- a/embassy-stm32/src/usb/otg.rs
+++ b/embassy-stm32/src/usb/otg.rs
@@ -562,51 +562,29 @@ impl<'d, T: Instance> Bus<'d, T> {
562 fn init(&mut self) { 562 fn init(&mut self) {
563 super::common_init::<T>(); 563 super::common_init::<T>();
564 564
565 #[cfg(stm32f7)] 565 // Enable ULPI clock if external PHY is used
566 { 566 let _ulpien = !self.phy_type.internal();
567 // Enable ULPI clock if external PHY is used
568 let ulpien = !self.phy_type.internal();
569 critical_section::with(|_| {
570 crate::pac::RCC.ahb1enr().modify(|w| {
571 if T::HIGH_SPEED {
572 w.set_usb_otg_hsulpien(ulpien);
573 } else {
574 w.set_usb_otg_hsen(ulpien);
575 }
576 });
577 567
578 // Low power mode 568 #[cfg(any(stm32f2, stm32f4, stm32f7))]
579 crate::pac::RCC.ahb1lpenr().modify(|w| { 569 if T::HIGH_SPEED {
580 if T::HIGH_SPEED { 570 critical_section::with(|_| {
581 w.set_usb_otg_hsulpilpen(ulpien); 571 let rcc = crate::pac::RCC;
582 } else { 572 rcc.ahb1enr().modify(|w| w.set_usb_otg_hsulpien(_ulpien));
583 w.set_usb_otg_hslpen(ulpien); 573 rcc.ahb1lpenr().modify(|w| w.set_usb_otg_hsulpilpen(_ulpien));
584 }
585 });
586 }); 574 });
587 } 575 }
588 576
589 #[cfg(stm32h7)] 577 #[cfg(stm32h7)]
590 { 578 critical_section::with(|_| {
591 // Enable ULPI clock if external PHY is used 579 let rcc = crate::pac::RCC;
592 let ulpien = !self.phy_type.internal(); 580 if T::HIGH_SPEED {
593 critical_section::with(|_| { 581 rcc.ahb1enr().modify(|w| w.set_usb_otg_hs_ulpien(_ulpien));
594 crate::pac::RCC.ahb1enr().modify(|w| { 582 rcc.ahb1lpenr().modify(|w| w.set_usb_otg_hs_ulpilpen(_ulpien));
595 if T::HIGH_SPEED { 583 } else {
596 w.set_usb_otg_hs_ulpien(ulpien); 584 rcc.ahb1enr().modify(|w| w.set_usb_otg_fs_ulpien(_ulpien));
597 } else { 585 rcc.ahb1lpenr().modify(|w| w.set_usb_otg_fs_ulpilpen(_ulpien));
598 w.set_usb_otg_fs_ulpien(ulpien); 586 }
599 } 587 });
600 });
601 crate::pac::RCC.ahb1lpenr().modify(|w| {
602 if T::HIGH_SPEED {
603 w.set_usb_otg_hs_ulpilpen(ulpien);
604 } else {
605 w.set_usb_otg_fs_ulpilpen(ulpien);
606 }
607 });
608 });
609 }
610 588
611 let r = T::regs(); 589 let r = T::regs();
612 let core_id = r.cid().read().0; 590 let core_id = r.cid().read().0;