From ec6adab465180dd1847bbe6dead51018a134c5bb Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Tue, 11 May 2021 08:32:12 +0300 Subject: [PATCH 1/5] hex size for reserved --- src/generate/peripheral.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index 2d0753b5..158e91fc 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -468,7 +468,7 @@ fn register_or_cluster_block( let pad = region.offset - last_end; if pad != 0 { let name = Ident::new(&format!("_reserved{}", i), span); - let pad = pad as usize; + let pad = util::hex(pad as u64); rbfs.extend(quote! { #name : [u8; #pad], }); @@ -533,7 +533,7 @@ fn register_or_cluster_block( ), span, ); - let pad = (region.end - region.offset) as usize; + let pad = util::hex((region.end - region.offset) as u64); rbfs.extend(quote! { #name: [u8; #pad], }) From 23a2974ffc53fef912cd35f7679d6520bafb67f8 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Tue, 11 May 2021 08:39:03 +0300 Subject: [PATCH 2/5] changelog --- CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99f886f7..2fac9141 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,13 +11,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - MSP430 API for atomically changing register bits, gated behind the `--nightly` flag - New SVD test for `msp430fr2355` - -### Added - - Option `-o`(`--output-path`) let you specify output directory path ### Changed +- `_rererved` fields in `RegisterBlock` now hexidemical usize - options can be set now with `svd2rust.toml` config - option `ignore_groups` for optional disabling #506 - [breaking-change] move `const_generic` from features to options From 3ae0b4fb427aba06f4cec6857bde49c9adfe91d4 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Tue, 11 May 2021 09:49:30 +0300 Subject: [PATCH 3/5] start..end block --- src/generate/peripheral.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index 158e91fc..7cb0e7b3 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -478,11 +478,20 @@ fn register_or_cluster_block( let is_region_a_union = region.is_union(); for reg_block_field in ®ion.rbfs { - let comment = &format!( - "0x{:02x} - {}", - reg_block_field.offset, - util::escape_brackets(util::respace(®_block_field.description).as_ref()), - )[..]; + let comment = if reg_block_field.size > 32 { + format!( + "0x{:02x}..0x{:02x} - {}", + reg_block_field.offset, + reg_block_field.offset + reg_block_field.size / 8, + util::escape_brackets(util::respace(®_block_field.description).as_ref()), + ) + } else { + format!( + "0x{:02x} - {}", + reg_block_field.offset, + util::escape_brackets(util::respace(®_block_field.description).as_ref()), + ) + }; if is_region_a_union { let name = ®_block_field.field.ident; From f067e74fa5abb841da5ead8548a7a6924badc0e2 Mon Sep 17 00:00:00 2001 From: Ralph Loader Date: Mon, 10 May 2021 21:50:14 +1200 Subject: [PATCH 4/5] Be more careful computing the size of an array Cluster. Add changelog entry. --- CHANGELOG.md | 6 ++++++ src/generate/peripheral.rs | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fac9141..98c0448f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Use register iterator from `svd-parser` - rm unneeded `core::convert::` prefix on `From` +### Fixed + +- Padding has been corrected for SVD files containing nested array clusters. + + This showed up on Cypress PSOC and Traveo II CPUs. + ## [v0.18.0] - 2021-04-17 ### Added diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index 7cb0e7b3..9263e536 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -601,9 +601,23 @@ fn expand( Ok(ercs_expanded) } -/// Recursively calculate the size of a cluster. A cluster's size is the maximum -/// end position of its recursive children. +/// Calculate the size of a Cluster. If it is an array, then the dimensions +/// tell us the size of the array. Otherwise, inspect the contents using +/// [cluster_info_size_in_bits]. fn cluster_size_in_bits( + cluster: &Cluster, + defs: &RegisterProperties, + config: &Config, +) -> Result { + match cluster { + Cluster::Single(info) => cluster_info_size_in_bits(info, defs, config), + Cluster::Array(_info, dim) => Ok(dim.dim * dim.dim_increment * BITS_PER_BYTE), + } +} + +/// Recursively calculate the size of a ClusterInfo. A cluster's size is the +/// maximum end position of its recursive children. +fn cluster_info_size_in_bits( info: &ClusterInfo, defs: &RegisterProperties, config: &Config, @@ -641,7 +655,7 @@ fn expand_cluster( let defs = cluster.default_register_properties.derive_from(defs); - let cluster_size = cluster_size_in_bits(cluster, &defs, config) + let cluster_size = cluster_info_size_in_bits(cluster, &defs, config) .with_context(|| format!("Cluster {} has no determinable `size` field", cluster.name))?; match cluster { From d59a264da78e07d235adb479470de0c57ea1c295 Mon Sep 17 00:00:00 2001 From: Ralph Loader Date: Tue, 11 May 2021 06:19:22 +1200 Subject: [PATCH 5/5] Also correct the case, where: * A cluster contains a cluster that ends with a cluster array. * The innermost cluster has a mismatch between the size of the element data and the array dim_increment. --- src/generate/peripheral.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index 9263e536..c758c4d2 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -611,7 +611,18 @@ fn cluster_size_in_bits( ) -> Result { match cluster { Cluster::Single(info) => cluster_info_size_in_bits(info, defs, config), - Cluster::Array(_info, dim) => Ok(dim.dim * dim.dim_increment * BITS_PER_BYTE), + // If the contained array cluster has a mismatch between the + // dimIncrement and the size of the array items, then the array + // will get expanded in expand_cluster below. The overall size + // then ends at the last array entry. + Cluster::Array(info, dim) => { + if dim.dim == 0 { + return Ok(0); // Special case! + } + let last_offset = (dim.dim - 1) * dim.dim_increment * BITS_PER_BYTE; + let last_size = cluster_info_size_in_bits(info, defs, config); + Ok(last_offset + last_size?) + } } }