@@ -345,9 +345,10 @@ impl Rcc {
345
345
self
346
346
}
347
347
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.
351
352
pub fn hclk < F > ( mut self , freq : F ) -> Self
352
353
where
353
354
F : Into < Hertz > ,
@@ -436,13 +437,27 @@ macro_rules! ppre_calculate {
436
437
impl Rcc {
437
438
fn flash_setup ( rcc_aclk : u32 , vos : Voltage ) {
438
439
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 ;
440
445
441
- // See RM0433 Table 13 . FLASH recommended number of wait
446
+ // See RM0433 Rev 7 Table 17 . FLASH recommended number of wait
442
447
// states and programming delay
443
448
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
+ } ,
444
459
// VOS 1 range VCORE 1.15V - 1.26V
445
- Voltage :: Scale0 | Voltage :: Scale1 => match rcc_aclk_mhz {
460
+ Voltage :: Scale1 => match rcc_aclk_mhz {
446
461
0 ..=69 => ( 0 , 0 ) ,
447
462
70 ..=139 => ( 1 , 1 ) ,
448
463
140 ..=184 => ( 2 , 1 ) ,
@@ -456,7 +471,6 @@ impl Rcc {
456
471
55 ..=109 => ( 1 , 1 ) ,
457
472
110 ..=164 => ( 2 , 1 ) ,
458
473
165 ..=224 => ( 3 , 2 ) ,
459
- 225 => ( 4 , 2 ) ,
460
474
_ => ( 7 , 3 ) ,
461
475
} ,
462
476
// VOS 3 range VCORE 0.95V - 1.05V
@@ -643,6 +657,7 @@ impl Rcc {
643
657
// Calculate real AXI and AHB clock
644
658
let rcc_hclk = sys_d1cpre_ck / hpre_div;
645
659
assert ! ( rcc_hclk <= rcc_hclk_max) ;
660
+ let rcc_aclk = rcc_hclk; // AXI clock is always equal to AHB clock on H7
646
661
647
662
// Calculate ppreN dividers and real rcc_pclkN frequencies
648
663
ppre_calculate ! {
@@ -681,7 +696,7 @@ impl Rcc {
681
696
// Start switching clocks here! ----------------------------------------
682
697
683
698
// Flash setup
684
- Self :: flash_setup ( sys_d1cpre_ck , vos) ;
699
+ Self :: flash_setup ( rcc_aclk , vos) ;
685
700
686
701
// Ensure CSI is on and stable
687
702
rcc. cr . modify ( |_, w| w. csion ( ) . on ( ) ) ;
0 commit comments