diff options
Diffstat (limited to 'embassy-stm32/src/rcc/u5.rs')
| -rw-r--r-- | embassy-stm32/src/rcc/u5.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs index 06895a99a..47cc29c6f 100644 --- a/embassy-stm32/src/rcc/u5.rs +++ b/embassy-stm32/src/rcc/u5.rs | |||
| @@ -6,9 +6,9 @@ pub use crate::pac::rcc::vals::{ | |||
| 6 | Pllsrc as PllSource, Ppre as APBPrescaler, Sw as Sysclk, | 6 | Pllsrc as PllSource, Ppre as APBPrescaler, Sw as Sysclk, |
| 7 | }; | 7 | }; |
| 8 | use crate::pac::rcc::vals::{Hseext, Msipllfast, Msipllsel, Msirgsel, Pllmboost, Pllrge}; | 8 | use crate::pac::rcc::vals::{Hseext, Msipllfast, Msipllsel, Msirgsel, Pllmboost, Pllrge}; |
| 9 | #[cfg(all(peri_usb_otg_hs))] | ||
| 10 | pub use crate::pac::{syscfg::vals::Usbrefcksel, SYSCFG}; | ||
| 11 | use crate::pac::{FLASH, PWR, RCC}; | 9 | use crate::pac::{FLASH, PWR, RCC}; |
| 10 | #[cfg(all(peri_usb_otg_hs))] | ||
| 11 | pub use crate::pac::{SYSCFG, syscfg::vals::Usbrefcksel}; | ||
| 12 | use crate::rcc::LSI_FREQ; | 12 | use crate::rcc::LSI_FREQ; |
| 13 | use crate::time::Hertz; | 13 | use crate::time::Hertz; |
| 14 | 14 | ||
| @@ -343,6 +343,16 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 343 | 343 | ||
| 344 | let hsi48 = config.hsi48.map(super::init_hsi48); | 344 | let hsi48 = config.hsi48.map(super::init_hsi48); |
| 345 | 345 | ||
| 346 | // There's a possibility that a bootloader that ran before us has configured the system clock | ||
| 347 | // source to be PLL1_R. In that case we'd get forever stuck on (de)configuring PLL1 as the chip | ||
| 348 | // prohibits disabling PLL1 when it's used as a source for system clock. Change the system | ||
| 349 | // clock source to MSIS which doesn't suffer from this conflict. The correct source per the | ||
| 350 | // provided config is then set further down. | ||
| 351 | // See https://github.com/embassy-rs/embassy/issues/5072 | ||
| 352 | let default_system_clock_source = Config::default().sys; | ||
| 353 | RCC.cfgr1().modify(|w| w.set_sw(default_system_clock_source)); | ||
| 354 | while RCC.cfgr1().read().sws() != default_system_clock_source {} | ||
| 355 | |||
| 346 | let pll_input = PllInput { hse, hsi, msi: msis }; | 356 | let pll_input = PllInput { hse, hsi, msi: msis }; |
| 347 | let pll1 = init_pll(PllInstance::Pll1, config.pll1, &pll_input, config.voltage_range); | 357 | let pll1 = init_pll(PllInstance::Pll1, config.pll1, &pll_input, config.voltage_range); |
| 348 | let pll2 = init_pll(PllInstance::Pll2, config.pll2, &pll_input, config.voltage_range); | 358 | let pll2 = init_pll(PllInstance::Pll2, config.pll2, &pll_input, config.voltage_range); |
| @@ -442,7 +452,10 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 442 | Hertz(24_000_000) => Usbrefcksel::MHZ24, | 452 | Hertz(24_000_000) => Usbrefcksel::MHZ24, |
| 443 | Hertz(26_000_000) => Usbrefcksel::MHZ26, | 453 | Hertz(26_000_000) => Usbrefcksel::MHZ26, |
| 444 | Hertz(32_000_000) => Usbrefcksel::MHZ32, | 454 | Hertz(32_000_000) => Usbrefcksel::MHZ32, |
| 445 | _ => panic!("cannot select OTG_HS reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz", clk_val), | 455 | _ => panic!( |
| 456 | "cannot select OTG_HS reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz", | ||
| 457 | clk_val | ||
| 458 | ), | ||
| 446 | }, | 459 | }, |
| 447 | None => Usbrefcksel::MHZ24, | 460 | None => Usbrefcksel::MHZ24, |
| 448 | }; | 461 | }; |
