@@ -50,11 +50,21 @@ pub fn init(rcc: &mut Rcc, pwr: &mut Pwr, flash: &mut Flash) {
50
50
rcc. cr . update ( |r| r. set_pllon ( false ) ) ;
51
51
while rcc. cr . read ( ) . pllrdy ( ) { }
52
52
// Configure the main PLL clock source, multiplication and division factors.
53
+ // HSE is used as clock source. HSE runs at 25 MHz.
54
+ // PLLM = 25: Division factor for the main PLLs (PLL, PLLI2S and PLLSAI) input clock
55
+ // VCO input frequency = PLL input clock frequency / PLLM with 2 ≤ PLLM ≤ 63
56
+ // => VCO input frequency = 25_000 kHz / 25 = 1_000 kHz = 1 MHz
57
+ // PPLM = 432: Main PLL (PLL) multiplication factor for VCO
58
+ // VCO output frequency = VCO input frequency × PLLN with 50 ≤ PLLN ≤ 432
59
+ // => VCO output frequency 1 Mhz * 432 = 432 MHz
60
+ // PPLQ = 0 =^= division factor 2: Main PLL (PLL) division factor for main system clock
61
+ // PLL output clock frequency = VCO frequency / PLLP with PLLP = 2, 4, 6, or 8
62
+ // => PLL output clock frequency = 432 MHz / 2 = 216 MHz
53
63
rcc. pllcfgr . update ( |r| {
54
64
r. set_pllsrc ( true ) ; // HSE
55
65
r. set_pllm ( 25 ) ;
56
66
r. set_plln ( 432 ) ; // 400 for 200 MHz, 432 for 216 MHz(don't forget to update `get_frequency`)
57
- r. set_pllp ( 0 ) ; // 0 == division factor 2
67
+ r. set_pllp ( 0 ) ; // 0 =^ = division factor 2
58
68
r. set_pllq ( 9 ) ; // 8 for 200 MHz, 9 for 216 MHz
59
69
} ) ;
60
70
// enable main PLL
@@ -78,6 +88,8 @@ pub fn init(rcc: &mut Rcc, pwr: &mut Pwr, flash: &mut Flash) {
78
88
const SYSTEM_CLOCK_PLL : u8 = 0b10 ;
79
89
80
90
// HCLK Configuration
91
+ // HPRE = system clock not divided: AHB prescaler
92
+ // => AHB clock frequency = system clock / 1 = 216 MHz / 1 = 216 MHz
81
93
rcc. cfgr . update ( |r| r. set_hpre ( NO_DIVIDE ) ) ;
82
94
// SYSCLK Configuration
83
95
rcc. cfgr . update ( |r| r. set_sw ( SYSTEM_CLOCK_PLL ) ) ;
@@ -87,8 +99,14 @@ pub fn init(rcc: &mut Rcc, pwr: &mut Pwr, flash: &mut Flash) {
87
99
const DIVIDE_4 : u8 = 0b101 ;
88
100
89
101
// PCLK1 Configuration
102
+ // PPRE1: APB Low-speed prescaler (APB1)
103
+ // => APB low-speed clock frequency = 216 Mhz / 4 = 54 MHz
104
+ // FIXME: Frequency should not exceed 45 MHz
90
105
rcc. cfgr . update ( |r| r. set_ppre1 ( DIVIDE_4 ) ) ;
91
106
// PCLK2 Configuration
107
+ // PPRE2: APB high-speed prescaler (APB2)
108
+ // => APB high-speed clock frequency = 216 Mhz / 2 = 108 MHz
109
+ // FIXME: Frequency should not exceed 90 MHz
92
110
rcc. cfgr . update ( |r| r. set_ppre2 ( DIVIDE_2 ) ) ;
93
111
94
112
@@ -98,7 +116,9 @@ pub fn init(rcc: &mut Rcc, pwr: &mut Pwr, flash: &mut Flash) {
98
116
let pllm = u32:: from ( pll_cfgr. pllm ( ) ) ;
99
117
let plln = u32:: from ( pll_cfgr. plln ( ) ) ;
100
118
let pllp = u32:: from ( pll_cfgr. pllp ( ) + 1 ) * 2 ;
101
- systick. rvr . write ( 25 * 1000 / pllm * plln / pllp - 1 ) ; // hse runs at 25 MHz
119
+ // SysTick Reload Value Register = ((25000/25) * 432) / 2 - 1 = 215_999
120
+ // => SysTick interrupt tiggers every 1 ms
121
+ systick. rvr . write ( ( ( ( 25 * 1000 ) / pllm) * plln) / pllp - 1 ) ; // hse runs at 25 MHz
102
122
systick. cvr . write ( 0 ) ; // clear
103
123
systick. csr . write ( 0b111 ) ; // CLKSOURCE | TICKINT | ENABLE
104
124
0 commit comments