Skip to content

Fail to compile for LPC176x5x_v0.2.svd #112

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

Closed
nicholastmosher opened this issue Jun 8, 2017 · 9 comments
Closed

Fail to compile for LPC176x5x_v0.2.svd #112

nicholastmosher opened this issue Jun 8, 2017 · 9 comments

Comments

@nicholastmosher
Copy link

nicholastmosher commented Jun 8, 2017

Hi, I'm trying to create a crate for the LPC1768 using the LPC176x5x_v0.2.svd file. The output lib file seems to have a lot of errors involving duplicate definitions. Running svd2rust as in the usage works just fine, but when I try to compile the crate, I get the following errors:

$ cargo build
   Compiling LPC1769 v0.1.0 (file:///home/nick/Documents/LPC1769)
error[E0428]: a type named `MR` has already been defined in this module
     --> src/lib.rs:22536:5
      |
20407 | /     pub struct MR {
20408 | |         register: VolatileCell<u32>,
20409 | |     }
      | |_____- previous definition of `MR` here
...
22536 | /     pub struct MR {
22537 | |         register: VolatileCell<u32>,
22538 | |     }
      | |_____^ `MR` already defined

error[E0428]: a module named `mr` has already been defined in this module
     --> src/lib.rs:22540:5
      |
20411 | /     pub mod mr {
20412 | |         # [ doc = r" Value read from the register" ]
20413 | |         pub struct R {
20414 | |             bits: u32,
...     |
20512 | |         }
20513 | |     }
      | |_____- previous definition of `mr` here
...
22540 | /     pub mod mr {
22541 | |         # [ doc = r" Value read from the register" ]
22542 | |         pub struct R {
22543 | |             bits: u32,
...     |
22641 | |         }
22642 | |     }
      | |_____^ `mr` already defined

error[E0428]: a type named `THE_TIME_COUNTERS_AR` has already been defined in this enum
     --> src/lib.rs:28515:13
      |
28513 |             THE_TIME_COUNTERS_AR,
      |             -------------------- previous definition of `THE_TIME_COUNTERS_AR` here
28514 |             # [ doc = "The time counters are disabled so that they may be initialized." ]
28515 |             THE_TIME_COUNTERS_AR,
      |             ^^^^^^^^^^^^^^^^^^^^ `THE_TIME_COUNTERS_AR` already defined

error[E0428]: a type named `THE_CALIBRATION_COUN` has already been defined in this enum
     --> src/lib.rs:28615:13
      |
28613 |             THE_CALIBRATION_COUN,
      |             -------------------- previous definition of `THE_CALIBRATION_COUN` here
28614 |             # [ doc = "The calibration counter is enabled and counting, using the 1 Hz clock. When the calibration counter is equal to the value of the CALIBRATION register, the counter resets and repeats counting up to the value of the CALIBRATION register. See Section 30.6.4.2 and  Section 30.6.5." ]
28615 |             THE_CALIBRATION_COUN,
      |             ^^^^^^^^^^^^^^^^^^^^ `THE_CALIBRATION_COUN` already defined

error[E0428]: a type named `DISABLED` has already been defined in this enum
     --> src/lib.rs:52911:13
      |
52909 |             DISABLED,
      |             -------- previous definition of `DISABLED` here
52910 |             # [ doc = "Disabled. P0.6 pin has neither pull-up nor pull-down." ]
52911 |             DISABLED,
      |             ^^^^^^^^ `DISABLED` already defined

error[E0428]: a type named `CONFIG` has already been defined in this module
      --> src/lib.rs:135025:5
       |
132879 | /     pub struct CONFIG {
132880 | |         register: VolatileCell<u32>,
132881 | |     }
       | |_____- previous definition of `CONFIG` here
...
135025 | /     pub struct CONFIG {
135026 | |         register: VolatileCell<u32>,
135027 | |     }
       | |_____^ `CONFIG` already defined

error[E0428]: a module named `config` has already been defined in this module
      --> src/lib.rs:135029:5
       |
132883 | /     pub mod config {
132884 | |         # [ doc = r" Value read from the register" ]
132885 | |         pub struct R {
132886 | |             bits: u32,
...      |
133061 | |         }
133062 | |     }
       | |_____- previous definition of `config` here
...
135029 | /     pub mod config {
135030 | |         # [ doc = r" Value read from the register" ]
135031 | |         pub struct R {
135032 | |             bits: u32,
...      |
135566 | |         }
135567 | |     }
       | |_____^ `config` already defined

error[E0428]: a type named `THE_TIME_COUNTERS_AR` has already been defined in this enum
     --> src/lib.rs:28375:13
      |
28373 |             THE_TIME_COUNTERS_AR,
      |             -------------------- previous definition of `THE_TIME_COUNTERS_AR` here
28374 |             # [ doc = "The time counters are disabled so that they may be initialized." ]
28375 |             THE_TIME_COUNTERS_AR,
      |             ^^^^^^^^^^^^^^^^^^^^ `THE_TIME_COUNTERS_AR` already defined

error[E0428]: a type named `THE_CALIBRATION_COUN` has already been defined in this enum
     --> src/lib.rs:28469:13
      |
28467 |             THE_CALIBRATION_COUN,
      |             -------------------- previous definition of `THE_CALIBRATION_COUN` here
28468 |             # [ doc = "The calibration counter is enabled and counting, using the 1 Hz clock. When the calibration counter is equal to the value of the CALIBRATION register, the counter resets and repeats counting up to the value of the CALIBRATION register. See Section 30.6.4.2 and  Section 30.6.5." ]
28469 |             THE_CALIBRATION_COUN,
      |             ^^^^^^^^^^^^^^^^^^^^ `THE_CALIBRATION_COUN` already defined

error[E0428]: a type named `DISABLED` has already been defined in this enum
     --> src/lib.rs:52124:13
      |
52122 |             DISABLED,
      |             -------- previous definition of `DISABLED` here
52123 |             # [ doc = "Disabled. P0.6 pin has neither pull-up nor pull-down." ]
52124 |             DISABLED,
      |             ^^^^^^^^ `DISABLED` already defined

error[E0428]: a type named `ERROR_OCCURRED_DURIN` has already been defined in this enum
     --> src/lib.rs:80396:13
      |
80394 |             ERROR_OCCURRED_DURIN,
      |             -------------------- previous definition of `ERROR_OCCURRED_DURIN` here
80395 |             # [ doc = "Error occurred during receiving." ]
80396 |             ERROR_OCCURRED_DURIN,
      |             ^^^^^^^^^^^^^^^^^^^^ `ERROR_OCCURRED_DURIN` already defined

error[E0201]: duplicate definitions with name `bits`:
     --> src/lib.rs:27435:13
      |
27376 | /             pub fn bits(&self) -> u32 {
27377 | |                 self.bits
27378 | |             }
      | |_____________- previous definition of `bits` here
...
27435 | /             pub fn bits(&self) -> BITSR {
27436 | |                 BITSR::_from({
27437 | |                                  const MASK: u8 = 15;
27438 | |                                  const OFFSET: u8 = 8;
27439 | |                                  ((self.bits >> OFFSET) & MASK as u32) as u8
27440 | |                              })
27441 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `bits`:
     --> src/lib.rs:27487:13
      |
27451 | /             pub unsafe fn bits(&mut self, bits: u32) -> &mut Self {
27452 | |                 self.bits = bits;
27453 | |                 self
27454 | |             }
      | |_____________- previous definition of `bits` here
...
27487 | /             pub fn bits(&mut self) -> _BITSW {
27488 | |                 _BITSW { w: self }
27489 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_the_time_counters_ar`:
     --> src/lib.rs:28412:13
      |
28407 | /             pub fn is_the_time_counters_ar(&self) -> bool {
28408 | |                 *self == CLKENR::THE_TIME_COUNTERS_AR
28409 | |             }
      | |_____________- previous definition of `is_the_time_counters_ar` here
...
28412 | /             pub fn is_the_time_counters_ar(&self) -> bool {
28413 | |                 *self == CLKENR::THE_TIME_COUNTERS_AR
28414 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_the_calibration_coun`:
     --> src/lib.rs:28506:13
      |
28501 | /             pub fn is_the_calibration_coun(&self) -> bool {
28502 | |                 *self == CCALENR::THE_CALIBRATION_COUN
28503 | |             }
      | |_____________- previous definition of `is_the_calibration_coun` here
...
28506 | /             pub fn is_the_calibration_coun(&self) -> bool {
28507 | |                 *self == CCALENR::THE_CALIBRATION_COUN
28508 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `the_time_counters_ar`:
     --> src/lib.rs:28547:13
      |
28542 | /             pub fn the_time_counters_ar(self) -> &'a mut W {
28543 | |                 self.variant(CLKENW::THE_TIME_COUNTERS_AR)
28544 | |             }
      | |_____________- previous definition of `the_time_counters_ar` here
...
28547 | /             pub fn the_time_counters_ar(self) -> &'a mut W {
28548 | |                 self.variant(CLKENW::THE_TIME_COUNTERS_AR)
28549 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `the_calibration_coun`:
     --> src/lib.rs:28647:13
      |
28642 | /             pub fn the_calibration_coun(self) -> &'a mut W {
28643 | |                 self.variant(CCALENW::THE_CALIBRATION_COUN)
28644 | |             }
      | |_____________- previous definition of `the_calibration_coun` here
...
28647 | /             pub fn the_calibration_coun(self) -> &'a mut W {
28648 | |                 self.variant(CCALENW::THE_CALIBRATION_COUN)
28649 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_disabled`:
     --> src/lib.rs:52163:13
      |
52158 | /             pub fn is_disabled(&self) -> bool {
52159 | |                 *self == P0_06MODER::DISABLED
52160 | |             }
      | |_____________- previous definition of `is_disabled` here
...
52163 | /             pub fn is_disabled(&self) -> bool {
52164 | |                 *self == P0_06MODER::DISABLED
52165 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `disabled`:
     --> src/lib.rs:52952:13
      |
52947 | /             pub fn disabled(self) -> &'a mut W {
52948 | |                 self.variant(P0_06MODEW::DISABLED)
52949 | |             }
      | |_____________- previous definition of `disabled` here
...
52952 | /             pub fn disabled(self) -> &'a mut W {
52953 | |                 self.variant(P0_06MODEW::DISABLED)
52954 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:79905:13
      |
79878 | /             pub fn is_set(&self) -> bool {
79879 | |                 self.bit()
79880 | |             }
      | |_____________- previous definition of `is_set` here
...
79905 | /             pub fn is_set(&self) -> bool {
79906 | |                 *self == RIR::SET
79907 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:79952:13
      |
79925 | /             pub fn is_set(&self) -> bool {
79926 | |                 self.bit()
79927 | |             }
      | |_____________- previous definition of `is_set` here
...
79952 | /             pub fn is_set(&self) -> bool {
79953 | |                 *self == TI1R::SET
79954 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:79999:13
      |
79972 | /             pub fn is_set(&self) -> bool {
79973 | |                 self.bit()
79974 | |             }
      | |_____________- previous definition of `is_set` here
...
79999 | /             pub fn is_set(&self) -> bool {
80000 | |                 *self == EIR::SET
80001 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:80046:13
      |
80019 | /             pub fn is_set(&self) -> bool {
80020 | |                 self.bit()
80021 | |             }
      | |_____________- previous definition of `is_set` here
...
80046 | /             pub fn is_set(&self) -> bool {
80047 | |                 *self == DOIR::SET
80048 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:80093:13
      |
80066 | /             pub fn is_set(&self) -> bool {
80067 | |                 self.bit()
80068 | |             }
      | |_____________- previous definition of `is_set` here
...
80093 | /             pub fn is_set(&self) -> bool {
80094 | |                 *self == WUIR::SET
80095 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:80140:13
      |
80113 | /             pub fn is_set(&self) -> bool {
80114 | |                 self.bit()
80115 | |             }
      | |_____________- previous definition of `is_set` here
...
80140 | /             pub fn is_set(&self) -> bool {
80141 | |                 *self == EPIR::SET
80142 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:80187:13
      |
80160 | /             pub fn is_set(&self) -> bool {
80161 | |                 self.bit()
80162 | |             }
      | |_____________- previous definition of `is_set` here
...
80187 | /             pub fn is_set(&self) -> bool {
80188 | |                 *self == ALIR::SET
80189 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:80234:13
      |
80207 | /             pub fn is_set(&self) -> bool {
80208 | |                 self.bit()
80209 | |             }
      | |_____________- previous definition of `is_set` here
...
80234 | /             pub fn is_set(&self) -> bool {
80235 | |                 *self == BEIR::SET
80236 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:80281:13
      |
80254 | /             pub fn is_set(&self) -> bool {
80255 | |                 self.bit()
80256 | |             }
      | |_____________- previous definition of `is_set` here
...
80281 | /             pub fn is_set(&self) -> bool {
80282 | |                 *self == IDIR::SET
80283 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:80328:13
      |
80301 | /             pub fn is_set(&self) -> bool {
80302 | |                 self.bit()
80303 | |             }
      | |_____________- previous definition of `is_set` here
...
80328 | /             pub fn is_set(&self) -> bool {
80329 | |                 *self == TI2R::SET
80330 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_set`:
     --> src/lib.rs:80375:13
      |
80348 | /             pub fn is_set(&self) -> bool {
80349 | |                 self.bit()
80350 | |             }
      | |_____________- previous definition of `is_set` here
...
80375 | /             pub fn is_set(&self) -> bool {
80376 | |                 *self == TI3R::SET
80377 | |             }
      | |_____________^ duplicate definition

error[E0201]: duplicate definitions with name `is_error_occurred_durin`:
     --> src/lib.rs:80433:13
      |
80428 | /             pub fn is_error_occurred_durin(&self) -> bool {
80429 | |                 *self == ERRDIRR::ERROR_OCCURRED_DURIN
80430 | |             }
      | |_____________- previous definition of `is_error_occurred_durin` here
...
80433 | /             pub fn is_error_occurred_durin(&self) -> bool {
80434 | |                 *self == ERRDIRR::ERROR_OCCURRED_DURIN
80435 | |             }
      | |_____________^ duplicate definition

error: aborting due to previous error(s)

error: Could not compile `LPC1769`.

To learn more, run the command again with --verbose.

I apologize if this isn't the right place to report this. Do you have any suggestions on how to fix this*, or do you know of any existing support crate for the LPC1768? Any help would be greatly appreciated!

*I wondered about simply deleting the duplicate code, but I'm worried that may cause other problems that might be harder to detect, plus that would be more of a band-aid solution.

@roysmeding
Copy link

Hi!
I looked through the SVD file, and the errors about struct mr look like the same issue described in #90.

(Most of?) the other errors seem due to errors in the input SVD file. It looks like they generated the enum names using a tool that cuts off long names, which causes some of them to be identical.

e.g. on line 5476-5488 of the SVD file:

					<enumeratedValues>
					<name>ENUM</name>
						<enumeratedValue>
							<name>THE_TIME_COUNTERS_AR</name>
							<description>The time counters are enabled.</description>
							<value>1</value>
						</enumeratedValue>
						<enumeratedValue>
							<name>THE_TIME_COUNTERS_AR</name>
							<description>The time counters are disabled so that they may be initialized.</description>
							<value>0</value>
						</enumeratedValue>
					</enumeratedValues>

These issues can only be fixed in the SVD file (or by finding a file for your device that doesn't have these issues.)

It would be good if svd2rust checked for this, though, instead of passing the names through verbatim.

@nicholastmosher
Copy link
Author

Ah, thanks for taking the time to answer, that helps a lot! Do you know if there's a workaround for the MR problem at the moment? I imagine I can at least complete all of the enum names to fix that part.

I'll go ahead and close this since all of the problems here seem to be represented by other issues or are specific to my scenario and not svd2rust :)

@roysmeding
Copy link

AIUI, it should be possible to bypass the issue with non-contiguous arrays by writing a separate definition for each register instead of using the SVD array functionality.

In other words, instead of the two <register> definitions for MR%s that use <dim> and <dimIndex> to generate multiple registers, you'd have one <register> for each individual one, named e.g. MR0, MR1, etc. (it seems there are six of them total).

@nicholastmosher
Copy link
Author

That worked, thanks a bunch! Now the only thing I have to do is figure out what's causing those duplicate function definitions and I should be set!

@nicholastmosher
Copy link
Author

For posterity, the way I got rid of the errors with duplicate is_set functions is by removing the enumeratedValues from the fields in the registers with the clashes. For example, in the ICR register, each field looked like:

<field>
    <name>TI3</name>
    <description>Transmit Interrupt 3. This bit is set when the TBS3 bit in CANxSR goes from 0 to 1 (whenever a message out of TXB3 was successfully transmitted or aborted), indicating that Transmit buffer 3 is available, and the TIE3 bit in CANxIER is 1.</description>
    <bitRange>[10:10]</bitRange>
    <enumeratedValues>
        <name>ENUM</name>
        <enumeratedValue>
            <name>RESET</name>
            <description>Reset</description>
            <value>0</value>
        </enumeratedValue>
        <enumeratedValue>
            <name>SET</name>
            <description>Set</description>
            <value>1</value>
        </enumeratedValue>
    </enumeratedValues>
</field>

Since one of those enumerations was named exactly SET, svd2rust would create an accessor function named after it, which turned into is_set, which was already a function that svd2rust placed in the interface, causing the clash. After fixing the entries, the field looks like this:

<field>
    <name>TI3</name>
    <description>Transmit Interrupt 3. This bit is set when the TBS3 bit in CANxSR goes from 0 to 1 (whenever a message out of TXB3 was successfully transmitted or aborted), indicating that Transmit buffer 3 is available, and the TIE3 bit in CANxIER is 1.</description>
    <bitRange>[10:10]</bitRange>
</field>

@japaric
Copy link
Member

japaric commented Jun 10, 2017

the way I got rid of the errors with duplicate is_set functions

FWIW, that has already been fixed in #109 but has not made it into a release yet. I'm waiting on making a decision on #111 before I make a release. If you could comment on that issue I'd appreciate it.

@simonvandel
Copy link
Contributor

@nicholastmosher can you share the SVD file you got working?

@nicholastmosher
Copy link
Author

nicholastmosher commented Jun 11, 2017

@simonvandel of course! I probably should have done that in my last post. I've gone ahead and made a repository with the svd2rust generated crate, it has the SVD patch file in the root directory: https://github.com/nicholastmosher/lpc176x5x-rs. The only other change I've made to the crate is that I broke up the top-level modules into their own files in order to help intellij and the intellij-rust plugin do the smart-complete magic :)

@simonvandel
Copy link
Contributor

@nicholastmosher Thanks!

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

No branches or pull requests

4 participants