From e97eeeffbc90c576a121d19ccd3f2235306cc005 Mon Sep 17 00:00:00 2001 From: Morten Engelhardt Olsen Date: Mon, 16 Mar 2026 08:30:42 -0700 Subject: [PATCH] Change parsing of the CPU block to have optional mpuPresent and fpuPresent elements Per the SVD schema; these 2 elements are actually optional. However the documentation page for the schema incorrectly claims them to be required. Modify the parser to allow these to be optional when parsing. Fixes #300 --- svd-parser/src/cpu.rs | 14 ++++++++++++-- tests/src/cpu.rs | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/svd-parser/src/cpu.rs b/svd-parser/src/cpu.rs index e5430da..8602d2b 100644 --- a/svd-parser/src/cpu.rs +++ b/svd-parser/src/cpu.rs @@ -20,12 +20,22 @@ impl Parse for Cpu { _ => false, }; + let has_mpu_present = match tree.get_child_bool("mpuPresent") { + Ok(v) => v, + _ => false, + }; + + let has_fpu_present = match tree.get_child_bool("fpuPresent") { + Ok(v) => v, + _ => false, + }; + Cpu::builder() .name(tree.get_child_text("name")?) .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")?) + .mpu_present(has_mpu_present) + .fpu_present(has_fpu_present) .fpu_double_precision(optional::("fpuDP", tree, &())?) .dsp_present(optional::("dspPresent", tree, &())?) .icache_present(optional::("icachePresent", tree, &())?) diff --git a/tests/src/cpu.rs b/tests/src/cpu.rs index 8ee5348..6ed93c8 100644 --- a/tests/src/cpu.rs +++ b/tests/src/cpu.rs @@ -16,7 +16,7 @@ fn decode_encode() { .unwrap(), " - EFM32JG12B500F512GM48 + EFM32JG12B500F512GM48 5.1.1 little true @@ -27,7 +27,7 @@ fn decode_encode() { ", " - EFM32JG12B500F512GM48 + EFM32JG12B500F512GM48 5.1.1 little true