Skip to content

Commit 2f7358d

Browse files
Disasmmvertescher
authored andcommitted
Fix base frequency calculation
This way SYSCLK is correctly derived from the base frequency even if HSE is requested.
1 parent 455f407 commit 2f7358d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/rcc.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,12 @@ impl CFGR {
271271
// Switch to HSI
272272
rcc.cfgr.modify(|_, w| w.sw().hsi());
273273

274-
// If HSE is provided by the user
275-
let hse_freq: u32 = self.hse.as_ref().map_or(0, |c| c.freq);
276-
// SYSCLK, must be <= 216 Mhz. By default, HSI frequency is chosen
277-
let mut sysclk = self.sysclk.unwrap_or(HSI);
278-
let base_clk = match hse_freq {
279-
0 => HSI,
280-
_ => hse_freq,
274+
let base_clk = match self.hse.as_ref() {
275+
Some(hse) => hse.freq,
276+
None => HSI,
281277
};
278+
// SYSCLK, must be <= 216 Mhz. By default, HSI/HSE frequency is chosen
279+
let mut sysclk = self.sysclk.unwrap_or(base_clk);
282280

283281
// Configure HSE if provided
284282
if self.hse.is_some() {

0 commit comments

Comments
 (0)