Merge pull request #2829 from aurelj/stm32-rcc-hsi

stm32: ensure the core runs on HSI clock while setting up rcc
This commit is contained in:
Dario Nieuwenhuis 2024-05-21 22:06:24 +00:00 committed by GitHub
commit 5ecc9b805d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -146,17 +146,18 @@ pub(crate) unsafe fn init(config: Config) {
while !PWR.csr1().read().odswrdy() {} while !PWR.csr1().read().odswrdy() {}
} }
// Configure HSI // Turn on the HSI
let hsi = match config.hsi {
false => {
RCC.cr().modify(|w| w.set_hsion(false));
None
}
true => {
RCC.cr().modify(|w| w.set_hsion(true)); RCC.cr().modify(|w| w.set_hsion(true));
while !RCC.cr().read().hsirdy() {} while !RCC.cr().read().hsirdy() {}
Some(HSI_FREQ)
} // Use the HSI clock as system clock during the actual clock setup
RCC.cfgr().modify(|w| w.set_sw(Sysclk::HSI));
while RCC.cfgr().read().sws() != Sysclk::HSI {}
// Configure HSI
let hsi = match config.hsi {
false => None,
true => Some(HSI_FREQ),
}; };
// Configure HSE // Configure HSE
@ -260,6 +261,11 @@ pub(crate) unsafe fn init(config: Config) {
}); });
while RCC.cfgr().read().sws() != config.sys {} while RCC.cfgr().read().sws() != config.sys {}
// Disable HSI if not used
if !config.hsi {
RCC.cr().modify(|w| w.set_hsion(false));
}
config.mux.init(); config.mux.init();
set_clocks!( set_clocks!(