From 4e47b15daf5ac739fa9da12f9918e3b01eed3ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Fri, 30 Jul 2021 14:30:32 +0200 Subject: Ignore the clock number for enable bit search The number has different meanings depending on family: stm32f0: RCC_APB2ENR - APB peripheral clock enable register 2 CLOCK: APB1 stm32f4: RCC_APB2ENR - RCC APB2 peripheral clock enable register CLOCK: APB2 Ignore the clock number and search all registers for a matching enable bit. --- stm32-metapac-gen/src/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 8a2698d8..d9ab92ee 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs @@ -441,21 +441,31 @@ pub fn gen(options: Options) { }; if let Some(clock_prefix) = clock_prefix { + // Ignore the numbers in clock name when searching for enable bits because clock + // names do not map cleanly to regsiter names. + // Example: + // stm32f0: RCC_APB2ENR - APB peripheral clock enable register 2 CLOCK: APB1 + // stm32f4: RCC_APB2ENR - RCC APB2 peripheral clock enable register CLOCK: APB2 + // + // Search for the enable bit in all available registers to support the stm32f0 case. + let search_clock_prefix = clock_prefix.trim_end_matches(char::is_numeric); + // Workaround for clock registers being split on some chip families. Assume fields are // named after peripheral and look for first field matching and use that register. - let mut en = find_reg_for_field(&rcc, clock_prefix, &format!("{}EN", name)); + let mut en = + find_reg_for_field(&rcc, search_clock_prefix, &format!("{}EN", name)); let mut rst = - find_reg_for_field(&rcc, clock_prefix, &format!("{}RST", name)); + find_reg_for_field(&rcc, search_clock_prefix, &format!("{}RST", name)); if en.is_none() && name.ends_with("1") { en = find_reg_for_field( &rcc, - clock_prefix, + search_clock_prefix, &format!("{}EN", &name[..name.len() - 1]), ); rst = find_reg_for_field( &rcc, - clock_prefix, + search_clock_prefix, &format!("{}RST", &name[..name.len() - 1]), ); } -- cgit v1.2.3