stm32-metapac: assume RCC is always present
This commit is contained in:
parent
f3de443ee7
commit
dd62790f36
@ -1,4 +1,5 @@
|
|||||||
use chiptool::generate::CommonModule;
|
use chiptool::generate::CommonModule;
|
||||||
|
use chiptool::ir::IR;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||||
@ -273,19 +274,18 @@ pub fn gen(options: Options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Load RCC register for chip
|
// Load RCC register for chip
|
||||||
let rcc = core.peripherals.iter().find_map(|(name, p)| {
|
let (_, rcc) = core
|
||||||
if name == "RCC" {
|
.peripherals
|
||||||
p.block.as_ref().map(|block| {
|
.iter()
|
||||||
let bi = BlockInfo::parse(block);
|
.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
|
let rcc_reg_path = data_dir
|
||||||
.join("registers")
|
.join("registers")
|
||||||
.join(&format!("{}_{}.yaml", bi.module, bi.version));
|
.join(&format!("{}_{}.yaml", bi.module, bi.version));
|
||||||
serde_yaml::from_reader(File::open(rcc_reg_path).unwrap()).unwrap()
|
let rcc: IR = serde_yaml::from_reader(File::open(rcc_reg_path).unwrap()).unwrap();
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new();
|
let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new();
|
||||||
let mut pin_table: Vec<Vec<String>> = Vec::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
|
// 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.
|
// 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));
|
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);
|
dev.peripherals.push(ir_peri);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::env::args;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use stm32_metapac_gen::*;
|
use stm32_metapac_gen::*;
|
||||||
|
|
||||||
@ -5,13 +6,24 @@ fn main() {
|
|||||||
let out_dir = PathBuf::from("out");
|
let out_dir = PathBuf::from("out");
|
||||||
let data_dir = PathBuf::from("../stm32-data/data");
|
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()
|
.unwrap()
|
||||||
.filter_map(|res| res.unwrap().file_name().to_str().map(|s| s.to_string()))
|
.filter_map(|res| res.unwrap().file_name().to_str().map(|s| s.to_string()))
|
||||||
.filter(|s| s.ends_with(".yaml"))
|
.filter(|s| s.ends_with(".yaml"))
|
||||||
.filter(|s| !s.starts_with("STM32L1")) // cursed gpio stride
|
.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())
|
.map(|s| s.strip_suffix(".yaml").unwrap().to_string())
|
||||||
.collect();
|
.collect()
|
||||||
|
}
|
||||||
|
_ => panic!("usage: stm32-metapac-gen [chip?]"),
|
||||||
|
};
|
||||||
|
|
||||||
gen(Options {
|
gen(Options {
|
||||||
out_dir,
|
out_dir,
|
||||||
|
Loading…
Reference in New Issue
Block a user