rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
709 stars 151 forks source link

Generate arrya of register when using `%s` in dimElementGroup #561

Closed duskmoon314 closed 2 years ago

duskmoon314 commented 2 years ago

Hi.

In the svd file, I use dimElementGroup to describe a list of registers in this way:

<register>
  <dim>32</dim>
  <dimIncrement>0x04</dimIncrement>
  <name>LEDC_FIFO_DATA%s</name>
  <description>LEDC FIFO Data Register</description>
  <addressOffset>0x0030</addressOffset>
  <access>read-only</access>
</register>

The generated rust code is:

#[doc = "0x30..0xb0 - LEDC FIFO Data Register"]
pub ledc_fifo_data: [crate::Reg<ledc_fifo_data::LEDC_FIFO_DATA_SPEC>; 32],

According to CMSIS-SVD 1.3.6, I believe we use %s to describe a list of registers and [%s] to describe an array of registers.

Is this a bug or a feature? I haven't found a description of this behavior in the document.

burrbull commented 2 years ago

This is not a bug and not a feature. We just decided to produce arrays when it is possible. You could add PR to change this behavior if you need, but under feature flag.

burrbull commented 2 years ago

You can try to run svd2rust with --const_generic. It should create array proxy with can work in more complicated situations.