rust-embedded / svd2rust

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

Compiler complains that Peripherals is not an iterator #699

Closed erazor-de closed 1 year ago

erazor-de commented 1 year ago

I'm using rustc 1.65.0 (897e37553 2022-11-02) svd2rust 0.27.2 ( )

I made a crate from the manufacturers STM32F103.svd using your documentation. When I try to use the crate in another project like:

#![no_std]
#![no_main]

use panic_halt as _;

use cortex_m_rt::entry;
use stm32f103;

#[entry]
fn main() -> ! {
    let peripherals = stm32f103::Peripherals::take().unwrap();
    let cortex = cortex_m::Peripherals::take().unwrap();

    loop {}
}

I get the error message:

error: src/main.rs:11: `stm32f103::Peripherals` is not an iterator
error: src/main.rs:11: `stm32f103::Peripherals` is not an iterator
note: src/main.rs:11: the following trait bounds were not satisfied:
`stm32f103::Peripherals: Iterator`
which is required by `&mut stm32f103::Peripherals: Iterator`
error: stm32f103/src/lib.rs:2126: doesn't satisfy `stm32f103::Peripherals: Iterator`
error: could not compile `stm32f103rb` due to 2 previous errors

Taking the Peripherals of the cortex_m crate produces no error. I tried with edition 2021 and 2018 in Cargo.toml.

Emilgardis commented 1 year ago

please post the entire error output instead of a truncated one.

error[E0599]: `Peripherals` is not an iterator
    --> tests/test.rs:3:29
     |
3    |     stm32f103::Peripherals::take().unwrap();
     |                             ^^^^ `Peripherals` is not an iterator
     |
    ::: /Users/emil/workspace/dev_space/svdtests/stm32f103/src/lib.rs:1797:1
     |
1797 | pub struct Peripherals {
     | ---------------------- doesn't satisfy `Peripherals: Iterator`
             `Peripherals: Iterator`
             which is required by `&mut Peripherals: Iterator`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `stm32f103` due to previous error

make sure you enable the feature critical-section in the binary crate for stm32f103

pretty sure this is the issue, unfortunate that we get this error and not

 --> tests/test.rs:3:29
  |
3 |     stm32f103::Peripherals::take().unwrap();
  |                             ^^^^^ function or associated item not found in `Peripherals`
erazor-de commented 1 year ago

The using crate now has two new feature uses regarding critical-section:

cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
stm32f103 = { version = "0.0.1", path = "./stm32f103", features = ["rt", "critical-section"] }

This seems to work now.