svd2rust icon indicating copy to clipboard operation
svd2rust copied to clipboard

Problem with registers with %s not being expanded.

Open tim-programmer opened this issue 8 years ago • 3 comments

I'm using the SVD for the LPC4357 which I retrieved from here: https://community.nxp.com/docs/DOC-334628. I had to make some edits of some enum names since the original file causes duplicate symbols.

The problem is with the SGPIO registers which have the form SFSP0_%s but the generated rust code doesn't have the additional index value of 0-1 (from dimIndex) that I'd expect.

    pub struct RegisterBlock {
        #[doc = "0x00 - Pin configuration register for pins P0"]
        pub sfsp0_: [SFSP0_; 2],
    }
    #[doc = "Pin configuration register for pins P0"]
    pub struct SFSP0_ {
        register: VolatileCell<u32>,
    }

I've attached a reduced version of the file the reproduces the problem. LPC43xx_43Sxx_reduce.zip

tim-programmer avatar Jan 19 '18 19:01 tim-programmer

This is because svd2rust "unrolls" the array/list. This is to make functions taking an %sed register easier to write.

Emilgardis avatar Jan 29 '18 21:01 Emilgardis

@Emilgardis Yes I understand what it's supposed to do, the issue is that it isn't replacing the %s with anything. I'd expect pub struct SFSP0_0 and pub struct SFSP0_1 blocks rather than just multiple pub struct SFSP0_ blocks.

tim-programmer avatar Feb 08 '18 18:02 tim-programmer

This could be solved with having svd2rust make a trait SFSP0_, and then generate structs which implement that trait. The only problem with this approach is that we'd need to have an array like [T;2] where T: SFSP0_, which iirc is not possible today.

Emilgardis avatar Feb 08 '18 20:02 Emilgardis

This isn't really related to #662 but I may be able to offer some insight. In this case svd2rust is not expanding/unrolling the dimElementGroup (identifiers with the %s notation) as suggested, but actually making an array using a common type. Since it uses a common type, that type has to have a name, which in most cases is best given by simply replacing the enumerating token %s with nothing. In your case, the trailing underscore is unfortunate and I might suggest that svd2rust replace it with something interesting like n to denote that the struct is shared by a number of SFSP0_n registers. What do @burrbull and @Emilgardis think?

n8tlarsen avatar Nov 07 '22 16:11 n8tlarsen

We already have keep_list cli flag which should give expected in topic behavior.

burrbull avatar Nov 07 '22 16:11 burrbull

Reopen if keep_list doesn't work.

burrbull avatar Nov 07 '22 19:11 burrbull