diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-02-02 01:36:34 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-02 01:36:34 +0000 |
| commit | 9e704e622abc348d63c061425c9699fbff9ca7d2 (patch) | |
| tree | 3e52cbfa257d2838dba62d632b60eececc886aa2 | |
| parent | b7bc31e51a6c6be658acc9f09bed41b94ea57623 (diff) | |
| parent | e05c8e2f44d3b210affa10a6e7fc7e9a3c991683 (diff) | |
Merge pull request #2517 from embassy-rs/rcc-mux
stm32: misc rcc cleanups
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/build.rs | 15 | ||||
| -rw-r--r-- | embassy-stm32/src/dac/mod.rs | 23 |
3 files changed, 15 insertions, 27 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 698febf71..aed9f7a46 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -68,7 +68,7 @@ rand_core = "0.6.3" | |||
| 68 | sdio-host = "0.5.0" | 68 | sdio-host = "0.5.0" |
| 69 | critical-section = "1.1" | 69 | critical-section = "1.1" |
| 70 | #stm32-metapac = { version = "15" } | 70 | #stm32-metapac = { version = "15" } |
| 71 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-0cb3a4fcaec702c93b3700715de796636d562b15" } | 71 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-768b3e8e3199e03de0acd0d4590d06f51eebb7dd" } |
| 72 | vcell = "0.1.3" | 72 | vcell = "0.1.3" |
| 73 | bxcan = "0.7.0" | 73 | bxcan = "0.7.0" |
| 74 | nb = "1.0.0" | 74 | nb = "1.0.0" |
| @@ -89,7 +89,7 @@ critical-section = { version = "1.1", features = ["std"] } | |||
| 89 | proc-macro2 = "1.0.36" | 89 | proc-macro2 = "1.0.36" |
| 90 | quote = "1.0.15" | 90 | quote = "1.0.15" |
| 91 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} | 91 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} |
| 92 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-0cb3a4fcaec702c93b3700715de796636d562b15", default-features = false, features = ["metadata"]} | 92 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-768b3e8e3199e03de0acd0d4590d06f51eebb7dd", default-features = false, features = ["metadata"]} |
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | [features] | 95 | [features] |
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 69848762a..74cc3f8b9 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -449,7 +449,16 @@ fn main() { | |||
| 449 | // ======== | 449 | // ======== |
| 450 | // Generate RccPeripheral impls | 450 | // Generate RccPeripheral impls |
| 451 | 451 | ||
| 452 | let refcounted_peripherals = HashSet::from(["usart", "adc", "can"]); | 452 | // count how many times each xxENR field is used, to enable refcounting if used more than once. |
| 453 | let mut rcc_field_count: HashMap<_, usize> = HashMap::new(); | ||
| 454 | for p in METADATA.peripherals { | ||
| 455 | if let Some(rcc) = &p.rcc { | ||
| 456 | let en = rcc.enable.as_ref().unwrap(); | ||
| 457 | *rcc_field_count.entry((en.register, en.field)).or_insert(0) += 1; | ||
| 458 | } | ||
| 459 | } | ||
| 460 | |||
| 461 | let force_refcount = HashSet::from(["usart"]); | ||
| 453 | let mut refcount_statics = BTreeSet::new(); | 462 | let mut refcount_statics = BTreeSet::new(); |
| 454 | 463 | ||
| 455 | for p in METADATA.peripherals { | 464 | for p in METADATA.peripherals { |
| @@ -487,7 +496,9 @@ fn main() { | |||
| 487 | let en_reg = format_ident!("{}", en.register); | 496 | let en_reg = format_ident!("{}", en.register); |
| 488 | let set_en_field = format_ident!("set_{}", en.field); | 497 | let set_en_field = format_ident!("set_{}", en.field); |
| 489 | 498 | ||
| 490 | let (before_enable, before_disable) = if refcounted_peripherals.contains(ptype) { | 499 | let refcount = |
| 500 | force_refcount.contains(ptype) || *rcc_field_count.get(&(en.register, en.field)).unwrap() > 1; | ||
| 501 | let (before_enable, before_disable) = if refcount { | ||
| 491 | let refcount_static = | 502 | let refcount_static = |
| 492 | format_ident!("{}_{}", en.register.to_ascii_uppercase(), en.field.to_ascii_uppercase()); | 503 | format_ident!("{}_{}", en.register.to_ascii_uppercase(), en.field.to_ascii_uppercase()); |
| 493 | 504 | ||
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 31dedf06e..60f9404c2 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs | |||
| @@ -504,29 +504,6 @@ pub trait DacPin<T: Instance, const C: u8>: crate::gpio::Pin + 'static {} | |||
| 504 | 504 | ||
| 505 | foreach_peripheral!( | 505 | foreach_peripheral!( |
| 506 | (dac, $inst:ident) => { | 506 | (dac, $inst:ident) => { |
| 507 | // H7 uses single bit for both DAC1 and DAC2, this is a hack until a proper fix is implemented | ||
| 508 | #[cfg(any(rcc_h7, rcc_h7rm0433))] | ||
| 509 | impl crate::rcc::sealed::RccPeripheral for peripherals::$inst { | ||
| 510 | fn frequency() -> crate::time::Hertz { | ||
| 511 | critical_section::with(|_| unsafe { crate::rcc::get_freqs().pclk1 }) | ||
| 512 | } | ||
| 513 | |||
| 514 | fn enable_and_reset_with_cs(_cs: critical_section::CriticalSection) { | ||
| 515 | // TODO: Increment refcount? | ||
| 516 | crate::pac::RCC.apb1lrstr().modify(|w| w.set_dac12rst(true)); | ||
| 517 | crate::pac::RCC.apb1lrstr().modify(|w| w.set_dac12rst(false)); | ||
| 518 | crate::pac::RCC.apb1lenr().modify(|w| w.set_dac12en(true)); | ||
| 519 | } | ||
| 520 | |||
| 521 | fn disable_with_cs(_cs: critical_section::CriticalSection) { | ||
| 522 | // TODO: Decrement refcount? | ||
| 523 | crate::pac::RCC.apb1lenr().modify(|w| w.set_dac12en(false)) | ||
| 524 | } | ||
| 525 | } | ||
| 526 | |||
| 527 | #[cfg(any(rcc_h7, rcc_h7rm0433))] | ||
| 528 | impl crate::rcc::RccPeripheral for peripherals::$inst {} | ||
| 529 | |||
| 530 | impl crate::dac::sealed::Instance for peripherals::$inst { | 507 | impl crate::dac::sealed::Instance for peripherals::$inst { |
| 531 | fn regs() -> &'static crate::pac::dac::Dac { | 508 | fn regs() -> &'static crate::pac::dac::Dac { |
| 532 | &crate::pac::$inst | 509 | &crate::pac::$inst |
