Struct stm32wlxx_hal::spi::Spi

source ·
pub struct Spi<SPI, SCK, MISO, MOSI> { /* private fields */ }
Expand description

SPI 1 and 2 driver.

Implementations§

source§

impl<SCK, MISO, MOSI> Spi<SPI1, SCK, MISO, MOSI>

source

pub unsafe fn pulse_reset(rcc: &mut RCC)

Reset the SPI.

Safety
  1. The SPI must not be in-use.
  2. You are responsible for setting up the SPI after a reset.
Example
use stm32wlxx_hal::{
    pac,
    spi::{NoMiso, NoMosi, NoSck, Spi},
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
unsafe { Spi::<pac::SPI1, NoSck, NoMiso, NoMosi>::pulse_reset(&mut dp.RCC) };
source

pub unsafe fn disable_clock(rcc: &mut RCC)

Disable the SPI clock.

Safety
  1. You are responsible for ensuring the SPI is in a state where the clock can be disabled without entering an error state.
  2. You cannot use the SPI while the clock is disabled.
  3. You are responsible for re-enabling the clock before resuming use of the SPI.
  4. You are responsible for setting up anything that may have lost state while the clock was disabled.
Example
use stm32wlxx_hal::{
    pac,
    spi::{NoMiso, NoMosi, NoSck, Spi},
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
unsafe { Spi::<pac::SPI1, NoSck, NoMiso, NoMosi>::disable_clock(&mut dp.RCC) };
source

pub fn enable_clock(rcc: &mut RCC)

Enable the SPI clock.

This is done for you in new_ constructors.

Example
use stm32wlxx_hal::{
    pac,
    spi::{NoMiso, NoMosi, NoSck, Spi},
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
Spi::<pac::SPI1, NoSck, NoMiso, NoMosi>::enable_clock(&mut dp.RCC);
source§

impl<SCK, MISO, MOSI> Spi<SPI2, SCK, MISO, MOSI>

source

pub unsafe fn pulse_reset(rcc: &mut RCC)

Reset the SPI.

Safety
  1. The SPI must not be in-use.
  2. You are responsible for setting up the SPI after a reset.
Example
use stm32wlxx_hal::{
    pac,
    spi::{NoMiso, NoMosi, NoSck, Spi},
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
unsafe { Spi::<pac::SPI2, NoSck, NoMiso, NoMosi>::pulse_reset(&mut dp.RCC) };
source

pub unsafe fn disable_clock(rcc: &mut RCC)

Disable the SPI clock.

Safety
  1. You are responsible for ensuring the SPI is in a state where the clock can be disabled without entering an error state.
  2. You cannot use the SPI while the clock is disabled.
  3. You are responsible for re-enabling the clock before resuming use of the SPI.
  4. You are responsible for setting up anything that may have lost state while the clock was disabled.
Example
use stm32wlxx_hal::{
    pac,
    spi::{NoMiso, NoMosi, NoSck, Spi},
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
unsafe { Spi::<pac::SPI2, NoSck, NoMiso, NoMosi>::disable_clock(&mut dp.RCC) };
source

pub fn enable_clock(rcc: &mut RCC)

Enable the SPI clock.

This is done for you in new_ constructors.

Example
use stm32wlxx_hal::{
    pac,
    spi::{NoMiso, NoMosi, NoSck, Spi},
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
Spi::<pac::SPI2, NoSck, NoMiso, NoMosi>::enable_clock(&mut dp.RCC);
source§

impl<SCK, MISO, MOSI> Spi<SPI1, SCK, MISO, MOSI>where SCK: Spi1Sck, MISO: Spi1Miso, MOSI: Spi1Mosi,

source

pub fn new_spi1_full_duplex( spi: SPI1, pins: (SCK, MISO, MOSI), mode: Mode, div: BaudRate, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new full-duplex master.

Example
use stm32wlxx_hal::{
    cortex_m,
    gpio::PortA,
    pac,
    spi::{BaudRate::Div2, Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_full_duplex(
        dp.SPI1,
        (pa.a5, pa.a6, pa.a7),
        MODE_0,
        Div2,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MISO, MOSI> Spi<SPI2, SCK, MISO, MOSI>where SCK: Spi2Sck, MISO: Spi2Miso, MOSI: Spi2Mosi,

source

pub fn new_spi2_full_duplex( spi: SPI2, pins: (SCK, MISO, MOSI), mode: Mode, div: BaudRate, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new full-duplex master.

Example
use stm32wlxx_hal::{
    cortex_m,
    gpio::PortA,
    pac,
    spi::{BaudRate::Div2, Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_full_duplex(
        dp.SPI1,
        (pa.a5, pa.a6, pa.a7),
        MODE_0,
        Div2,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MISO, MOSI, MISODMA, MOSIDMA> Spi<SPI1, SCK, (MISO, MISODMA), (MOSI, MOSIDMA)>where SCK: Spi1Sck, MISO: Spi1Miso, MOSI: Spi1Mosi, MISODMA: DmaCh, MOSIDMA: DmaCh,

source

pub fn new_spi1_full_duplex_dma( spi: SPI1, pins: (SCK, MISO, MOSI), dmas: (MISODMA, MOSIDMA), mode: Mode, div: BaudRate, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new full-duplex master with DMA transfers.

Example
use stm32wlxx_hal::{
    cortex_m,
    dma::AllDma,
    gpio::PortA,
    pac,
    spi::{BaudRate::Div2, Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let dma = AllDma::split(dp.DMAMUX, dp.DMA1, dp.DMA2, &mut dp.RCC);
let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_full_duplex_dma(
        dp.SPI1,
        (pa.a5, pa.a6, pa.a7),
        (dma.d1.c1, dma.d1.c2),
        MODE_0,
        Div2,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MISO, MOSI, MISODMA, MOSIDMA> Spi<SPI2, SCK, (MISO, MISODMA), (MOSI, MOSIDMA)>where SCK: Spi2Sck, MISO: Spi2Miso, MOSI: Spi2Mosi, MISODMA: DmaCh, MOSIDMA: DmaCh,

source

pub fn new_spi2_full_duplex_dma( spi: SPI2, pins: (SCK, MISO, MOSI), dmas: (MISODMA, MOSIDMA), mode: Mode, div: BaudRate, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new full-duplex master with DMA transfers.

Example
use stm32wlxx_hal::{
    cortex_m,
    dma::AllDma,
    gpio::PortA,
    pac,
    spi::{BaudRate::Div2, Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let dma = AllDma::split(dp.DMAMUX, dp.DMA1, dp.DMA2, &mut dp.RCC);
let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_full_duplex_dma(
        dp.SPI1,
        (pa.a5, pa.a6, pa.a7),
        (dma.d1.c1, dma.d1.c2),
        MODE_0,
        Div2,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MOSI> Spi<SPI1, SCK, NoMiso, MOSI>where SCK: Spi1Sck, MOSI: Spi1Mosi,

source

pub fn new_spi1_mosi_simplex( spi: SPI1, pins: (SCK, MOSI), mode: Mode, div: BaudRate, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new MOSI-simplex master.

Example
use stm32wlxx_hal::{
    cortex_m,
    gpio::PortA,
    pac,
    spi::{BaudRate::Div2, Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_mosi_simplex(
        dp.SPI1,
        (pa.a5, pa.a7),
        MODE_0,
        Div2,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MOSI> Spi<SPI2, SCK, NoMiso, MOSI>where SCK: Spi2Sck, MOSI: Spi2Mosi,

source

pub fn new_spi2_mosi_simplex( spi: SPI2, pins: (SCK, MOSI), mode: Mode, div: BaudRate, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new MOSI-simplex master.

Example
use stm32wlxx_hal::{
    cortex_m,
    gpio::PortA,
    pac,
    spi::{BaudRate::Div2, Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_mosi_simplex(
        dp.SPI1,
        (pa.a5, pa.a7),
        MODE_0,
        Div2,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MOSI, MOSIDMA> Spi<SPI1, SCK, NoMiso, (MOSI, MOSIDMA)>where SCK: Spi1Sck, MOSI: Spi1Mosi, MOSIDMA: DmaCh,

source

pub fn new_spi1_mosi_simplex_dma( spi: SPI1, pins: (SCK, MOSI), dma: MOSIDMA, mode: Mode, div: BaudRate, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new MOSI-simplex master with DMA transfers.

Example
use stm32wlxx_hal::{
    cortex_m,
    dma::AllDma,
    gpio::PortA,
    pac,
    spi::{BaudRate::Div2, Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let dma = AllDma::split(dp.DMAMUX, dp.DMA1, dp.DMA2, &mut dp.RCC);
let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_mosi_simplex_dma(
        dp.SPI1,
        (pa.a5, pa.a7),
        dma.d1.c1,
        MODE_0,
        Div2,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MOSI, MOSIDMA> Spi<SPI2, SCK, NoMiso, (MOSI, MOSIDMA)>where SCK: Spi2Sck, MOSI: Spi2Mosi, MOSIDMA: DmaCh,

source

pub fn new_spi2_mosi_simplex_dma( spi: SPI2, pins: (SCK, MOSI), dma: MOSIDMA, mode: Mode, div: BaudRate, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new MOSI-simplex master with DMA transfers.

Example
use stm32wlxx_hal::{
    cortex_m,
    dma::AllDma,
    gpio::PortA,
    pac,
    spi::{BaudRate::Div2, Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let dma = AllDma::split(dp.DMAMUX, dp.DMA1, dp.DMA2, &mut dp.RCC);
let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_mosi_simplex_dma(
        dp.SPI1,
        (pa.a5, pa.a7),
        dma.d1.c1,
        MODE_0,
        Div2,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MISO> Spi<SPI1, SCK, MISO, NoMosi>where SCK: Spi1Sck, MISO: Spi1Miso,

source

pub fn new_spi1_miso_simplex_slave( spi: SPI1, pins: (SCK, MISO), mode: Mode, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new MOSI-simplex slave.

Example
use stm32wlxx_hal::{
    cortex_m,
    gpio::PortA,
    pac,
    spi::{Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_miso_simplex_slave(
        dp.SPI1,
        (pa.a5, pa.a6),
        MODE_0,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MISO> Spi<SPI2, SCK, MISO, NoMosi>where SCK: Spi2Sck, MISO: Spi2Miso,

source

pub fn new_spi2_miso_simplex_slave( spi: SPI2, pins: (SCK, MISO), mode: Mode, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new MOSI-simplex slave.

Example
use stm32wlxx_hal::{
    cortex_m,
    gpio::PortA,
    pac,
    spi::{Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_miso_simplex_slave(
        dp.SPI1,
        (pa.a5, pa.a6),
        MODE_0,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MISO, MISODMA> Spi<SPI1, SCK, (MISO, MISODMA), NoMosi>where SCK: Spi1Sck, MISO: Spi1Miso, MISODMA: DmaCh,

source

pub fn new_spi1_miso_simplex_slave_dma( spi: SPI1, pins: (SCK, MISO), dma: MISODMA, mode: Mode, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new MISO-simplex slave with DMA transfers.

Example
use stm32wlxx_hal::{
    cortex_m,
    dma::AllDma,
    gpio::PortA,
    pac,
    spi::{Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let dma = AllDma::split(dp.DMAMUX, dp.DMA1, dp.DMA2, &mut dp.RCC);
let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_miso_simplex_slave_dma(
        dp.SPI1,
        (pa.a5, pa.a6),
        dma.d1.c1,
        MODE_0,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SCK, MISO, MISODMA> Spi<SPI2, SCK, (MISO, MISODMA), NoMosi>where SCK: Spi2Sck, MISO: Spi2Miso, MISODMA: DmaCh,

source

pub fn new_spi2_miso_simplex_slave_dma( spi: SPI2, pins: (SCK, MISO), dma: MISODMA, mode: Mode, rcc: &mut RCC, cs: &CriticalSection ) -> Self

Create a new MISO-simplex slave with DMA transfers.

Example
use stm32wlxx_hal::{
    cortex_m,
    dma::AllDma,
    gpio::PortA,
    pac,
    spi::{Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let dma = AllDma::split(dp.DMAMUX, dp.DMA1, dp.DMA2, &mut dp.RCC);
let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_miso_simplex_slave_dma(
        dp.SPI1,
        (pa.a5, pa.a6),
        dma.d1.c1,
        MODE_0,
        &mut dp.RCC,
        cs,
    )
});
source§

impl<SPI, SCK, MISO, MOSI> Spi<SPI, SCK, MISO, MOSI>

source

pub fn free(self) -> (SPI, SCK, MISO, MOSI)

Free the SPI peripheral, pins, and DMA channel(s) from the driver.

Example
use stm32wlxx_hal::{
    dma::AllDma,
    gpio::PortA,
    pac,
    spi::{BaudRate::Div2, Spi, MODE_0},
};

let mut dp = pac::Peripherals::take().unwrap();

let dma = AllDma::split(dp.DMAMUX, dp.DMA1, dp.DMA2, &mut dp.RCC);
let pa = PortA::split(dp.GPIOA, &mut dp.RCC);
let spi = cortex_m::interrupt::free(|cs| {
    Spi::new_spi1_full_duplex_dma(
        dp.SPI1,
        (pa.a5, pa.a6, pa.a7),
        (dma.d1.c1, dma.d1.c2),
        MODE_0,
        Div2,
        &mut dp.RCC,
        cs,
    )
});
// .. use spi
let (spi1, a5, (a6, d1c1), (a7, d1c2)) = spi.free();
source§

impl<SPI: SpiRegs, SCK, MISO, MOSI> Spi<SPI, SCK, MISO, MOSI>

source

pub fn status(&self) -> R

Read the SPI status register.

Trait Implementations§

source§

impl<SPI: Debug, SCK: Debug, MISO: Debug, MOSI: Debug> Debug for Spi<SPI, SCK, MISO, MOSI>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<SPI: SpiRegs, SCK: SpiSck, MISO: SpiMiso, MOSI: SpiMosi, MISODMA: DmaCh, MOSIDMA: DmaCh> Transfer<u8> for Spi<SPI, SCK, (MISO, MISODMA), (MOSI, MOSIDMA)>

§

type Error = Error

Error type
source§

fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error>

Sends words to the slave. Returns the words received from the slave
source§

impl<SPI: SpiRegs, SCK: SpiSck, MISO: SpiMiso, MOSI: SpiMosi> Transfer<u8> for Spi<SPI, SCK, MISO, MOSI>

§

type Error = Error

Error type
source§

fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error>

Sends words to the slave. Returns the words received from the slave
source§

impl<SPI: SpiRegs, SCK: SpiSck, MISO: SpiMiso, MOSI: SpiMosi, MISODMA: DmaCh, MOSIDMA: DmaCh> Write<u8> for Spi<SPI, SCK, (MISO, MISODMA), (MOSI, MOSIDMA)>

§

type Error = Error

Error type
source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Sends words to the slave, ignoring all the incoming words
source§

impl<SPI: SpiRegs, SCK: SpiSck, MISO: SpiMiso, MISODMA: DmaCh> Write<u8> for Spi<SPI, SCK, (MISO, MISODMA), NoMosi>

§

type Error = Error

Error type
source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Sends words to the slave, ignoring all the incoming words
source§

impl<SPI: SpiRegs, SCK: SpiSck, MISO: SpiMiso, MOSI: SpiMosi> Write<u8> for Spi<SPI, SCK, MISO, MOSI>

§

type Error = Error

Error type
source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Sends words to the slave, ignoring all the incoming words
source§

impl<SPI: SpiRegs, SCK: SpiSck, MOSI: SpiMosi, MOSIDMA: DmaCh> Write<u8> for Spi<SPI, SCK, NoMiso, (MOSI, MOSIDMA)>

§

type Error = Error

Error type
source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Sends words to the slave, ignoring all the incoming words
source§

impl<SPI: SpiRegs, SCK: SpiSck, MOSI: SpiMosi> Write<u8> for Spi<SPI, SCK, NoMiso, MOSI>

§

type Error = Error

Error type
source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Sends words to the slave, ignoring all the incoming words
source§

impl<SPI: SpiRegs, SCK: SpiSck, MISO: SpiMiso, MOSI: SpiMosi> FullDuplex<u8> for Spi<SPI, SCK, MISO, MOSI>

§

type Error = Error

An enumeration of SPI errors
source§

fn read(&mut self) -> Result<u8, Self::Error>

Reads the word stored in the shift register Read more
source§

fn send(&mut self, word: u8) -> Result<(), Self::Error>

Sends a word to the slave

Auto Trait Implementations§

§

impl<SPI, SCK, MISO, MOSI> RefUnwindSafe for Spi<SPI, SCK, MISO, MOSI>where MISO: RefUnwindSafe, MOSI: RefUnwindSafe, SCK: RefUnwindSafe, SPI: RefUnwindSafe,

§

impl<SPI, SCK, MISO, MOSI> Send for Spi<SPI, SCK, MISO, MOSI>where MISO: Send, MOSI: Send, SCK: Send, SPI: Send,

§

impl<SPI, SCK, MISO, MOSI> Sync for Spi<SPI, SCK, MISO, MOSI>where MISO: Sync, MOSI: Sync, SCK: Sync, SPI: Sync,

§

impl<SPI, SCK, MISO, MOSI> Unpin for Spi<SPI, SCK, MISO, MOSI>where MISO: Unpin, MOSI: Unpin, SCK: Unpin, SPI: Unpin,

§

impl<SPI, SCK, MISO, MOSI> UnwindSafe for Spi<SPI, SCK, MISO, MOSI>where MISO: UnwindSafe, MOSI: UnwindSafe, SCK: UnwindSafe, SPI: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.