Skip to content

Commit df75390

Browse files
Merge #124
124: Use rcc_aclk for flash wait state calculations r=richardeoin a=richardeoin * Add flash wait state table for VOS0 * Add rcc_aclk and use for flash wait state calculations. Closes #120 Co-authored-by: Richard Meadows <[email protected]>
2 parents e358da3 + 6bd2a17 commit df75390

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/rcc/mod.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,10 @@ impl Rcc {
345345
self
346346
}
347347

348-
/// Set the peripheral clock frequency for AHB and AXI
349-
/// peripherals. There are several gated versions `rcc_hclk[1-4]`
350-
/// for different power domains, but they are all the same frequency
348+
/// Set the peripheral clock frequency for AHB and AXI peripherals. There
349+
/// are several gated versions `rcc_hclk[1-4]` for different power domains,
350+
/// and the AXI bus clock is called `rcc_aclk`. However they are all the
351+
/// same frequency.
351352
pub fn hclk<F>(mut self, freq: F) -> Self
352353
where
353354
F: Into<Hertz>,
@@ -436,13 +437,27 @@ macro_rules! ppre_calculate {
436437
impl Rcc {
437438
fn flash_setup(rcc_aclk: u32, vos: Voltage) {
438439
use crate::stm32::FLASH;
439-
let rcc_aclk_mhz = rcc_aclk / 1_000_000;
440+
// ACLK in MHz, round down and subtract 1 from integers. eg.
441+
// 61_999_999 -> 61MHz
442+
// 62_000_000 -> 61MHz
443+
// 62_000_001 -> 62MHz
444+
let rcc_aclk_mhz = (rcc_aclk - 1) / 1_000_000;
440445

441-
// See RM0433 Table 13. FLASH recommended number of wait
446+
// See RM0433 Rev 7 Table 17. FLASH recommended number of wait
442447
// states and programming delay
443448
let (wait_states, progr_delay) = match vos {
449+
// VOS 0 range VCORE 1.26V - 1.40V
450+
Voltage::Scale0 => match rcc_aclk_mhz {
451+
0..=69 => (0, 0),
452+
70..=139 => (1, 1),
453+
140..=184 => (2, 1),
454+
185..=209 => (2, 2),
455+
210..=224 => (3, 2),
456+
225..=239 => (4, 2),
457+
_ => (7, 3),
458+
},
444459
// VOS 1 range VCORE 1.15V - 1.26V
445-
Voltage::Scale0 | Voltage::Scale1 => match rcc_aclk_mhz {
460+
Voltage::Scale1 => match rcc_aclk_mhz {
446461
0..=69 => (0, 0),
447462
70..=139 => (1, 1),
448463
140..=184 => (2, 1),
@@ -456,7 +471,6 @@ impl Rcc {
456471
55..=109 => (1, 1),
457472
110..=164 => (2, 1),
458473
165..=224 => (3, 2),
459-
225 => (4, 2),
460474
_ => (7, 3),
461475
},
462476
// VOS 3 range VCORE 0.95V - 1.05V
@@ -643,6 +657,7 @@ impl Rcc {
643657
// Calculate real AXI and AHB clock
644658
let rcc_hclk = sys_d1cpre_ck / hpre_div;
645659
assert!(rcc_hclk <= rcc_hclk_max);
660+
let rcc_aclk = rcc_hclk; // AXI clock is always equal to AHB clock on H7
646661

647662
// Calculate ppreN dividers and real rcc_pclkN frequencies
648663
ppre_calculate! {
@@ -681,7 +696,7 @@ impl Rcc {
681696
// Start switching clocks here! ----------------------------------------
682697

683698
// Flash setup
684-
Self::flash_setup(sys_d1cpre_ck, vos);
699+
Self::flash_setup(rcc_aclk, vos);
685700

686701
// Ensure CSI is on and stable
687702
rcc.cr.modify(|_, w| w.csion().on());

0 commit comments

Comments
 (0)