diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-02-01 23:15:17 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-02-01 23:15:17 +0100 |
| commit | e7d1119750dff876e76adbb04f57ac274e913772 (patch) | |
| tree | f89d2cd0548a0994e554b5bfa89c6ced9115456b | |
| parent | b7bc31e51a6c6be658acc9f09bed41b94ea57623 (diff) | |
stm32: automatically use refcounting for rcc bits used multiple times.
| -rw-r--r-- | embassy-stm32/build.rs | 15 |
1 files changed, 13 insertions, 2 deletions
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 | ||
