Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions mspm0-data-gen/src/generate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use std::{borrow::Cow, cmp::Ordering, collections::{BTreeMap, BTreeSet}, fs, sync::LazyLock};
use std::{
borrow::Cow,
cmp::Ordering,
collections::{BTreeMap, BTreeSet},
fs,
sync::LazyLock,
};

use anyhow::{anyhow, bail, ensure, Context};
use mspm0_data_types::{
Expand Down Expand Up @@ -195,8 +201,7 @@ fn generate_peripherals2(
LazyLock::new(|| Regex::new(r"(?m)^P(?<bank>[A-Z])\d+").unwrap());
static DMA_CHANNEL: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"DMA_CH(?<channel>\d+)").unwrap());
static USB_EP: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"USBFS(\d+)_EP(\w+)").unwrap());
static USB_EP: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"USBFS(\d+)_EP(\w+)").unwrap());

let mut peripherals = BTreeMap::new();

Expand Down Expand Up @@ -255,11 +260,7 @@ fn generate_peripherals2(
// IWDT technically exists on G151x and G351x, but the SDK and datasheets do not define the address for IWDT.
//
// To prevent issues, we will only consider IWDT to exist on chips which define an address.
if name == "IWDT" && header
.peripheral_addresses
.get(&name)
.is_none()
{
if name == "IWDT" && header.peripheral_addresses.get(&name).is_none() {
continue;
}

Expand Down
12 changes: 10 additions & 2 deletions mspm0-data-gen/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,20 @@ fn pin_names(chip: &Chip, name: &str) -> anyhow::Result<()> {
}

fn gpio_no_duplicates(chip: &Chip, name: &str) -> anyhow::Result<()> {
for (_, peripheral) in chip.peripherals.iter().filter(|(name, _)| name.starts_with("GPIO")) {
for (_, peripheral) in chip
.peripherals
.iter()
.filter(|(name, _)| name.starts_with("GPIO"))
{
let mut signals = HashSet::new();

for pin in peripheral.pins.iter() {
if !signals.insert(&pin.pin) {
bail!("{name}: {} contains multiple pins of {}", peripheral.name, pin.pin);
bail!(
"{name}: {} contains multiple pins of {}",
peripheral.name,
pin.pin
);
}
}
}
Expand Down
23 changes: 20 additions & 3 deletions mspm0-metapac-gen/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn peripherals(chip: &Chip, package: &Package) -> TokenStream {
let mut peripherals = Vec::<TokenStream>::new();

for peri in chip.peripherals.values() {
if let Some(peri) = generate_peripheral(peri, &pins) {
if let Some(peri) = generate_peripheral(peri, &pins, package) {
peripherals.push(peri);
}
}
Expand Down Expand Up @@ -143,12 +143,13 @@ pub fn interrupt_groups(chip: &Chip) -> TokenStream {
}

fn skip_peripheral(ty: PeripheralType) -> bool {
matches!(ty, PeripheralType::Unknown | PeripheralType::Sysctl)
matches!(ty, PeripheralType::Unknown)
}

fn generate_peripheral(
peripheral: &Peripheral,
available_pins: &HashSet<String>,
package: &Package,
) -> Option<TokenStream> {
// Exclude peripherals that don't really exist as singletons.
if skip_peripheral(peripheral.ty) {
Expand All @@ -172,7 +173,23 @@ fn generate_peripheral(
None => quote! { None },
};

if available_pins.contains(name) {
if available_pins.contains(name) || name == "NRST" {
// If NRST is being used, figure out what pin it truly maps to.
let name = if name == "NRST" {
// Some packages share a GPIO with NRST.
let shared_pin = package
.pins
.iter()
.find(|pin| pin.signals.iter().any(|s| s == "NRST") && pin.signals.len() > 1);

match shared_pin {
Some(pin) => pin.signals.iter().find(|s| **s != "NRST").unwrap(),
None => name,
}
} else {
name
};

pins.push(quote! {
PeripheralPin {
pin: #name,
Expand Down