Skip to content

Commit ddccb4f

Browse files
authored
Merge pull request #138 from thalesfragoso/wait-pre
Wait for the new prescalers values to take effect
2 parents c888eaa + f0a9ec8 commit ddccb4f

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Wait 16 cycles after setting prescalers for some clock domains to follow manual.
13+
1014
## [v0.7.0] - 2020-03-07
1115

1216
### Changed

src/rcc.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,22 +353,29 @@ impl CFGR {
353353
while rcc.cr.read().pllrdy().bit_is_clear() {}
354354
}
355355

356-
// Set scaling factors and select system clock source
356+
// Set scaling factors
357357
rcc.cfgr.modify(|_, w| unsafe {
358358
w.ppre2()
359359
.bits(ppre2_bits)
360360
.ppre1()
361361
.bits(ppre1_bits)
362362
.hpre()
363363
.variant(hpre_bits)
364-
.sw()
365-
.variant(if sysclk_on_pll {
366-
SW_A::PLL
367-
} else if self.hse.is_some() {
368-
SW_A::HSE
369-
} else {
370-
SW_A::HSI
371-
})
364+
});
365+
366+
// Wait for the new prescalers to kick in
367+
// "The clocks are divided with the new prescaler factor from 1 to 16 AHB cycles after write"
368+
cortex_m::asm::delay(16);
369+
370+
// Select system clock source
371+
rcc.cfgr.modify(|_, w| {
372+
w.sw().variant(if sysclk_on_pll {
373+
SW_A::PLL
374+
} else if self.hse.is_some() {
375+
SW_A::HSE
376+
} else {
377+
SW_A::HSI
378+
})
372379
});
373380

374381
let clocks = Clocks {

0 commit comments

Comments
 (0)