rust-embedded / svd2rust

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

Enum explicit descriminant collision #701

Closed Slesarew closed 1 year ago

Slesarew commented 1 year ago

After running the tool for EFM32PG23B310 devices (like ones used in https://github.com/efm32-rs/efm32pg-pacs/tree/master/svd/EFM32PG23 or those on keil.com, does not matter) I end up with chunks of code like this:

#[doc = "Configure transition action in normal mode\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum PRSACT_A {
    #[doc = "0: No PRS output generated (if PRSCOUNT == 0), or do not count (if PRSCOUNT == 1)."]
    NONE = 0,
    #[doc = "1: Pulse generated on LESENSE PRS output 0 (if PRSCOUNT == 0)."]
    PRS0 = 1,
    #[doc = "1: Count Up (if PRSCOUNT == 1)."]
    UP = 1,
    #[doc = "2: Pulse generated on LESENSE PRS output 1 (if PRSCOUNT == 0)."]
    PRS1 = 2,
    #[doc = "2: Count Down (if PRSCOUNT == 1)."]
    DOWN = 2,
    #[doc = "3: Pulse generated on LESENSE PRS output 0 and 1 (if PRSCOUNT == 0)."]
    PRS01 = 3,
    #[doc = "4: Pulse generated on LESENSE PRS output 2. (PRSCOUNT == 0 OR 1)."]
    PRS2 = 4,
    #[doc = "5: Pulse generated on LESENSE PRS output 0 and 2 (if PRSCOUNT == 0)."]
    PRS02 = 5,
    #[doc = "5: Count Up and Pulse generated on LESENSE PRS output 2 (if PRSCOUNT == 1)."]
    UPANDPRS2 = 5,
    #[doc = "6: Pulse generated on LESENSE PRS output 1 and 2 (if PRSCOUNT == 0)."]
    PRS12 = 6,
    #[doc = "6: Count Down and Pulse generated on LESENSE PRS output 2 (if PRSCOUNT == 1)."]
    DOWNANDPRS2 = 6,
    #[doc = "7: Pulse generated on LESENSE PRS output 0, 1 and 2 (if PRSCOUNT == 0)."]
    PRS012 = 7,
}

which results in hundreds of collision errors upon build:

error[E0081]: discriminant value `6` assigned more than once
  --> src/lesense_ns/st63_arc.rs:54:1
   |
54 | / pub enum PRSACT_A {
55 | |     #[doc = "0: No PRS output generated (if PRSCOUNT == 0), or do not count (if PRSCOUNT == 1)."]
56 | |     NONE = 0,
57 | |     #[doc = "1: Pulse generated on LESENSE PRS output 0 (if PRSCOUNT == 0)."]
...  |
74 | |     PRS12 = 6,
   | |             - first assignment of `6`
75 | |     #[doc = "6: Count Down and Pulse generated on LESENSE PRS output 2 (if PRSCOUNT == 1)."]
76 | |     DOWNANDPRS2 = 6,
   | |                   - second assignment of `6`
77 | |     #[doc = "7: Pulse generated on LESENSE PRS output 0, 1 and 2 (if PRSCOUNT == 0)."]
78 | |     PRS012 = 7,
79 | | }
   | |_^

I have tried passing --strict and all kinds of other underdocumented (sorry I didn't find any clear explanations) config keys in varying combinations and this is still the same. Maybe it is related to #283 or #636 issues. It might be caused by #402

Similar issue seems to be present in abovelinked crate.

svd configs for STM32 devices build without issues with my setup.

burrbull commented 1 year ago

Your SVD have several entries in enums with identical values. It is not supported and will not be:

              <name>PRSACT</name>
              <description>Configure transition action in normal mode</description>
              <bitOffset>13</bitOffset>
              <bitWidth>3</bitWidth>
              <access>read-write</access>
              <enumeratedValues>
                <enumeratedValue>
                  <name>NONE</name>
                  <description>No PRS output generated (if PRSCOUNT == 0), or do not count (if PRSCOUNT == 1).</description>
                  <value>0</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>PRS0</name>
                  <description>Pulse generated on LESENSE PRS output 0 (if PRSCOUNT == 0).</description>
                  <value>1</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>UP</name>
                  <description>Count Up (if PRSCOUNT == 1).</description>
                  <value>1</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>PRS1</name>
                  <description>Pulse generated on LESENSE PRS output 1 (if PRSCOUNT == 0).</description>
                  <value>2</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>DOWN</name>
                  <description>Count Down (if PRSCOUNT == 1).</description>
                  <value>2</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>PRS01</name>
                  <description>Pulse generated on LESENSE PRS output 0 and 1 (if PRSCOUNT == 0).</description>
                  <value>3</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>PRS2</name>
                  <description>Pulse generated on LESENSE PRS output 2. (PRSCOUNT == 0 OR 1).</description>
                  <value>4</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>PRS02</name>
                  <description>Pulse generated on LESENSE PRS output 0 and 2 (if PRSCOUNT == 0).</description>
                  <value>5</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>UPANDPRS2</name>
                  <description>Count Up and Pulse generated on LESENSE PRS output 2 (if PRSCOUNT == 1).</description>
                  <value>5</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>PRS12</name>
                  <description>Pulse generated on LESENSE PRS output 1 and 2 (if PRSCOUNT == 0).</description>
                  <value>6</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>DOWNANDPRS2</name>
                  <description>Count Down and Pulse generated on LESENSE PRS output 2 (if PRSCOUNT == 1).</description>
                  <value>6</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>PRS012</name>
                  <description>Pulse generated on LESENSE PRS output 0, 1 and 2 (if PRSCOUNT == 0).</description>
                  <value>7</value>
                </enumeratedValue>
              </enumeratedValues>

You need to delete those before start svd2rust. All listed above issues and PRs are not related to this one.

Slesarew commented 1 year ago

Thank you, it's on my side indeed! I didn't expect the silabs to be this mean in their definitions. Sorry for confusion. I probably should not be using vendor-made svd files after all.