stm32-metapac: assume RCC is always present

This commit is contained in:
Dario Nieuwenhuis 2021-08-19 22:16:27 +02:00
parent f3de443ee7
commit dd62790f36
2 changed files with 95 additions and 85 deletions

View File

@ -1,4 +1,5 @@
use chiptool::generate::CommonModule;
use chiptool::ir::IR;
use regex::Regex;
use serde::Deserialize;
use std::collections::{BTreeMap, HashMap, HashSet};
@ -273,19 +274,18 @@ pub fn gen(options: Options) {
});
// Load RCC register for chip
let rcc = core.peripherals.iter().find_map(|(name, p)| {
if name == "RCC" {
p.block.as_ref().map(|block| {
let bi = BlockInfo::parse(block);
let (_, rcc) = core
.peripherals
.iter()
.find(|(name, _)| name == &"RCC")
.expect("RCC peripheral missing");
let rcc_block = rcc.block.as_ref().expect("RCC peripheral has no block");
let bi = BlockInfo::parse(&rcc_block);
let rcc_reg_path = data_dir
.join("registers")
.join(&format!("{}_{}.yaml", bi.module, bi.version));
serde_yaml::from_reader(File::open(rcc_reg_path).unwrap()).unwrap()
})
} else {
None
}
});
let rcc: IR = serde_yaml::from_reader(File::open(rcc_reg_path).unwrap()).unwrap();
let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new();
let mut pin_table: Vec<Vec<String>> = Vec::new();
@ -424,7 +424,6 @@ pub fn gen(options: Options) {
_ => {}
}
if let Some(rcc) = &rcc {
// 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, "^.+ENR\\d*$", &format!("{}EN", name));
@ -493,7 +492,6 @@ pub fn gen(options: Options) {
}
}
}
}
dev.peripherals.push(ir_peri);
}

View File

@ -1,3 +1,4 @@
use std::env::args;
use std::path::PathBuf;
use stm32_metapac_gen::*;
@ -5,13 +6,24 @@ fn main() {
let out_dir = PathBuf::from("out");
let data_dir = PathBuf::from("../stm32-data/data");
let chips = std::fs::read_dir(data_dir.join("chips"))
let args: Vec<String> = args().collect();
let chips = match &args[..] {
[_, chip] => {
vec![chip.clone()]
}
[_] => {
std::fs::read_dir(data_dir.join("chips"))
.unwrap()
.filter_map(|res| res.unwrap().file_name().to_str().map(|s| s.to_string()))
.filter(|s| s.ends_with(".yaml"))
.filter(|s| !s.starts_with("STM32L1")) // cursed gpio stride
.filter(|s| !s.starts_with("STM32GBK")) // cursed weird STM32G4
.map(|s| s.strip_suffix(".yaml").unwrap().to_string())
.collect();
.collect()
}
_ => panic!("usage: stm32-metapac-gen [chip?]"),
};
gen(Options {
out_dir,