aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarnaby Walters <[email protected]>2024-02-16 21:52:58 +0100
committerBarnaby Walters <[email protected]>2024-02-16 21:52:58 +0100
commita24087c36c60e97f8b0aaefe57111c3a2edd6e8a (patch)
tree74228f77be992d808819ac2f9a524083195980e4
parente465dacf739e499f64b7943f4674edfe060f83b7 (diff)
Configured SYSCLK after boost mode, added comments
-rw-r--r--embassy-stm32/src/rcc/g4.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs
index e2afd5260..0c1a1e4b1 100644
--- a/embassy-stm32/src/rcc/g4.rs
+++ b/embassy-stm32/src/rcc/g4.rs
@@ -241,16 +241,13 @@ pub(crate) unsafe fn init(config: Config) {
241 _ => unreachable!(), 241 _ => unreachable!(),
242 }; 242 };
243 243
244 RCC.cfgr().modify(|w| { 244 // Calculate the AHB frequency (HCLK), among other things so we can calculate the correct flash read latency.
245 w.set_sw(sw);
246 w.set_hpre(config.ahb_pre);
247 w.set_ppre1(config.apb1_pre);
248 w.set_ppre2(config.apb2_pre);
249 });
250
251 let ahb_freq = sys_clk / config.ahb_pre; 245 let ahb_freq = sys_clk / config.ahb_pre;
252 246
253 // Configure Core Boost mode ([RM0440] p234 – inverted because setting r1mode to 0 enables boost mode!) 247 // Configure Core Boost mode ([RM0440] p234 – inverted because setting r1mode to 0 enables boost mode!)
248 // TODO: according to RM0440 p235, when switching from range1-normal to range1-boost, it’s necessary to divide
249 // SYSCLK by 2 using the AHB prescaler, set boost and flash read latency, switch system frequency, wait 1us and
250 // reconfigure the AHB prescaler as desired. Unclear whether this is always necessary.
254 PWR.cr5().modify(|w| w.set_r1mode(!config.boost)); 251 PWR.cr5().modify(|w| w.set_r1mode(!config.boost));
255 252
256 // Configure flash read access latency based on boost mode and frequency (RM0440 p98) 253 // Configure flash read access latency based on boost mode and frequency (RM0440 p98)
@@ -270,6 +267,14 @@ pub(crate) unsafe fn init(config: Config) {
270 }) 267 })
271 }); 268 });
272 269
270 // Now that boost mode and flash read access latency are configured, set up SYSCLK
271 RCC.cfgr().modify(|w| {
272 w.set_sw(sw);
273 w.set_hpre(config.ahb_pre);
274 w.set_ppre1(config.apb1_pre);
275 w.set_ppre2(config.apb2_pre);
276 });
277
273 let (apb1_freq, apb1_tim_freq) = match config.apb1_pre { 278 let (apb1_freq, apb1_tim_freq) = match config.apb1_pre {
274 APBPrescaler::DIV1 => (ahb_freq, ahb_freq), 279 APBPrescaler::DIV1 => (ahb_freq, ahb_freq),
275 pre => { 280 pre => {