aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/rcc/bus.rs4
-rw-r--r--embassy-stm32/src/rcc/mod.rs1
-rw-r--r--embassy-stm32/src/rcc/wba.rs88
3 files changed, 33 insertions, 60 deletions
diff --git a/embassy-stm32/src/rcc/bus.rs b/embassy-stm32/src/rcc/bus.rs
index fb6dcb01d..9c9de5486 100644
--- a/embassy-stm32/src/rcc/bus.rs
+++ b/embassy-stm32/src/rcc/bus.rs
@@ -41,9 +41,13 @@ impl Div<AHBPrescaler> for Hertz {
41 AHBPrescaler::DIV16 => 16, 41 AHBPrescaler::DIV16 => 16,
42 #[cfg(any(rcc_wb, rcc_wl5, rcc_wle))] 42 #[cfg(any(rcc_wb, rcc_wl5, rcc_wle))]
43 AHBPrescaler::DIV32 => 32, 43 AHBPrescaler::DIV32 => 32,
44 #[cfg(not(rcc_wba))]
44 AHBPrescaler::DIV64 => 64, 45 AHBPrescaler::DIV64 => 64,
46 #[cfg(not(rcc_wba))]
45 AHBPrescaler::DIV128 => 128, 47 AHBPrescaler::DIV128 => 128,
48 #[cfg(not(rcc_wba))]
46 AHBPrescaler::DIV256 => 256, 49 AHBPrescaler::DIV256 => 256,
50 #[cfg(not(rcc_wba))]
47 AHBPrescaler::DIV512 => 512, 51 AHBPrescaler::DIV512 => 512,
48 _ => unreachable!(), 52 _ => unreachable!(),
49 }; 53 };
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index b8c12b995..892dcf937 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -1,7 +1,6 @@
1#![macro_use] 1#![macro_use]
2 2
3pub(crate) mod bd; 3pub(crate) mod bd;
4#[cfg(not(rcc_wba))]
5pub mod bus; 4pub mod bus;
6use core::mem::MaybeUninit; 5use core::mem::MaybeUninit;
7 6
diff --git a/embassy-stm32/src/rcc/wba.rs b/embassy-stm32/src/rcc/wba.rs
index 2a11c9a22..c5d7ab62f 100644
--- a/embassy-stm32/src/rcc/wba.rs
+++ b/embassy-stm32/src/rcc/wba.rs
@@ -43,36 +43,6 @@ impl Into<Sw> for ClockSrc {
43 } 43 }
44} 44}
45 45
46trait Div {
47 fn div(&self) -> u8;
48}
49
50impl Div for APBPrescaler {
51 fn div(&self) -> u8 {
52 match self {
53 Self::DIV1 => 1,
54 Self::DIV2 => 2,
55 Self::DIV4 => 4,
56 Self::DIV8 => 8,
57 Self::DIV16 => 16,
58 _ => unreachable!(),
59 }
60 }
61}
62
63impl Div for AHBPrescaler {
64 fn div(&self) -> u8 {
65 match self {
66 Self::DIV1 => 1,
67 Self::DIV2 => 2,
68 Self::DIV4 => 4,
69 Self::DIV8 => 8,
70 Self::DIV16 => 16,
71 _ => unreachable!(),
72 }
73 }
74}
75
76#[derive(Copy, Clone)] 46#[derive(Copy, Clone)]
77pub struct Config { 47pub struct Config {
78 pub mux: ClockSrc, 48 pub mux: ClockSrc,
@@ -100,13 +70,13 @@ pub(crate) unsafe fn init(config: Config) {
100 RCC.cr().write(|w| w.set_hseon(true)); 70 RCC.cr().write(|w| w.set_hseon(true));
101 while !RCC.cr().read().hserdy() {} 71 while !RCC.cr().read().hserdy() {}
102 72
103 freq.0 73 freq
104 } 74 }
105 ClockSrc::HSI16 => { 75 ClockSrc::HSI16 => {
106 RCC.cr().write(|w| w.set_hsion(true)); 76 RCC.cr().write(|w| w.set_hsion(true));
107 while !RCC.cr().read().hsirdy() {} 77 while !RCC.cr().read().hsirdy() {}
108 78
109 HSI_FREQ.0 79 HSI_FREQ
110 } 80 }
111 }; 81 };
112 82
@@ -115,14 +85,14 @@ pub(crate) unsafe fn init(config: Config) {
115 85
116 // states and programming delay 86 // states and programming delay
117 let wait_states = match power_vos { 87 let wait_states = match power_vos {
118 VoltageScale::RANGE1 => match sys_clk { 88 VoltageScale::RANGE1 => match sys_clk.0 {
119 ..=32_000_000 => 0, 89 ..=32_000_000 => 0,
120 ..=64_000_000 => 1, 90 ..=64_000_000 => 1,
121 ..=96_000_000 => 2, 91 ..=96_000_000 => 2,
122 ..=100_000_000 => 3, 92 ..=100_000_000 => 3,
123 _ => 4, 93 _ => 4,
124 }, 94 },
125 VoltageScale::RANGE2 => match sys_clk { 95 VoltageScale::RANGE2 => match sys_clk.0 {
126 ..=8_000_000 => 0, 96 ..=8_000_000 => 0,
127 ..=16_000_000 => 1, 97 ..=16_000_000 => 1,
128 _ => 2, 98 _ => 2,
@@ -147,38 +117,38 @@ pub(crate) unsafe fn init(config: Config) {
147 w.set_ppre7(config.apb7_pre.into()); 117 w.set_ppre7(config.apb7_pre.into());
148 }); 118 });
149 119
150 let ahb_freq: u32 = sys_clk / config.ahb_pre.div() as u32; 120 let ahb_freq = sys_clk / config.ahb_pre;
151 let (apb1_freq, apb1_tim_freq) = match config.apb1_pre.div() { 121 let (apb1_freq, apb1_tim_freq) = match config.apb1_pre {
152 1 => (ahb_freq, ahb_freq), 122 APBPrescaler::DIV1 => (ahb_freq, ahb_freq),
153 div => { 123 pre => {
154 let freq = ahb_freq / div as u32; 124 let freq = ahb_freq / pre;
155 (freq, freq * 2) 125 (freq, freq * 2u32)
156 } 126 }
157 }; 127 };
158 let (apb2_freq, apb2_tim_freq) = match config.apb2_pre.div() { 128 let (apb2_freq, apb2_tim_freq) = match config.apb2_pre {
159 1 => (ahb_freq, ahb_freq), 129 APBPrescaler::DIV1 => (ahb_freq, ahb_freq),
160 div => { 130 pre => {
161 let freq = ahb_freq / div as u32; 131 let freq = ahb_freq / pre;
162 (freq, freq * 2) 132 (freq, freq * 2u32)
163 } 133 }
164 }; 134 };
165 let (apb7_freq, _apb7_tim_freq) = match config.apb7_pre.div() { 135 let (apb7_freq, _apb7_tim_freq) = match config.apb7_pre {
166 1 => (ahb_freq, ahb_freq), 136 APBPrescaler::DIV1 => (ahb_freq, ahb_freq),
167 div => { 137 pre => {
168 let freq = ahb_freq / div as u32; 138 let freq = ahb_freq / pre;
169 (freq, freq * 2) 139 (freq, freq * 2u32)
170 } 140 }
171 }; 141 };
172 142
173 set_freqs(Clocks { 143 set_freqs(Clocks {
174 sys: Hertz(sys_clk), 144 sys: sys_clk,
175 ahb1: Hertz(ahb_freq), 145 ahb1: ahb_freq,
176 ahb2: Hertz(ahb_freq), 146 ahb2: ahb_freq,
177 ahb4: Hertz(ahb_freq), 147 ahb4: ahb_freq,
178 apb1: Hertz(apb1_freq), 148 apb1: apb1_freq,
179 apb2: Hertz(apb2_freq), 149 apb2: apb2_freq,
180 apb7: Hertz(apb7_freq), 150 apb7: apb7_freq,
181 apb1_tim: Hertz(apb1_tim_freq), 151 apb1_tim: apb1_tim_freq,
182 apb2_tim: Hertz(apb2_tim_freq), 152 apb2_tim: apb2_tim_freq,
183 }); 153 });
184} 154}