Skip to content

Can not use SPI3 #356

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
rfael opened this issue Aug 4, 2021 · 2 comments
Closed

Can not use SPI3 #356

rfael opened this issue Aug 4, 2021 · 2 comments

Comments

@rfael
Copy link

rfael commented Aug 4, 2021

Hi,
I am trying to use SPI3 on STM32F107 MCU, but I can not due to this error:

error[E0271]: type mismatch resolving `<Spi1Remap as stm32f1xx_hal::spi::sealed::Remap>::Periph == stm32f1xx_hal::pac::SPI3`
   --> src/main.rs:128:19
    |
128 |         let spi = stm32f1xx_hal::spi::Spi::spi3(
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `stm32f1xx_hal::pac::SPI3`, found struct `stm32f1xx_hal::pac::SPI1`
    |
    = note: required by `Spi::<stm32f1xx_hal::pac::SPI3, REMAP, PINS, u8>::spi3`

I think the compiler forces me to use remaped SPI1 instead of SPI3. In my case I can do that, but what if I want to use SPI1 and SPI3 at the same time?

Code snippet that I use to initialize the SPI3:

        let (_pa15, pb3, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4);

        let spi_pins = (
            pb3.into_alternate_push_pull(&mut gpiob.crl),
            pb4.into_floating_input(&mut gpiob.crl),
            gpiob.pb5.into_alternate_push_pull(&mut gpiob.crl),
        );

        let spi_mode = embedded_hal::spi::Mode {
            polarity: embedded_hal::spi::Polarity::IdleLow,
            phase: embedded_hal::spi::Phase::CaptureOnFirstTransition,
        };

        let spi = stm32f1xx_hal::spi::Spi::spi3(
            device.SPI3,
            spi_pins,
            &mut afio.mapr,
            spi_mode,
            100.khz(),
            clocks,
            &mut rcc_apb1,
        );
@burrbull
Copy link
Member

burrbull commented Aug 4, 2021

Try master branch.
Should be fixed by #312 .

@tfx2001
Copy link

tfx2001 commented Aug 11, 2021

It has been fixed by #312. You can use below in your Cargo.toml

stm32f1xx-hal = { git = "https://github.com/stm32-rs/stm32f1xx-hal.git", features = ["stm32f103", "rt", "high"] }

@rfael rfael closed this as completed Aug 11, 2021
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

3 participants