aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2021-06-15 16:07:23 +0200
committerUlf Lilleengen <[email protected]>2021-06-15 16:07:23 +0200
commit49fad2de8ae53464e551e581e54b1af4fdc60952 (patch)
tree023a90a1e9e9b4a50a112d56ca1922ca973a1f3f
parentceb5d92da3b19ff3af3d4e0c42b823e25c930353 (diff)
Use correct frequencies for timers
-rw-r--r--embassy-stm32/src/rcc/f4/mod.rs14
-rw-r--r--embassy-stm32/src/rcc/h7/mod.rs2
-rw-r--r--embassy-stm32/src/rcc/l0/mod.rs14
-rw-r--r--embassy-stm32/src/rcc/l4/mod.rs14
-rw-r--r--embassy-stm32/src/rcc/mod.rs2
-rw-r--r--embassy-stm32/src/rcc/wb55/mod.rs22
-rw-r--r--stm32-metapac/gen/src/lib.rs11
7 files changed, 49 insertions, 30 deletions
diff --git a/embassy-stm32/src/rcc/f4/mod.rs b/embassy-stm32/src/rcc/f4/mod.rs
index e8709b5fc..4b17bdf40 100644
--- a/embassy-stm32/src/rcc/f4/mod.rs
+++ b/embassy-stm32/src/rcc/f4/mod.rs
@@ -167,23 +167,23 @@ impl RccExt for RCC {
167 } 167 }
168 }; 168 };
169 169
170 let apb1_freq = match cfgr.apb1_pre { 170 let (apb1_freq, apb1_tim_freq) = match cfgr.apb1_pre {
171 APBPrescaler::NotDivided => ahb_freq, 171 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
172 pre => { 172 pre => {
173 let pre: Ppre = pre.into(); 173 let pre: Ppre = pre.into();
174 let pre: u8 = 1 << (pre.0 - 3); 174 let pre: u8 = 1 << (pre.0 - 3);
175 let freq = ahb_freq / pre as u32; 175 let freq = ahb_freq / pre as u32;
176 freq 176 (freq, freq * 2)
177 } 177 }
178 }; 178 };
179 179
180 let apb2_freq = match cfgr.apb2_pre { 180 let (apb2_freq, apb2_tim_freq) = match cfgr.apb2_pre {
181 APBPrescaler::NotDivided => ahb_freq, 181 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
182 pre => { 182 pre => {
183 let pre: Ppre = pre.into(); 183 let pre: Ppre = pre.into();
184 let pre: u8 = 1 << (pre.0 - 3); 184 let pre: u8 = 1 << (pre.0 - 3);
185 let freq = ahb_freq / (1 << (pre as u8 - 3)); 185 let freq = ahb_freq / (1 << (pre as u8 - 3));
186 freq 186 (freq, freq * 2)
187 } 187 }
188 }; 188 };
189 189
@@ -194,6 +194,8 @@ impl RccExt for RCC {
194 ahb3: ahb_freq.hz(), 194 ahb3: ahb_freq.hz(),
195 apb1: apb1_freq.hz(), 195 apb1: apb1_freq.hz(),
196 apb2: apb2_freq.hz(), 196 apb2: apb2_freq.hz(),
197 apb1_tim: apb1_tim_freq.hz(),
198 apb2_tim: apb2_tim_freq.hz(),
197 } 199 }
198 } 200 }
199} 201}
diff --git a/embassy-stm32/src/rcc/h7/mod.rs b/embassy-stm32/src/rcc/h7/mod.rs
index 4bb50be3e..309902335 100644
--- a/embassy-stm32/src/rcc/h7/mod.rs
+++ b/embassy-stm32/src/rcc/h7/mod.rs
@@ -535,5 +535,7 @@ pub unsafe fn init(config: Config) {
535 apb1: core_clocks.pclk1, 535 apb1: core_clocks.pclk1,
536 apb2: core_clocks.pclk2, 536 apb2: core_clocks.pclk2,
537 apb4: core_clocks.pclk4, 537 apb4: core_clocks.pclk4,
538 apb1_tim: core_clocks.timx_ker_ck.unwrap_or(core_clocks.pclk1),
539 apb2_tim: core_clocks.timy_ker_ck.unwrap_or(core_clocks.pclk2),
538 }); 540 });
539} 541}
diff --git a/embassy-stm32/src/rcc/l0/mod.rs b/embassy-stm32/src/rcc/l0/mod.rs
index 2d51c690f..9a8bee418 100644
--- a/embassy-stm32/src/rcc/l0/mod.rs
+++ b/embassy-stm32/src/rcc/l0/mod.rs
@@ -353,23 +353,23 @@ impl RccExt for RCC {
353 } 353 }
354 }; 354 };
355 355
356 let apb1_freq = match cfgr.apb1_pre { 356 let (apb1_freq, apb1_tim_freq) = match cfgr.apb1_pre {
357 APBPrescaler::NotDivided => ahb_freq, 357 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
358 pre => { 358 pre => {
359 let pre: Ppre = pre.into(); 359 let pre: Ppre = pre.into();
360 let pre: u8 = 1 << (pre.0 - 3); 360 let pre: u8 = 1 << (pre.0 - 3);
361 let freq = ahb_freq / pre as u32; 361 let freq = ahb_freq / pre as u32;
362 freq 362 (freq, freq * 2)
363 } 363 }
364 }; 364 };
365 365
366 let apb2_freq = match cfgr.apb2_pre { 366 let (apb2_freq, apb2_tim_freq) = match cfgr.apb2_pre {
367 APBPrescaler::NotDivided => ahb_freq, 367 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
368 pre => { 368 pre => {
369 let pre: Ppre = pre.into(); 369 let pre: Ppre = pre.into();
370 let pre: u8 = 1 << (pre.0 - 3); 370 let pre: u8 = 1 << (pre.0 - 3);
371 let freq = ahb_freq / (1 << (pre as u8 - 3)); 371 let freq = ahb_freq / (1 << (pre as u8 - 3));
372 freq 372 (freq, freq * 2)
373 } 373 }
374 }; 374 };
375 375
@@ -378,6 +378,8 @@ impl RccExt for RCC {
378 ahb: ahb_freq.hz(), 378 ahb: ahb_freq.hz(),
379 apb1: apb1_freq.hz(), 379 apb1: apb1_freq.hz(),
380 apb2: apb2_freq.hz(), 380 apb2: apb2_freq.hz(),
381 apb1_tim: apb1_tim_freq.hz(),
382 apb2_tim: apb2_tim_freq.hz(),
381 } 383 }
382 } 384 }
383} 385}
diff --git a/embassy-stm32/src/rcc/l4/mod.rs b/embassy-stm32/src/rcc/l4/mod.rs
index 9ae6d62b9..e6662f59f 100644
--- a/embassy-stm32/src/rcc/l4/mod.rs
+++ b/embassy-stm32/src/rcc/l4/mod.rs
@@ -166,23 +166,23 @@ impl RccExt for RCC {
166 } 166 }
167 }; 167 };
168 168
169 let apb1_freq = match cfgr.apb1_pre { 169 let (apb1_freq, apb1_tim_freq) = match cfgr.apb1_pre {
170 APBPrescaler::NotDivided => ahb_freq, 170 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
171 pre => { 171 pre => {
172 let pre: u8 = pre.into(); 172 let pre: u8 = pre.into();
173 let pre: u8 = 1 << (pre - 3); 173 let pre: u8 = 1 << (pre - 3);
174 let freq = ahb_freq / pre as u32; 174 let freq = ahb_freq / pre as u32;
175 freq 175 (freq, freq * 2)
176 } 176 }
177 }; 177 };
178 178
179 let apb2_freq = match cfgr.apb2_pre { 179 let (apb2_freq, apb2_tim_freq) = match cfgr.apb2_pre {
180 APBPrescaler::NotDivided => ahb_freq, 180 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
181 pre => { 181 pre => {
182 let pre: u8 = pre.into(); 182 let pre: u8 = pre.into();
183 let pre: u8 = 1 << (pre - 3); 183 let pre: u8 = 1 << (pre - 3);
184 let freq = ahb_freq / (1 << (pre as u8 - 3)); 184 let freq = ahb_freq / (1 << (pre as u8 - 3));
185 freq 185 (freq, freq * 2)
186 } 186 }
187 }; 187 };
188 188
@@ -193,6 +193,8 @@ impl RccExt for RCC {
193 ahb3: ahb_freq.hz(), 193 ahb3: ahb_freq.hz(),
194 apb1: apb1_freq.hz(), 194 apb1: apb1_freq.hz(),
195 apb2: apb2_freq.hz(), 195 apb2: apb2_freq.hz(),
196 apb1_tim: apb1_tim_freq.hz(),
197 apb2_tim: apb2_tim_freq.hz(),
196 } 198 }
197 } 199 }
198} 200}
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index 096ba6b95..7721c2857 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -10,6 +10,8 @@ pub struct Clocks {
10 pub sys: Hertz, 10 pub sys: Hertz,
11 pub apb1: Hertz, 11 pub apb1: Hertz,
12 pub apb2: Hertz, 12 pub apb2: Hertz,
13 pub apb1_tim: Hertz,
14 pub apb2_tim: Hertz,
13 15
14 #[cfg(any(rcc_l0))] 16 #[cfg(any(rcc_l0))]
15 pub ahb: Hertz, 17 pub ahb: Hertz,
diff --git a/embassy-stm32/src/rcc/wb55/mod.rs b/embassy-stm32/src/rcc/wb55/mod.rs
index 9ae6d62b9..3d508f343 100644
--- a/embassy-stm32/src/rcc/wb55/mod.rs
+++ b/embassy-stm32/src/rcc/wb55/mod.rs
@@ -166,23 +166,23 @@ impl RccExt for RCC {
166 } 166 }
167 }; 167 };
168 168
169 let apb1_freq = match cfgr.apb1_pre { 169 let (apb1_freq, apb1_tim_freq) = match cfgr.apb1_pre {
170 APBPrescaler::NotDivided => ahb_freq, 170 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
171 pre => { 171 pre => {
172 let pre: u8 = pre.into(); 172 let pre: Ppre = pre.into();
173 let pre: u8 = 1 << (pre - 3); 173 let pre: u8 = 1 << (pre.0 - 3);
174 let freq = ahb_freq / pre as u32; 174 let freq = ahb_freq / pre as u32;
175 freq 175 (freq, freq * 2)
176 } 176 }
177 }; 177 };
178 178
179 let apb2_freq = match cfgr.apb2_pre { 179 let (apb2_freq, apb2_tim_freq) = match cfgr.apb2_pre {
180 APBPrescaler::NotDivided => ahb_freq, 180 APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
181 pre => { 181 pre => {
182 let pre: u8 = pre.into(); 182 let pre: Ppre = pre.into();
183 let pre: u8 = 1 << (pre - 3); 183 let pre: u8 = 1 << (pre.0 - 3);
184 let freq = ahb_freq / (1 << (pre as u8 - 3)); 184 let freq = ahb_freq / (1 << (pre as u8 - 3));
185 freq 185 (freq, freq * 2)
186 } 186 }
187 }; 187 };
188 188
@@ -193,6 +193,8 @@ impl RccExt for RCC {
193 ahb3: ahb_freq.hz(), 193 ahb3: ahb_freq.hz(),
194 apb1: apb1_freq.hz(), 194 apb1: apb1_freq.hz(),
195 apb2: apb2_freq.hz(), 195 apb2: apb2_freq.hz(),
196 apb1_tim: apb1_tim_freq.hz(),
197 apb2_tim: apb2_tim_freq.hz(),
196 } 198 }
197 } 199 }
198} 200}
diff --git a/stm32-metapac/gen/src/lib.rs b/stm32-metapac/gen/src/lib.rs
index 5133aef9a..5a021569c 100644
--- a/stm32-metapac/gen/src/lib.rs
+++ b/stm32-metapac/gen/src/lib.rs
@@ -291,7 +291,7 @@ pub fn gen(options: Options) {
291 291
292 match (en, rst) { 292 match (en, rst) {
293 (Some((enable_reg, enable_field)), Some((reset_reg, reset_field))) => { 293 (Some((enable_reg, enable_field)), Some((reset_reg, reset_field))) => {
294 let clock = if clock_prefix == "" { 294 let clock = if clock_prefix.is_empty() {
295 let re = Regex::new("([A-Z]+\\d*).*").unwrap(); 295 let re = Regex::new("([A-Z]+\\d*).*").unwrap();
296 if !re.is_match(enable_reg) { 296 if !re.is_match(enable_reg) {
297 panic!( 297 panic!(
@@ -305,9 +305,16 @@ pub fn gen(options: Options) {
305 } else { 305 } else {
306 clock_prefix 306 clock_prefix
307 }; 307 };
308
309 let clock = if name.starts_with("TIM") {
310 format!("{}_tim", clock.to_ascii_lowercase())
311 } else {
312 clock.to_ascii_lowercase()
313 };
314
308 peripheral_rcc_table.push(vec![ 315 peripheral_rcc_table.push(vec![
309 name.clone(), 316 name.clone(),
310 clock.to_ascii_lowercase(), 317 clock,
311 enable_reg.to_ascii_lowercase(), 318 enable_reg.to_ascii_lowercase(),
312 reset_reg.to_ascii_lowercase(), 319 reset_reg.to_ascii_lowercase(),
313 format!("set_{}", enable_field.to_ascii_lowercase()), 320 format!("set_{}", enable_field.to_ascii_lowercase()),