Skip to content

Commit a24190c

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 5dbf6f3 commit a24190c

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
@@ -602,7 +602,18 @@ fn cluster_size_in_bits(
602602
) -> Result<u32> {
603603
match cluster {
604604
Cluster::Single(info) => cluster_info_size_in_bits(info, defs, config),
605-
Cluster::Array(_info, dim) => Ok(dim.dim * dim.dim_increment * BITS_PER_BYTE),
605+
// If the contained array cluster has a mismatch between the
606+
// dimIncrement and the size of the array items, then the array
607+
// will get expanded in expand_cluster below. The overall size
608+
// then ends at the last array entry.
609+
Cluster::Array(info, dim) => {
610+
if dim.dim <= 0 {
611+
return Ok(0); // Special case!
612+
}
613+
let last_offset = (dim.dim - 1) * dim.dim_increment * BITS_PER_BYTE;
614+
let last_size = cluster_info_size_in_bits(info, defs, config);
615+
Ok(last_offset + last_size?)
616+
}
606617
}
607618
}
608619

0 commit comments

Comments
 (0)