embassy-stm32

Crates

git

Versions

stm32h733zg

Flavors

embassy_stm32::usart

Struct UartRx

Source
pub struct UartRx<'d, M: Mode> { /* private fields */ }
Expand description

Rx-only UART Driver.

Can be obtained from Uart::split, or can be constructed independently, if you do not need the transmitting half of the driver.

§Notes on embedded_io::Read

embedded_io::Read requires guarantees that this struct cannot provide:

  • Any data received between calls to UartRx::read or UartRx::blocking_read will be thrown away, as UartRx is unbuffered. Users of embedded_io::Read are likely to not expect this behavior (for instance if they read multiple small chunks in a row).
  • UartRx::read and UartRx::blocking_read only return once the entire buffer has been filled, whereas embedded_io::Read requires us to fill the buffer with what we already received, and only block/wait until the first byte arrived.
    While UartRx::read_until_idle does return early, it will still eagerly wait for data until the buffer is full or no data has been transmitted in a while, which may not be what users of embedded_io::Read expect.

UartRx::into_ring_buffered can be called to equip UartRx with a buffer, that it can then use to store data received between calls to read, provided you are using DMA already.

Alternatively, you can use BufferedUartRx, which is interrupt-based and which can also store data received between calls.

Also see this github comment.

Implementations§

Source§

impl<'d> UartRx<'d, Async>

Source

pub fn into_ring_buffered(self, dma_buf: &'d mut [u8]) -> RingBufferedUartRx<'d>

Turn the UartRx into a buffered uart which can continously receive in the background without the possibility of losing bytes. The dma_buf is a buffer registered to the DMA controller, and must be large enough to prevent overflows.

Source§

impl<'d> UartRx<'d, Async>

Source

pub fn new<T: Instance>( peri: impl Peripheral<P = T> + 'd, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>

Create a new rx-only UART with no hardware flow control.

Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power.

Source

pub fn new_with_rts<T: Instance>( peri: impl Peripheral<P = T> + 'd, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, rts: impl Peripheral<P = impl RtsPin<T>> + 'd, rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>

Create a new rx-only UART with a request-to-send pin

Source

pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error>

Initiate an asynchronous UART read

Source

pub async fn read_until_idle( &mut self, buffer: &mut [u8], ) -> Result<usize, Error>

Initiate an asynchronous read with idle line detection enabled

Source§

impl<'d> UartRx<'d, Blocking>

Source

pub fn new_blocking<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>

Create a new rx-only UART with no hardware flow control.

Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power.

Source

pub fn new_blocking_with_rts<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, rts: impl Peripheral<P = impl RtsPin<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>

Create a new rx-only UART with a request-to-send pin

Source§

impl<'d, M: Mode> UartRx<'d, M>

Source

pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError>

Reconfigure the driver

Source

pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error>

Perform a blocking read into buffer

Source

pub fn set_baudrate(&self, baudrate: u32) -> Result<(), ConfigError>

Set baudrate

Trait Implementations§

Source§

impl<'d, M: Mode> Drop for UartRx<'d, M>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'d, M: Mode> ErrorType for UartRx<'d, M>

Source§

type Error = Error

Error type
Source§

impl<'d, M: Mode> Read for UartRx<'d, M>

Source§

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

Reads a single word from the serial interface
Source§

impl<'d, M: Mode> SetConfig for UartRx<'d, M>

Source§

type Config = Config

The configuration type used by this driver.
Source§

type ConfigError = ConfigError

The error type that can occur if set_config fails.
Source§

fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError>

Set the configuration of the driver.
Source§

impl<'d, M: Mode> Read<u8> for UartRx<'d, M>

Source§

type Error = Error

Read error
Source§

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

Reads a single word from the serial interface

Auto Trait Implementations§

§

impl<'d, M> Freeze for UartRx<'d, M>

§

impl<'d, M> !RefUnwindSafe for UartRx<'d, M>

§

impl<'d, M> Send for UartRx<'d, M>
where M: Send,

§

impl<'d, M> Sync for UartRx<'d, M>
where M: Sync,

§

impl<'d, M> Unpin for UartRx<'d, M>
where M: Unpin,

§

impl<'d, M> !UnwindSafe for UartRx<'d, M>

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>,

Source§

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>,

Source§

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.