Handle overrides in element group derivation#293
Handle overrides in element group derivation#293scootermon wants to merge 1 commit intorust-embedded:masterfrom
Conversation
|
Thanks for the PR and sorry for the delay in reviewing! LGTM but I don't understand why the CI workflows haven't run and there doesn't seem to be the usual option to approve running them. Maybe if you run another force push it will run/allow approving to run? Otherwise all seems OK so we could merge through the merge queue which will run CI too. @burrbull / @Emilgardis ? |
|
Unfortunately the spec does not fully describe behavior during derive. I not sure about correctness of code neither before PR not after (I afraid that partial derive of dim group could cause tag conflicts). I need see real example what was working wrong and how it should work. |
@scootermon show this file, please. Or part of the file. |
svd-rs/src/derive_from.rs
Outdated
| derived.dim_index = derived.dim_index.or_else(|| dim_index.clone()); | ||
| derived.dim_name = derived.dim_name.or_else(|| dim_name.clone()); | ||
| derived.dim_array_index = derived.dim_array_index.or_else(|| dim_array_index.clone()); |
There was a problem hiding this comment.
| derived.dim_index = derived.dim_index.or_else(|| dim_index.clone()); | |
| derived.dim_name = derived.dim_name.or_else(|| dim_name.clone()); | |
| derived.dim_array_index = derived.dim_array_index.or_else(|| dim_array_index.clone()); | |
| derived.dim_index = derived.dim_index.or_else(|| { | |
| dim_index | |
| .as_ref() | |
| .and_then(|di| (*dim == derived.dim).then(|| di.clone())) | |
| }); | |
| derived.dim_name = derived.dim_name.or_else(|| dim_name.clone()); | |
| derived.dim_array_index = derived.dim_array_index.or_else(|| { | |
| dim_array_index | |
| .as_ref() | |
| .and_then(|dai| (*dim == derived.dim).then(|| dai.clone())) | |
| }); |
We should derive dim_index only when same size.
@burrbull, unfortunately, I cannot share the file or significant portions from it. Here's a reduced version just to illustrate the pattern: <!-- CAN0 -->
<register>
<name>eRAM[%s]</name>
<description>Embedded RAM</description>
<size>32</size>
<access>read-write</access>
<dim>128</dim>
<dimIncrement>4</dimIncrement>
<!-- [Other elements omitted] -->
</register>
<!-- CAN1 (this one is complete!) -->
<register derivedFrom="CAN0.eRAM[%s]">
<name>eRAM[%s]</name>
<description>Embedded RAM</description>
<dim>64</dim>
<dimIncrement>4</dimIncrement>
</register>The CAN1 peripheral only has half the amount of "RAM" registers, but the fields are otherwise identical. |
|
Really strange that CI hasn't run. I agree with being hesitant to this change. Does the svd pass through svdconv? |
bf41ce3 to
44af50a
Compare
I think it's some weirdness with the CI not being approved in time. I rebased the PR so you should be able to approve the workflow run again. You can also see the run from the forked repo here: https://github.com/inomotech-foss/svd/actions/runs/20753031060 |
@Emilgardis I ran typedef struct { /*!< CAN0 Structure */
/* [SNIP] */
__IM uint32_t RESERVED4[11];
__IOM uint32_t CAN0_eRAM[128]; /*!< Embedded RAM */
__IM uint32_t RESERVED5[384];
/* [SNIP] */
} CAN0_Type;
typedef struct { /*!< CAN1 Structure */
/* [SNIP] */
__IM uint32_t RESERVED4[11];
__IOM uint32_t CAN1_eRAM[64]; /*!< Embedded RAM */
__IM uint32_t RESERVED5[448];
/* [SNIP] */
} CAN1_Type;So it definitely understands the I went ahead and crafted a minimal SVD file to reproduce this. You can find it along with the generated header file here: https://gist.github.com/scootermon/68828d5bc4f19b06dfb3a0b1e473d155 |
|
LGTM
|
Apologies, @burrbull. I first wanted to settle whether there's even a chance for this PR to get merged before going into the details.
No, there's nothing important hidden there, it's just a lot more registers that aren't relevant to the issue. |
I have an SVD file with two instances of a peripheral. The second peripheral contains the same registers, but instead of 128 it only has 64. The SVD file uses
derivedFromin the second peripheral to inherit these registers but overrides the<dim>element. To my surprise,svd2rustgenerated arrays with the same number of elements for both instances.Well, after following the trail I ended up here and the reason wasn't hard to find.
I saw #283 and the follow up #286, but there's little to no reasoning attached to these PRs.
Looking at the spec here I really don't see a reason why the fields from
dimElementGroupshouldn't also be overridden.The
derivedFromdescription readsI can't see a statement about the
dimElementGroupelements somehow being exempt.