Skip to content

Commit f067e74

Browse files
committed
Be more careful computing the size of an array Cluster.
Add changelog entry.
1 parent 3ae0b4f commit f067e74

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2323
- Use register iterator from `svd-parser`
2424
- rm unneeded `core::convert::` prefix on `From`
2525

26+
### Fixed
27+
28+
- Padding has been corrected for SVD files containing nested array clusters.
29+
30+
This showed up on Cypress PSOC and Traveo II CPUs.
31+
2632
## [v0.18.0] - 2021-04-17
2733

2834
### Added

src/generate/peripheral.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,23 @@ fn expand(
601601
Ok(ercs_expanded)
602602
}
603603

604-
/// Recursively calculate the size of a cluster. A cluster's size is the maximum
605-
/// end position of its recursive children.
604+
/// Calculate the size of a Cluster. If it is an array, then the dimensions
605+
/// tell us the size of the array. Otherwise, inspect the contents using
606+
/// [cluster_info_size_in_bits].
606607
fn cluster_size_in_bits(
608+
cluster: &Cluster,
609+
defs: &RegisterProperties,
610+
config: &Config,
611+
) -> Result<u32> {
612+
match cluster {
613+
Cluster::Single(info) => cluster_info_size_in_bits(info, defs, config),
614+
Cluster::Array(_info, dim) => Ok(dim.dim * dim.dim_increment * BITS_PER_BYTE),
615+
}
616+
}
617+
618+
/// Recursively calculate the size of a ClusterInfo. A cluster's size is the
619+
/// maximum end position of its recursive children.
620+
fn cluster_info_size_in_bits(
607621
info: &ClusterInfo,
608622
defs: &RegisterProperties,
609623
config: &Config,
@@ -641,7 +655,7 @@ fn expand_cluster(
641655

642656
let defs = cluster.default_register_properties.derive_from(defs);
643657

644-
let cluster_size = cluster_size_in_bits(cluster, &defs, config)
658+
let cluster_size = cluster_info_size_in_bits(cluster, &defs, config)
645659
.with_context(|| format!("Cluster {} has no determinable `size` field", cluster.name))?;
646660

647661
match cluster {

0 commit comments

Comments
 (0)