pub struct Serial<USART, PINS> {
    pub tx: Tx<USART>,
    pub rx: Rx<USART>,
    pub token: ReleaseToken<USART, PINS>,
}
Expand description

Serial abstraction

Fields§

§tx: Tx<USART>§rx: Rx<USART>§token: ReleaseToken<USART, PINS>

Implementations§

Configures the serial interface and creates the interface struct.

Bps is the baud rate of the interface.

Clocks passes information about the current frequencies of the clocks. The existence of the struct ensures that the clock settings are fixed.

The serial struct takes ownership over the USARTX device registers and the specified PINS

MAPR and APBX are register handles which are passed for configuration. (MAPR is used to map the USART to the corresponding pins. APBX is used to reset the USART.)

Reconfigure the USART instance.

If a transmission is currently in progress, this returns nb::Error::WouldBlock.

Returns ownership of the borrowed register handles

Examples

Basic usage:

let mut serial = Serial::new(usart, (tx_pin, rx_pin), &mut afio.mapr, 9600.bps(), &clocks);

// You can split the `Serial`
let Serial { tx, rx, token } = serial;

// You can reunite the `Serial` back
let serial = Serial { tx, rx, token };

// Release `Serial`
let (usart, (tx_pin, rx_pin)) = serial.release();

Separates the serial struct into separate channel objects for sending (Tx) and receiving (Rx)

If in the future it will be necessary to free up resources, then you need to use a different method of separation:

let Serial { tx, rx, token } = serial;

Starts listening to the USART by enabling the Received data ready to be read (RXNE) interrupt and Transmit data register empty (TXE) interrupt

Stops listening to the USART by disabling the Received data ready to be read (RXNE) interrupt and Transmit data register empty (TXE) interrupt

Returns true if the line idle status is set

Returns true if the tx register is empty (and can accept data)

Returns true if the rx register is not empty (and can be read)

Clear idle line interrupt flag

Trait Implementations§

Read error
Reads a single word from the serial interface
Read error
Reads a single word from the serial interface
Write error
Writes a single word to the serial interface
Ensures that none of the previously written words are still buffered
The type of error that can occur when writing
Writes a slice, blocking until everything has been written Read more
Block until the serial interface has sent all buffered words
Write error
Writes a single word to the serial interface
Ensures that none of the previously written words are still buffered
The type of error that can occur when writing
Writes a slice, blocking until everything has been written Read more
Block until the serial interface has sent all buffered words
Writes a string slice into this writer, returning whether the write succeeded. Read more
Writes a char into this writer, returning whether the write succeeded. Read more
Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.