Skip to content

Commit 69baa3a

Browse files
f-brooli-obk
authored andcommitted
Add methods for AHB-, APB1-, APB2-frequency
1 parent e27bf55 commit 69baa3a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/system_clock.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ pub fn init(rcc: &mut Rcc, pwr: &mut Pwr, flash: &mut Flash) {
100100

101101
// PCLK1 Configuration
102102
// PPRE1: APB Low-speed prescaler (APB1)
103-
// => APB low-speed clock frequency = 216 Mhz / 4 = 54 MHz
103+
// => APB low-speed clock frequency = AHB clock / 4 = 216 Mhz / 4 = 54 MHz
104104
// FIXME: Frequency should not exceed 45 MHz
105105
rcc.cfgr.update(|r| r.set_ppre1(DIVIDE_4));
106106
// PCLK2 Configuration
107107
// PPRE2: APB high-speed prescaler (APB2)
108-
// => APB high-speed clock frequency = 216 Mhz / 2 = 108 MHz
108+
// => APB high-speed clock frequency = AHB clock / 2 = 216 Mhz / 2 = 108 MHz
109109
// FIXME: Frequency should not exceed 90 MHz
110110
rcc.cfgr.update(|r| r.set_ppre2(DIVIDE_2));
111111

@@ -128,3 +128,15 @@ pub fn init(rcc: &mut Rcc, pwr: &mut Pwr, flash: &mut Flash) {
128128
pub fn get_frequency() -> u32 {
129129
216_000_000 // 216 MHz
130130
}
131+
132+
pub fn get_ahb_frequency() -> u32 {
133+
get_frequency() / 1 //216 MHz
134+
}
135+
136+
pub fn get_apb1_frequency() -> u32 {
137+
get_ahb_frequency / 4 // 54 MHz
138+
}
139+
140+
pub fn get_apb2_frequency() -> u32 {
141+
get_ahb_frequency / 2 // 108 MHz
142+
}

0 commit comments

Comments
 (0)