aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-04-13 02:13:41 +0200
committerDario Nieuwenhuis <[email protected]>2024-04-14 22:29:07 +0200
commit65c085ce910f50903bc5c41ca82eda989810f855 (patch)
tree2dde97f356234411a1c5d780eba9e55a7f90f8ff /embassy-stm32/src
parent87b79d449916b26d0d29b6247ae366a80c02cfa5 (diff)
Add stm32u0 support.
Diffstat (limited to 'embassy-stm32/src')
-rw-r--r--embassy-stm32/src/exti.rs16
-rw-r--r--embassy-stm32/src/rcc/l.rs28
-rw-r--r--embassy-stm32/src/rcc/mco.rs2
-rw-r--r--embassy-stm32/src/rcc/mod.rs2
4 files changed, 34 insertions, 14 deletions
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index 8d5dae436..224d51b84 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -27,11 +27,11 @@ fn cpu_regs() -> pac::exti::Exti {
27 EXTI 27 EXTI
28} 28}
29 29
30#[cfg(not(any(exti_c0, exti_g0, exti_l5, gpio_v1, exti_u5, exti_h5, exti_h50)))] 30#[cfg(not(any(exti_c0, exti_g0, exti_u0, exti_l5, gpio_v1, exti_u5, exti_h5, exti_h50)))]
31fn exticr_regs() -> pac::syscfg::Syscfg { 31fn exticr_regs() -> pac::syscfg::Syscfg {
32 pac::SYSCFG 32 pac::SYSCFG
33} 33}
34#[cfg(any(exti_c0, exti_g0, exti_l5, exti_u5, exti_h5, exti_h50))] 34#[cfg(any(exti_c0, exti_g0, exti_u0, exti_l5, exti_u5, exti_h5, exti_h50))]
35fn exticr_regs() -> pac::exti::Exti { 35fn exticr_regs() -> pac::exti::Exti {
36 EXTI 36 EXTI
37} 37}
@@ -44,9 +44,9 @@ unsafe fn on_irq() {
44 #[cfg(feature = "low-power")] 44 #[cfg(feature = "low-power")]
45 crate::low_power::on_wakeup_irq(); 45 crate::low_power::on_wakeup_irq();
46 46
47 #[cfg(not(any(exti_c0, exti_g0, exti_l5, exti_u5, exti_h5, exti_h50)))] 47 #[cfg(not(any(exti_c0, exti_g0, exti_u0, exti_l5, exti_u5, exti_h5, exti_h50)))]
48 let bits = EXTI.pr(0).read().0; 48 let bits = EXTI.pr(0).read().0;
49 #[cfg(any(exti_c0, exti_g0, exti_l5, exti_u5, exti_h5, exti_h50))] 49 #[cfg(any(exti_c0, exti_g0, exti_u0, exti_l5, exti_u5, exti_h5, exti_h50))]
50 let bits = EXTI.rpr(0).read().0 | EXTI.fpr(0).read().0; 50 let bits = EXTI.rpr(0).read().0 | EXTI.fpr(0).read().0;
51 51
52 // We don't handle or change any EXTI lines above 16. 52 // We don't handle or change any EXTI lines above 16.
@@ -61,9 +61,9 @@ unsafe fn on_irq() {
61 } 61 }
62 62
63 // Clear pending 63 // Clear pending
64 #[cfg(not(any(exti_c0, exti_g0, exti_l5, exti_u5, exti_h5, exti_h50)))] 64 #[cfg(not(any(exti_c0, exti_g0, exti_u0, exti_l5, exti_u5, exti_h5, exti_h50)))]
65 EXTI.pr(0).write_value(Lines(bits)); 65 EXTI.pr(0).write_value(Lines(bits));
66 #[cfg(any(exti_c0, exti_g0, exti_l5, exti_u5, exti_h5, exti_h50))] 66 #[cfg(any(exti_c0, exti_g0, exti_u0, exti_l5, exti_u5, exti_h5, exti_h50))]
67 { 67 {
68 EXTI.rpr(0).write_value(Lines(bits)); 68 EXTI.rpr(0).write_value(Lines(bits));
69 EXTI.fpr(0).write_value(Lines(bits)); 69 EXTI.fpr(0).write_value(Lines(bits));
@@ -241,9 +241,9 @@ impl<'a> ExtiInputFuture<'a> {
241 EXTI.ftsr(0).modify(|w| w.set_line(pin, falling)); 241 EXTI.ftsr(0).modify(|w| w.set_line(pin, falling));
242 242
243 // clear pending bit 243 // clear pending bit
244 #[cfg(not(any(exti_c0, exti_g0, exti_l5, exti_u5, exti_h5, exti_h50)))] 244 #[cfg(not(any(exti_c0, exti_g0, exti_u0, exti_l5, exti_u5, exti_h5, exti_h50)))]
245 EXTI.pr(0).write(|w| w.set_line(pin, true)); 245 EXTI.pr(0).write(|w| w.set_line(pin, true));
246 #[cfg(any(exti_c0, exti_g0, exti_l5, exti_u5, exti_h5, exti_h50))] 246 #[cfg(any(exti_c0, exti_g0, exti_u0, exti_l5, exti_u5, exti_h5, exti_h50))]
247 { 247 {
248 EXTI.rpr(0).write(|w| w.set_line(pin, true)); 248 EXTI.rpr(0).write(|w| w.set_line(pin, true));
249 EXTI.fpr(0).write(|w| w.set_line(pin, true)); 249 EXTI.fpr(0).write(|w| w.set_line(pin, true));
diff --git a/embassy-stm32/src/rcc/l.rs b/embassy-stm32/src/rcc/l.rs
index 9079ddd41..d7235ac7f 100644
--- a/embassy-stm32/src/rcc/l.rs
+++ b/embassy-stm32/src/rcc/l.rs
@@ -49,6 +49,7 @@ pub struct Config {
49 pub sys: Sysclk, 49 pub sys: Sysclk,
50 pub ahb_pre: AHBPrescaler, 50 pub ahb_pre: AHBPrescaler,
51 pub apb1_pre: APBPrescaler, 51 pub apb1_pre: APBPrescaler,
52 #[cfg(not(stm32u0))]
52 pub apb2_pre: APBPrescaler, 53 pub apb2_pre: APBPrescaler,
53 #[cfg(any(stm32wl5x, stm32wb))] 54 #[cfg(any(stm32wl5x, stm32wb))]
54 pub core2_ahb_pre: AHBPrescaler, 55 pub core2_ahb_pre: AHBPrescaler,
@@ -75,6 +76,7 @@ impl Default for Config {
75 sys: Sysclk::MSI, 76 sys: Sysclk::MSI,
76 ahb_pre: AHBPrescaler::DIV1, 77 ahb_pre: AHBPrescaler::DIV1,
77 apb1_pre: APBPrescaler::DIV1, 78 apb1_pre: APBPrescaler::DIV1,
79 #[cfg(not(stm32u0))]
78 apb2_pre: APBPrescaler::DIV1, 80 apb2_pre: APBPrescaler::DIV1,
79 #[cfg(any(stm32wl5x, stm32wb))] 81 #[cfg(any(stm32wl5x, stm32wb))]
80 core2_ahb_pre: AHBPrescaler::DIV1, 82 core2_ahb_pre: AHBPrescaler::DIV1,
@@ -130,7 +132,7 @@ pub const WPAN_DEFAULT: Config = Config {
130}; 132};
131 133
132fn msi_enable(range: MSIRange) { 134fn msi_enable(range: MSIRange) {
133 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))] 135 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl, stm32u0))]
134 RCC.cr().modify(|w| { 136 RCC.cr().modify(|w| {
135 #[cfg(not(stm32wb))] 137 #[cfg(not(stm32wb))]
136 w.set_msirgsel(crate::pac::rcc::vals::Msirgsel::CR); 138 w.set_msirgsel(crate::pac::rcc::vals::Msirgsel::CR);
@@ -240,7 +242,7 @@ pub(crate) unsafe fn init(config: Config) {
240 let pll_input = PllInput { 242 let pll_input = PllInput {
241 hse, 243 hse,
242 hsi, 244 hsi,
243 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))] 245 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl, stm32u0))]
244 msi, 246 msi,
245 }; 247 };
246 let pll = init_pll(PllInstance::Pll, config.pll, &pll_input); 248 let pll = init_pll(PllInstance::Pll, config.pll, &pll_input);
@@ -254,6 +256,10 @@ pub(crate) unsafe fn init(config: Config) {
254 Sysclk::HSI => hsi.unwrap(), 256 Sysclk::HSI => hsi.unwrap(),
255 Sysclk::MSI => msi.unwrap(), 257 Sysclk::MSI => msi.unwrap(),
256 Sysclk::PLL1_R => pll.r.unwrap(), 258 Sysclk::PLL1_R => pll.r.unwrap(),
259 #[cfg(stm32u0)]
260 Sysclk::LSI | Sysclk::LSE => todo!(),
261 #[cfg(stm32u0)]
262 Sysclk::_RESERVED_6 | Sysclk::_RESERVED_7 => unreachable!(),
257 }; 263 };
258 264
259 #[cfg(rcc_l4plus)] 265 #[cfg(rcc_l4plus)]
@@ -263,6 +269,7 @@ pub(crate) unsafe fn init(config: Config) {
263 269
264 let hclk1 = sys_clk / config.ahb_pre; 270 let hclk1 = sys_clk / config.ahb_pre;
265 let (pclk1, pclk1_tim) = super::util::calc_pclk(hclk1, config.apb1_pre); 271 let (pclk1, pclk1_tim) = super::util::calc_pclk(hclk1, config.apb1_pre);
272 #[cfg(not(stm32u0))]
266 let (pclk2, pclk2_tim) = super::util::calc_pclk(hclk1, config.apb2_pre); 273 let (pclk2, pclk2_tim) = super::util::calc_pclk(hclk1, config.apb2_pre);
267 #[cfg(any(stm32l4, stm32l5, stm32wlex))] 274 #[cfg(any(stm32l4, stm32l5, stm32wlex))]
268 let hclk2 = hclk1; 275 let hclk2 = hclk1;
@@ -315,6 +322,13 @@ pub(crate) unsafe fn init(config: Config) {
315 ..=64_000_000 => 3, 322 ..=64_000_000 => 3,
316 _ => 4, 323 _ => 4,
317 }; 324 };
325 #[cfg(stm32u0)]
326 let latency = match hclk1.0 {
327 // VOS RANGE1, others TODO.
328 ..=24_000_000 => 0,
329 ..=48_000_000 => 1,
330 _ => 2,
331 };
318 332
319 #[cfg(stm32l1)] 333 #[cfg(stm32l1)]
320 FLASH.acr().write(|w| w.set_acc64(true)); 334 FLASH.acr().write(|w| w.set_acc64(true));
@@ -326,7 +340,11 @@ pub(crate) unsafe fn init(config: Config) {
326 RCC.cfgr().modify(|w| { 340 RCC.cfgr().modify(|w| {
327 w.set_sw(config.sys); 341 w.set_sw(config.sys);
328 w.set_hpre(config.ahb_pre); 342 w.set_hpre(config.ahb_pre);
343 #[cfg(stm32u0)]
344 w.set_ppre(config.apb1_pre);
345 #[cfg(not(stm32u0))]
329 w.set_ppre1(config.apb1_pre); 346 w.set_ppre1(config.apb1_pre);
347 #[cfg(not(stm32u0))]
330 w.set_ppre2(config.apb2_pre); 348 w.set_ppre2(config.apb2_pre);
331 }); 349 });
332 while RCC.cfgr().read().sws() != config.sys {} 350 while RCC.cfgr().read().sws() != config.sys {}
@@ -353,8 +371,10 @@ pub(crate) unsafe fn init(config: Config) {
353 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))] 371 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
354 hclk3: Some(hclk3), 372 hclk3: Some(hclk3),
355 pclk1: Some(pclk1), 373 pclk1: Some(pclk1),
374 #[cfg(not(stm32u0))]
356 pclk2: Some(pclk2), 375 pclk2: Some(pclk2),
357 pclk1_tim: Some(pclk1_tim), 376 pclk1_tim: Some(pclk1_tim),
377 #[cfg(not(stm32u0))]
358 pclk2_tim: Some(pclk2_tim), 378 pclk2_tim: Some(pclk2_tim),
359 #[cfg(stm32wl)] 379 #[cfg(stm32wl)]
360 pclk3: Some(hclk3), 380 pclk3: Some(hclk3),
@@ -408,7 +428,7 @@ fn msirange_to_hertz(range: MSIRange) -> Hertz {
408 Hertz(32_768 * (1 << (range as u8 + 1))) 428 Hertz(32_768 * (1 << (range as u8 + 1)))
409} 429}
410 430
411#[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))] 431#[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl, stm32u0))]
412fn msirange_to_hertz(range: MSIRange) -> Hertz { 432fn msirange_to_hertz(range: MSIRange) -> Hertz {
413 match range { 433 match range {
414 MSIRange::RANGE100K => Hertz(100_000), 434 MSIRange::RANGE100K => Hertz(100_000),
@@ -521,7 +541,7 @@ mod pll {
521 } 541 }
522} 542}
523 543
524#[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))] 544#[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl, stm32u0))]
525mod pll { 545mod pll {
526 use super::{pll_enable, PllInstance}; 546 use super::{pll_enable, PllInstance};
527 pub use crate::pac::rcc::vals::{ 547 pub use crate::pac::rcc::vals::{
diff --git a/embassy-stm32/src/rcc/mco.rs b/embassy-stm32/src/rcc/mco.rs
index d8604e07e..4b22a099d 100644
--- a/embassy-stm32/src/rcc/mco.rs
+++ b/embassy-stm32/src/rcc/mco.rs
@@ -52,7 +52,7 @@ macro_rules! impl_peri {
52 }; 52 };
53} 53}
54 54
55#[cfg(any(rcc_c0, rcc_g0))] 55#[cfg(any(rcc_c0, rcc_g0, rcc_u0))]
56#[allow(unused_imports)] 56#[allow(unused_imports)]
57use self::{McoSource as Mco1Source, McoSource as Mco2Source}; 57use self::{McoSource as Mco1Source, McoSource as Mco2Source};
58 58
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index 5497bba07..a4e497fe7 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -25,7 +25,7 @@ pub use hsi48::*;
25#[cfg_attr(stm32g0, path = "g0.rs")] 25#[cfg_attr(stm32g0, path = "g0.rs")]
26#[cfg_attr(stm32g4, path = "g4.rs")] 26#[cfg_attr(stm32g4, path = "g4.rs")]
27#[cfg_attr(any(stm32h5, stm32h7), path = "h.rs")] 27#[cfg_attr(any(stm32h5, stm32h7), path = "h.rs")]
28#[cfg_attr(any(stm32l0, stm32l1, stm32l4, stm32l5, stm32wb, stm32wl), path = "l.rs")] 28#[cfg_attr(any(stm32l0, stm32l1, stm32l4, stm32l5, stm32wb, stm32wl, stm32u0), path = "l.rs")]
29#[cfg_attr(stm32u5, path = "u5.rs")] 29#[cfg_attr(stm32u5, path = "u5.rs")]
30#[cfg_attr(stm32wba, path = "wba.rs")] 30#[cfg_attr(stm32wba, path = "wba.rs")]
31mod _version; 31mod _version;