Skip to content

Commit d59a264

Browse files
committed
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.
1 parent f067e74 commit d59a264

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/generate/peripheral.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,18 @@ fn cluster_size_in_bits(
611611
) -> Result<u32> {
612612
match cluster {
613613
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),
614+
// If the contained array cluster has a mismatch between the
615+
// dimIncrement and the size of the array items, then the array
616+
// will get expanded in expand_cluster below. The overall size
617+
// then ends at the last array entry.
618+
Cluster::Array(info, dim) => {
619+
if dim.dim == 0 {
620+
return Ok(0); // Special case!
621+
}
622+
let last_offset = (dim.dim - 1) * dim.dim_increment * BITS_PER_BYTE;
623+
let last_size = cluster_info_size_in_bits(info, defs, config);
624+
Ok(last_offset + last_size?)
625+
}
615626
}
616627
}
617628

0 commit comments

Comments
 (0)