Struct stm32_hal2::usart::Usart

source ·
pub struct Usart<R> {
    pub regs: R,
    /* private fields */
}
Expand description

Represents the USART peripheral, for serial communications.

Fields§

§regs: R

Implementations§

source§

impl<R> Usart<R>
where R: Deref<Target = RegisterBlock> + RccPeriph + BaudPeriph,

source

pub fn new(regs: R, baud: u32, config: UsartConfig, clock_cfg: &Clocks) -> Self

Initialize a U[s]ART peripheral, including configuration register writes, and enabling and resetting its RCC peripheral clock. baud is the baud rate, in bytes-per-second.

source

pub fn enable(&mut self)

Enable this U[s]ART peripheral.

source

pub fn disable(&mut self)

Disable this U[s]ART peripheral.

source

pub fn set_baud( &mut self, baud: u32, clock_cfg: &Clocks ) -> Result<(), UartError>

Set the BAUD rate. Called during init, and can be called later to change BAUD during program execution.

source

pub fn write(&mut self, data: &[u8]) -> Result<(), UartError>

Transmit data, as a sequence of u8. See L44 RM, section 38.5.2: “Character transmission procedure”

source

pub fn write_one(&mut self, word: u8)

Write a single word, without waiting until ready for the next. Compared to the write() function, this does not block.

source

pub fn read(&mut self, buf: &mut [u8]) -> Result<(), UartError>

Receive data into a u8 buffer. See L44 RM, section 38.5.3: “Character reception procedure”

source

pub fn read_one(&mut self) -> u8

Read a single word, without waiting until ready for the next. Compared to the read() function, this does not block.

source

pub unsafe fn write_dma( &mut self, buf: &[u8], channel: DmaChannel, channel_cfg: ChannelCfg, dma_periph: DmaPeriph )

Transmit data using DMA. (L44 RM, section 38.5.15) Note that the channel argument is unused on F3 and L4, since it is hard-coded, and can’t be configured using the DMAMUX peripheral. (dma::mux() fn).

source

pub unsafe fn read_dma( &mut self, buf: &mut [u8], channel: DmaChannel, channel_cfg: ChannelCfg, dma_periph: DmaPeriph )

Receive data using DMA. (L44 RM, section 38.5.15; G4 RM section 37.5.19. Note that the channel argument is unused on F3 and L4, since it is hard-coded, and can’t be configured using the DMAMUX peripheral. (dma::mux() fn).

source

pub fn enable_interrupt(&mut self, interrupt: UsartInterrupt)

Enable a specific type of interrupt. See G4 RM, Table 349: USART interrupt requests. If Some, the inner value of CharDetect sets the address of the char to match. If None, the interrupt is enabled without changing the char to match.

source

pub fn disable_interrupt(&mut self, interrupt: UsartInterrupt)

Disable a specific type of interrupt. See G4 RM, Table 349: USART interrupt requests. Note that the inner value of CharDetect doesn’t do anything here.

source

pub fn read_status(&self) -> u32

Print the (raw) contents of the status register.

source

pub fn clear_interrupt(&mut self, interrupt: UsartInterrupt)

Clears the interrupt pending flag for a specific type of interrupt. Note that it can also clear error flags, like Overrun and framing errors. See G4 RM, Table 349: USART interrupt requests. Note that the inner value of CharDetect doesn’t do anything here.

source

pub fn check_status_flag(&mut self, flag: UsartInterrupt) -> bool

Checks if a given status flag is set. Returns true if the status flag is set. Note that this preforms a read each time called. If checking multiple flags, this isn’t optimal.

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for Usart<R>
where R: RefUnwindSafe,

§

impl<R> Send for Usart<R>
where R: Send,

§

impl<R> Sync for Usart<R>
where R: Sync,

§

impl<R> Unpin for Usart<R>
where R: Unpin,

§

impl<R> UnwindSafe for Usart<R>
where R: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where 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 T
where 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.