diff --git a/stm32-data-gen/src/rcc.rs b/stm32-data-gen/src/rcc.rs index 0b00339..b0b00f6 100644 --- a/stm32-data-gen/src/rcc.rs +++ b/stm32-data-gen/src/rcc.rs @@ -6,7 +6,7 @@ use std::hash::Hash; use anyhow::{anyhow, Ok}; use chiptool::ir::{BlockItemInner, Enum}; use stm32_data_serde::chip::core::peripheral; -use stm32_data_serde::chip::core::peripheral::rcc::Mux; +use stm32_data_serde::chip::core::peripheral::rcc::{Mux, StopMode}; use crate::regex; use crate::registers::Registers; @@ -245,6 +245,13 @@ impl PeripheralToClock { for field in &body.fields { if let Some(peri) = field.name.strip_suffix("EN") { let peri = if peri == "RTCAPB" { "RTC" } else { peri }; + let stop_mode = if peri == "RTC" { + StopMode::Standby + } else if peri.starts_with("LP") { + StopMode::Stop2 + } else { + StopMode::Stop1 + }; // Timers are a bit special, they may have a x2 freq let peri_clock = { @@ -280,6 +287,7 @@ impl PeripheralToClock { register: reg.to_ascii_lowercase(), field: field.name.to_ascii_lowercase(), }, + stop_mode, reset, mux, }); diff --git a/stm32-data-serde/src/lib.rs b/stm32-data-serde/src/lib.rs index ba07b9c..c82633c 100644 --- a/stm32-data-serde/src/lib.rs +++ b/stm32-data-serde/src/lib.rs @@ -10,6 +10,10 @@ macro_rules! regex { }}; } +fn is_default(variant: &T) -> bool { + *variant == T::default() +} + #[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] pub struct Chip { pub name: String, @@ -116,6 +120,8 @@ pub mod chip { pub reset: Option, #[serde(skip_serializing_if = "Option::is_none")] pub mux: Option, + #[serde(default, skip_serializing_if = "crate::is_default")] + pub stop_mode: rcc::StopMode, } pub mod rcc { @@ -138,6 +144,14 @@ pub mod chip { pub register: String, pub field: String, } + + #[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize, Default)] + pub enum StopMode { + #[default] + Stop1, // Peripheral prevents chip from entering Stop1 + Stop2, // Peripheral prevents chip from entering Stop2 + Standby, // Peripheral does not prevent chip from entering Stop + } } #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] diff --git a/stm32-metapac-gen/res/src/metadata.rs b/stm32-metapac-gen/res/src/metadata.rs index e468451..a1e028a 100644 --- a/stm32-metapac-gen/res/src/metadata.rs +++ b/stm32-metapac-gen/res/src/metadata.rs @@ -182,6 +182,7 @@ pub struct PeripheralRcc { pub enable: Option, pub reset: Option, pub mux: Option, + pub stop_mode: StopMode, } #[derive(Debug, Eq, PartialEq, Clone)] @@ -190,6 +191,14 @@ pub struct PeripheralRccRegister { pub field: &'static str, } +#[derive(Debug, Eq, PartialEq, Clone, Default)] +pub enum StopMode { + #[default] + Stop1, // Peripheral prevents chip from entering Stop1 + Stop2, // Peripheral prevents chip from entering Stop2 + Standby, // Peripheral does not prevent chip from entering Stop +} + #[derive(Debug, Eq, PartialEq, Clone)] pub struct PeripheralPin { pub pin: &'static str, diff --git a/stm32-metapac-gen/src/data.rs b/stm32-metapac-gen/src/data.rs index c7363f1..b85f3cf 100644 --- a/stm32-metapac-gen/src/data.rs +++ b/stm32-metapac-gen/src/data.rs @@ -325,6 +325,8 @@ pub struct PeripheralRcc { pub reset: Option, #[serde(default)] pub mux: Option, + #[serde(default)] + pub stop_mode: StopMode, } #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] @@ -333,6 +335,14 @@ pub struct PeripheralRccRegister { pub field: String, } +#[derive(EnumDebug, Eq, PartialEq, Clone, Deserialize, Default)] +pub enum StopMode { + #[default] + Stop1, // Peripheral prevents chip from entering Stop1 + Stop2, // Peripheral prevents chip from entering Stop2 + Standby, // Peripheral does not prevent chip from entering Stop +} + #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] pub struct PeripheralPin { pub pin: String,