Update stm32-data, update build scripts for new schema.

This commit is contained in:
Dario Nieuwenhuis 2022-02-07 02:10:12 +01:00
parent a1d6077446
commit de19fe5c05
4 changed files with 87 additions and 69 deletions

@ -1 +1 @@
Subproject commit ffa64b996c53d9551bf5d333016ce17fbe381531 Subproject commit 69ac5bce28972de33b57497454421c6ac862b0ed

View file

@ -1,5 +1,5 @@
use serde::Deserialize; use serde::Deserialize;
use std::collections::{BTreeMap, HashMap}; use std::collections::HashMap;
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct Chip { pub struct Chip {
@ -27,9 +27,15 @@ pub struct MemoryRegion {
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct Core { pub struct Core {
pub name: String, pub name: String,
pub peripherals: BTreeMap<String, Peripheral>, pub peripherals: Vec<Peripheral>,
pub interrupts: BTreeMap<String, u32>, pub interrupts: Vec<Interrupt>,
pub dma_channels: BTreeMap<String, DmaChannel>, pub dma_channels: Vec<DmaChannel>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct Interrupt {
pub name: String,
pub number: u32,
} }
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@ -40,17 +46,24 @@ pub struct Package {
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct Peripheral { pub struct Peripheral {
pub name: String,
pub address: u64, pub address: u64,
#[serde(default)] #[serde(default)]
pub block: Option<String>, pub block: Option<String>,
#[serde(default)] #[serde(default)]
pub rcc: Option<PeripheralRcc>, pub rcc: Option<PeripheralRcc>,
#[serde(default)] #[serde(default)]
pub pins: Vec<Pin>, pub pins: Vec<PeripheralPin>,
#[serde(default)] #[serde(default)]
pub dma_channels: BTreeMap<String, Vec<PeripheralDmaChannel>>, pub dma_channels: Vec<PeripheralDmaChannel>,
#[serde(default)] #[serde(default)]
pub interrupts: BTreeMap<String, String>, pub interrupts: Vec<PeripheralInterrupt>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct PeripheralInterrupt {
pub signal: String,
pub interrupt: String,
} }
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@ -74,7 +87,7 @@ pub struct PeripheralRccRegister {
} }
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct Pin { pub struct PeripheralPin {
pub pin: String, pub pin: String,
pub signal: String, pub signal: String,
pub af: Option<String>, pub af: Option<String>,
@ -82,6 +95,7 @@ pub struct Pin {
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct DmaChannel { pub struct DmaChannel {
pub name: String,
pub dma: String, pub dma: String,
pub channel: u32, pub channel: u32,
pub dmamux: Option<String>, pub dmamux: Option<String>,
@ -90,6 +104,7 @@ pub struct DmaChannel {
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Hash)]
pub struct PeripheralDmaChannel { pub struct PeripheralDmaChannel {
pub signal: String,
pub channel: Option<String>, pub channel: Option<String>,
pub dmamux: Option<String>, pub dmamux: Option<String>,
pub request: Option<u32>, pub request: Option<u32>,

View file

@ -96,8 +96,8 @@ pub fn gen_chip(
}; };
// Load DBGMCU register for chip // Load DBGMCU register for chip
let mut dbgmcu: Option<ir::IR> = core.peripherals.iter().find_map(|(name, p)| { let mut dbgmcu: Option<ir::IR> = core.peripherals.iter().find_map(|p| {
if name == "DBGMCU" { if p.name == "DBGMCU" {
p.block.as_ref().map(|block| { p.block.as_ref().map(|block| {
let bi = BlockInfo::parse(block); let bi = BlockInfo::parse(block);
let dbgmcu_reg_path = options let dbgmcu_reg_path = options
@ -123,7 +123,12 @@ pub fn gen_chip(
let mut dma_channel_counts: BTreeMap<String, u8> = BTreeMap::new(); let mut dma_channel_counts: BTreeMap<String, u8> = BTreeMap::new();
let mut dbgmcu_table: Vec<Vec<String>> = Vec::new(); let mut dbgmcu_table: Vec<Vec<String>> = Vec::new();
let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address as u32; let gpio_base = core
.peripherals
.iter()
.find(|p| p.name == "GPIOA")
.unwrap()
.address as u32;
let gpio_stride = 0x400; let gpio_stride = 0x400;
let number_suffix_re = Regex::new("^(.*?)[0-9]*$").unwrap(); let number_suffix_re = Regex::new("^(.*?)[0-9]*$").unwrap();
@ -139,15 +144,15 @@ pub fn gen_chip(
} }
} }
for (name, p) in &core.peripherals { for p in &core.peripherals {
let captures = number_suffix_re.captures(&name).unwrap(); let captures = number_suffix_re.captures(&p.name).unwrap();
let root_peri_name = captures.get(1).unwrap().as_str().to_string(); let root_peri_name = captures.get(1).unwrap().as_str().to_string();
peripheral_counts.insert( peripheral_counts.insert(
root_peri_name.clone(), root_peri_name.clone(),
peripheral_counts.get(&root_peri_name).map_or(1, |v| v + 1), peripheral_counts.get(&root_peri_name).map_or(1, |v| v + 1),
); );
let mut ir_peri = ir::Peripheral { let mut ir_peri = ir::Peripheral {
name: name.clone(), name: p.name.clone(),
array: None, array: None,
base_address: p.address, base_address: p.address,
block: None, block: None,
@ -165,7 +170,7 @@ pub fn gen_chip(
for pin in &p.pins { for pin in &p.pins {
let mut row = Vec::new(); let mut row = Vec::new();
row.push(name.clone()); row.push(p.name.clone());
row.push(bi.module.clone()); row.push(bi.module.clone());
row.push(bi.block.clone()); row.push(bi.block.clone());
row.push(pin.pin.clone()); row.push(pin.pin.clone());
@ -176,32 +181,31 @@ pub fn gen_chip(
peripheral_pins_table.push(row); peripheral_pins_table.push(row);
} }
for (signal, irq_name) in &p.interrupts { for irq in &p.interrupts {
let mut row = Vec::new(); let mut row = Vec::new();
row.push(name.clone()); row.push(p.name.clone());
row.push(bi.module.clone()); row.push(bi.module.clone());
row.push(bi.block.clone()); row.push(bi.block.clone());
row.push(signal.clone()); row.push(irq.signal.clone());
row.push(irq_name.to_ascii_uppercase()); row.push(irq.interrupt.to_ascii_uppercase());
interrupt_table.push(row) interrupt_table.push(row)
} }
for (request, dma_channels) in &p.dma_channels { for ch in &p.dma_channels {
for channel in dma_channels.iter() {
let mut row = Vec::new(); let mut row = Vec::new();
row.push(name.clone()); row.push(p.name.clone());
row.push(bi.module.clone()); row.push(bi.module.clone());
row.push(bi.block.clone()); row.push(bi.block.clone());
row.push(request.clone()); row.push(ch.signal.clone());
row.push(if let Some(channel) = &channel.channel { row.push(if let Some(channel) = &ch.channel {
format!("{{channel: {}}}", channel) format!("{{channel: {}}}", channel)
} else if let Some(dmamux) = &channel.dmamux { } else if let Some(dmamux) = &ch.dmamux {
format!("{{dmamux: {}}}", dmamux) format!("{{dmamux: {}}}", dmamux)
} else { } else {
unreachable!(); unreachable!();
}); });
row.push(if let Some(request) = channel.request { row.push(if let Some(request) = ch.request {
request.to_string() request.to_string()
} else { } else {
"()".to_string() "()".to_string()
@ -215,11 +219,10 @@ pub fn gen_chip(
peripheral_dma_channels_table.push(row); peripheral_dma_channels_table.push(row);
} }
} }
}
let mut peripheral_row = Vec::new(); let mut peripheral_row = Vec::new();
peripheral_row.push(bi.module.clone()); peripheral_row.push(bi.module.clone());
peripheral_row.push(name.clone()); peripheral_row.push(p.name.clone());
peripherals_table.push(peripheral_row); peripherals_table.push(peripheral_row);
if let Some(old_version) = if let Some(old_version) =
@ -236,15 +239,15 @@ pub fn gen_chip(
match bi.module.as_str() { match bi.module.as_str() {
"gpio" => { "gpio" => {
let port_letter = name.chars().skip(4).next().unwrap(); let port_letter = p.name.chars().skip(4).next().unwrap();
assert_eq!(0, (p.address as u32 - gpio_base) % gpio_stride); assert_eq!(0, (p.address as u32 - gpio_base) % gpio_stride);
let port_num = (p.address as u32 - gpio_base) / gpio_stride; let port_num = (p.address as u32 - gpio_base) / gpio_stride;
for pin_num in 0..16 { for pin_num in 0u32..16 {
let pin_name = format!("P{}{}", port_letter, pin_num); let pin_name = format!("P{}{}", port_letter, pin_num);
pin_table.push(vec![ pin_table.push(vec![
pin_name.clone(), pin_name.clone(),
name.clone(), p.name.clone(),
port_num.to_string(), port_num.to_string(),
pin_num.to_string(), pin_num.to_string(),
format!("EXTI{}", pin_num), format!("EXTI{}", pin_num),
@ -256,12 +259,12 @@ pub fn gen_chip(
if let Some(rcc) = &p.rcc { if let Some(rcc) = &p.rcc {
let mut clock = rcc.clock.to_ascii_lowercase(); let mut clock = rcc.clock.to_ascii_lowercase();
if name.starts_with("TIM") { if p.name.starts_with("TIM") {
clock = format!("{}_tim", clock) clock = format!("{}_tim", clock)
} }
let mut row = Vec::new(); let mut row = Vec::new();
row.push(name.clone()); row.push(p.name.clone());
row.push(bi.module.clone()); row.push(bi.module.clone());
row.push(bi.block.clone()); row.push(bi.block.clone());
row.push(clock); row.push(clock);
@ -286,17 +289,17 @@ pub fn gen_chip(
dev.peripherals.push(ir_peri); dev.peripherals.push(ir_peri);
} }
for (id, channel_info) in &core.dma_channels { for ch in &core.dma_channels {
let mut row = Vec::new(); let mut row = Vec::new();
let dma_peri = core.peripherals.get(&channel_info.dma).unwrap(); let dma_peri = core.peripherals.iter().find(|p| p.name == ch.dma).unwrap();
let bi = BlockInfo::parse(dma_peri.block.as_ref().unwrap()); let bi = BlockInfo::parse(dma_peri.block.as_ref().unwrap());
row.push(id.clone()); row.push(ch.name.clone());
row.push(channel_info.dma.clone()); row.push(ch.dma.clone());
row.push(bi.module.clone()); row.push(bi.module.clone());
row.push(channel_info.channel.to_string()); row.push(ch.channel.to_string());
if let Some(dmamux) = &channel_info.dmamux { if let Some(dmamux) = &ch.dmamux {
let dmamux_channel = channel_info.dmamux_channel.unwrap(); let dmamux_channel = ch.dmamux_channel.unwrap();
row.push(format!( row.push(format!(
"{{dmamux: {}, dmamux_channel: {}}}", "{{dmamux: {}, dmamux_channel: {}}}",
dmamux, dmamux_channel dmamux, dmamux_channel
@ -307,21 +310,21 @@ pub fn gen_chip(
dma_channels_table.push(row); dma_channels_table.push(row);
let dma_peri_name = channel_info.dma.clone(); let dma_peri_name = ch.dma.clone();
dma_channel_counts.insert( dma_channel_counts.insert(
dma_peri_name.clone(), dma_peri_name.clone(),
dma_channel_counts.get(&dma_peri_name).map_or(1, |v| v + 1), dma_channel_counts.get(&dma_peri_name).map_or(1, |v| v + 1),
); );
} }
for (name, &num) in &core.interrupts { for irq in &core.interrupts {
dev.interrupts.push(ir::Interrupt { dev.interrupts.push(ir::Interrupt {
name: name.clone(), name: irq.name.clone(),
description: None, description: None,
value: num, value: irq.number,
}); });
let name = name.to_ascii_uppercase(); let name = irq.name.to_ascii_uppercase();
interrupt_table.push(vec![name.clone()]); interrupt_table.push(vec![name.clone()]);
@ -383,11 +386,11 @@ pub fn gen_chip(
let mut device_x = String::new(); let mut device_x = String::new();
for (name, _) in &core.interrupts { for irq in &core.interrupts {
write!( write!(
&mut device_x, &mut device_x,
"PROVIDE({} = DefaultHandler);\n", "PROVIDE({} = DefaultHandler);\n",
name.to_ascii_uppercase() irq.name.to_ascii_uppercase()
) )
.unwrap(); .unwrap();
} }
@ -441,7 +444,7 @@ fn load_chip(options: &Options, name: &str) -> Chip {
let chip_path = options let chip_path = options
.data_dir .data_dir
.join("chips") .join("chips")
.join(&format!("{}.yaml", name)); .join(&format!("{}.json", name));
let chip = fs::read(chip_path).expect(&format!("Could not load chip {}", name)); let chip = fs::read(chip_path).expect(&format!("Could not load chip {}", name));
serde_yaml::from_slice(&chip).unwrap() serde_yaml::from_slice(&chip).unwrap()
} }

View file

@ -16,9 +16,9 @@ fn main() {
std::fs::read_dir(data_dir.join("chips")) 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(".json"))
.filter(|s| !s.starts_with("STM32GBK")) // cursed weird STM32G4 .filter(|s| !s.starts_with("STM32GBK")) // cursed weird STM32G4
.map(|s| s.strip_suffix(".yaml").unwrap().to_string()) .map(|s| s.strip_suffix(".json").unwrap().to_string())
.collect() .collect()
} }
_ => panic!("usage: stm32-metapac-gen [chip?]"), _ => panic!("usage: stm32-metapac-gen [chip?]"),