From 43f95cec2f7ec987c6e7e2c3613bcbb8d4f9efdf Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 15 Jan 2024 00:37:26 +0100 Subject: [PATCH 1/4] Remove range checks to workaround broken ST SVDs --- svd-rs/src/enumeratedvalue.rs | 5 +---- svd-rs/src/writeconstraint.rs | 8 -------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/svd-rs/src/enumeratedvalue.rs b/svd-rs/src/enumeratedvalue.rs index e9f14a61..87ed9e25 100644 --- a/svd-rs/src/enumeratedvalue.rs +++ b/svd-rs/src/enumeratedvalue.rs @@ -146,10 +146,7 @@ impl EnumeratedValue { } } pub(crate) fn check_range(&self, range: &core::ops::Range) -> Result<(), SvdError> { - match &self.value { - Some(x) if !range.contains(x) => Err(Error::OutOfRange(*x, range.clone()).into()), - _ => Ok(()), - } + Ok(()) } } diff --git a/svd-rs/src/writeconstraint.rs b/svd-rs/src/writeconstraint.rs index aaf13775..e93560e4 100644 --- a/svd-rs/src/writeconstraint.rs +++ b/svd-rs/src/writeconstraint.rs @@ -41,14 +41,6 @@ pub enum Error { impl WriteConstraintRange { pub(crate) fn check_range(&self, range: core::ops::Range) -> Result<(), SvdError> { - if self.min > self.max { - return Err(Error::ReversedRange(self.min, self.max).into()); - } - for v in [&self.min, &self.max] { - if !range.contains(v) { - return Err(Error::OutOfRange(*v, range).into()); - } - } Ok(()) } } From d85c090d065cbe2299b32a52a4c6c813156f5a87 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 28 Feb 2025 01:17:47 +0200 Subject: [PATCH 2/4] Make fpu-present optional fpuPresent is an optional parameter in the CPU section. Encode it as such in order to parse more SVD files. Signed-off-by: Felipe Balbi --- svd-encoder/src/cpu.rs | 4 +++- svd-parser/src/cpu.rs | 2 +- svd-rs/Cargo.toml | 2 +- svd-rs/src/cpu.rs | 24 +++++++++++++++--------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/svd-encoder/src/cpu.rs b/svd-encoder/src/cpu.rs index ada46cf7..6067ab18 100644 --- a/svd-encoder/src/cpu.rs +++ b/svd-encoder/src/cpu.rs @@ -10,8 +10,10 @@ impl Encode for Cpu { new_node("revision", self.revision.clone()), self.endian.encode_node()?, new_node("mpuPresent", format!("{}", self.mpu_present)), - new_node("fpuPresent", format!("{}", self.fpu_present)), ]; + if let Some(v) = &self.fpu_present { + children.push(new_node("fpuPresent", format!("{}", v))); + } if let Some(v) = &self.fpu_double_precision { children.push(new_node("fpuDP", format!("{}", v))); } diff --git a/svd-parser/src/cpu.rs b/svd-parser/src/cpu.rs index 8725627e..9a8deee4 100644 --- a/svd-parser/src/cpu.rs +++ b/svd-parser/src/cpu.rs @@ -17,7 +17,7 @@ impl Parse for Cpu { .revision(tree.get_child_text("revision")?) .endian(Endian::parse(&tree.get_child_elem("endian")?, config)?) .mpu_present(tree.get_child_bool("mpuPresent")?) - .fpu_present(tree.get_child_bool("fpuPresent")?) + .fpu_present(optional::("fpuPresent", tree, &())?) .fpu_double_precision(optional::("fpuDP", tree, &())?) .dsp_present(optional::("dspPresent", tree, &())?) .icache_present(optional::("icachePresent", tree, &())?) diff --git a/svd-rs/Cargo.toml b/svd-rs/Cargo.toml index 8f3e9b94..150ec92f 100644 --- a/svd-rs/Cargo.toml +++ b/svd-rs/Cargo.toml @@ -20,7 +20,7 @@ derive-from = [] thiserror = "1.0.31" [dependencies.regex] -version = "=1.9.6" +version = "1.11.1" [dependencies.once_cell] version = "1.17.2" diff --git a/svd-rs/src/cpu.rs b/svd-rs/src/cpu.rs index b7348c83..39713899 100644 --- a/svd-rs/src/cpu.rs +++ b/svd-rs/src/cpu.rs @@ -21,7 +21,15 @@ pub struct Cpu { pub mpu_present: bool, /// Indicate whether the processor is equipped with a hardware floating point unit (FPU) - pub fpu_present: bool, + #[cfg_attr( + feature = "serde", + serde( + default, + skip_serializing_if = "Option::is_none", + rename = "fpuPresent" + ) + )] + pub fpu_present: Option, /// Indicate whether the processor is equipped with a double precision floating point unit. /// This element is valid only when `fpu_present` is set to `true` @@ -126,7 +134,7 @@ impl From for CpuBuilder { revision: Some(c.revision), endian: Some(c.endian), mpu_present: Some(c.mpu_present), - fpu_present: Some(c.fpu_present), + fpu_present: c.fpu_present, fpu_double_precision: c.fpu_double_precision, dsp_present: c.dsp_present, icache_present: c.icache_present, @@ -164,8 +172,8 @@ impl CpuBuilder { self } /// Set the fpu_present of the cpu. - pub fn fpu_present(mut self, value: bool) -> Self { - self.fpu_present = Some(value); + pub fn fpu_present(mut self, value: Option) -> Self { + self.fpu_present = value; self } /// Set the fpu_double_precision of the cpu. @@ -238,9 +246,7 @@ impl CpuBuilder { mpu_present: self .mpu_present .ok_or_else(|| BuildError::Uninitialized("mpu_present".to_string()))?, - fpu_present: self - .fpu_present - .ok_or_else(|| BuildError::Uninitialized("fpu_present".to_string()))?, + fpu_present: self.fpu_present, fpu_double_precision: self.fpu_double_precision, dsp_present: self.dsp_present, icache_present: self.icache_present, @@ -281,8 +287,8 @@ impl Cpu { if let Some(mpu_present) = builder.mpu_present { self.mpu_present = mpu_present; } - if let Some(fpu_present) = builder.fpu_present { - self.fpu_present = fpu_present; + if builder.fpu_present.is_some() { + self.fpu_present = builder.fpu_present; } if builder.fpu_double_precision.is_some() { self.fpu_double_precision = builder.fpu_double_precision; From 6e5d0bd006de5b0b8d366447de5c08940a3e9451 Mon Sep 17 00:00:00 2001 From: Dominik Boehi Date: Tue, 24 Jun 2025 06:19:32 +0200 Subject: [PATCH 3/4] Fix Nordic svd parsing again --- svd-rs/src/access.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/svd-rs/src/access.rs b/svd-rs/src/access.rs index 09a60ba1..6676a63a 100644 --- a/svd-rs/src/access.rs +++ b/svd-rs/src/access.rs @@ -48,12 +48,12 @@ impl Default for Access { impl Access { /// Parse a string into an [`Access`] value, returning [`Option::None`] if the string is not valid. pub fn parse_str(s: &str) -> Option { - match s { + match s.to_lowercase().as_str() { "read-only" => Some(Self::ReadOnly), "read-write" => Some(Self::ReadWrite), - "read-writeOnce" => Some(Self::ReadWriteOnce), + "read-writeonce" => Some(Self::ReadWriteOnce), "write-only" => Some(Self::WriteOnly), - "writeOnce" => Some(Self::WriteOnce), + "writeonce" => Some(Self::WriteOnce), _ => None, } } From 978eba612e370c5b719b620d37b64a2877bcf8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20G=C3=B3rski?= Date: Mon, 15 Sep 2025 16:39:53 +0200 Subject: [PATCH 4/4] Make the URL for the submodule valid CMSIS-SVD repository was moved plus git:// makes the git command hang. [Recent change](https://github.com/NixOS/nixpkgs/commit/5cd869caa4ea1bf1bde71731ecc96b24e1bdcc2d) in the Rust platform in `NixOS/nixpkgs` prevents a user from packaging a Rust program using crates from this repository to be used as dependencies as it forces their submodules to be checked out, regardless of the `submodule.*.update` setting. --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 9a8da720..97a6ce44 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "cmsis-svd"] path = cmsis-svd - url = git://github.com/posborne/cmsis-svd.git + url = https://github.com/cmsis-svd/cmsis-svd.git update = none