Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The number of enumeratedValue elements in the enumeratedValues element if the derivedFrom attribute is present #1647

Open
AndreySmirnov81 opened this issue Sep 27, 2023 · 6 comments
Labels

Comments

@AndreySmirnov81
Copy link

AndreySmirnov81 commented Sep 27, 2023

изображение
изображение

PROBLEMS (Validation with XSD grammar) when using the VS Code XML extension:
https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml

SVD File: https://stm32-rs.github.io/stm32-rs/stm32f103.svd.patched

изображение

@jkrech
Copy link
Collaborator

jkrech commented Sep 27, 2023

This looks like a bug in the schema. The enumeratedValue minOccurs should be 0, even if this only true in case the derivedFrom attribute is specified.

@AndreySmirnov81
Copy link
Author

If I understand correctly, XSD does not allow us to specify the relationship between the presence of the derivedFrom attribute and the number of enumeratedValue elements.
Do I understand correctly that if the derivedFrom attribute is missing, then the number of enumeratedValue elements should be at least one?

@JonatanAntoni
Copy link
Member

[..] XSD does not allow us to specify the relationship [..]

No, not directly. What might work is grouping elements into exclusive groups. But that easily creates new issues/drawbacks.

The schema describes the syntax of a language. The relationship between elements is about semantics.

@AndreySmirnov81
Copy link
Author

@JonatanAntoni
Could you give an example of how this can be done?

@jkrech jkrech added the bug label Oct 2, 2023
@jkrech
Copy link
Collaborator

jkrech commented Oct 2, 2023

It looks like the feature of reusing enumerated values has not really been used, as it would fail with the current schema. Sorry for the inconvenience.
Here is an example of how deriving an enumeratedValues description in a separate field.
I am using the ARM_Example.svd included in the ARM.CMSIS.5.9.0.pack in the CMSIS/utilities/ directory.
I am reusing the enumeration of the field "EN". To reference the enumeratedValues section, I need to specify the optional name tag in line 115

              <enumeratedValues>
			    <name>EN_enum</name>

For demonstration purposes I am adding a new register description:

        <register>
          <name>InheritEnum</name>
          <description>Control Register</description>
          <addressOffset>0xF0</addressOffset>
          <size>32</size>
          <access>read-write</access>
          <resetValue>0x00000000</resetValue>
          <resetMask>0xFFFFFFFF</resetMask>
          <fields>
	    <field>
	      <name>EN</name>
              <description>Enable</description>
              <bitRange>[0:0]</bitRange>
              <access>read-write</access>
              <enumeratedValues derivedFrom="TIMER0.CR.EN.EN_enum"/>
	   </field>
        </fields>
    </register>

In the above case it would have been smarter to derive the field EN.
The converter happily converts the above, however the schema requires changes to pass:
a) the derivedFrom attribute does not support dots . which are required for referencing a peripheral.register.field.enum. A new type shall be added to the schema e.g. referenceIdentifierType
b) as suggested above in the enumerationType the attribute minOccurs=0 nees to be set for the enumeratedValue element.

As a consequence the schema check no longer detects the case where the element enumeratedValues which is not derivedFrom another named enumeratedValues description, does not contain any enumeratedValue child elements.

Note that most people are generating the SVD file from some other source and therefore do not make use of deriving field and enumeration descriptions. I would be interested to understand how your use case is different.

@AndreySmirnov81
Copy link
Author

AndreySmirnov81 commented Oct 2, 2023

@jkrech

Note that most people are generating the SVD file from some other source and therefore do not make use of deriving field and enumeration descriptions. I would be interested to understand how your use case is different.

I'm taking SVD from the project https://github.com/stm32-rs/stm32-rs (more specifically https://stm32-rs.github.io/stm32-rs/) in order to use it in https://marketplace.visualstudio.com/items?itemName=mcu-debug.peripheral-viewer.
Sometimes I open SVD in VS Code editor to view and make changes.
In VS Code I use the extension https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml.
This extension performs XSD validation, as a result of which many errors are detected (see the very first message).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants