embassy-stm32

Crates

git

Versions

stm32l486rg

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

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.