Struct stm32f3xx_hal::serial::Serial[][src]

pub struct Serial<Usart, Pins> { /* fields omitted */ }
Expand description

Serial abstraction

This is an abstraction of the UART peripheral intended to be used for standard duplex serial communication.

Implementations

Configures a USART peripheral to provide serial communication

Get access to the underlying register block.

Safety

This function is not memory unsafe per se, but does not guarantee anything about assumptions of invariants made in this implementation.

Changing specific options can lead to un-expected behavior and nothing is guaranteed.

Releases the USART peripheral and associated pins

Joins previously Serial::split() serial.

This is often needed to access methods only implemented for Serial but not for Tx nor Rx.

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

(tx, rx) = Serial::new(dp.USART1, ...).split();

// Do something with tx and rx

serial = Serial::join(tx, rx);

Serial read out of the read register

No error handling and no additional side-effects, besides the implied side-effects when reading out the RDR register. Handling errors has to be done manually. This can be done, by checking the triggered events via Serial::triggered_events.

Returns None if the hardware is busy.

Check if the USART peripheral is busy.

This can be useful to block on to synchronize between peripheral and CPU because of the asynchronous nature of the peripheral.

Obtain the associated interrupt number for the serial peripheral.

Used to unmask / enable the interrupt with cortex_m::peripheral::NVIC::unmask(). This is useful for all cortex_m::peripheral::INTERRUPT functions.

Note

This is the easier alternative to obatain the interrupt for:

use cortex_m::peripheral::INTERRUPT;
use stm32f3xx_hal::pac::USART1;
use stm32f3xx_hal::interrupt::InterruptNumber;

const INTERRUPT: Interrupt = <USART1 as InterruptNumber>::INTERRUPT;

though this function can not be used in a const context.

Enable the interrupt for the specified Event.

Disable the interrupt for the specified Event.

Enable or disable the interrupt for the specified Event.

Enable or disable interrupt for the specified Events.

Like Serial::configure_interrupt, but instead using an enumset. The corresponding interrupt for every Event in the set will be enabled, every other interrupt will be disabled.

Check if an interrupt event happend.

Get an EnumSet of all fired interrupt events.

Examples

This allows disabling all fired event at once, via the enum set abstraction, like so

for event in serial.events() {
    serial.listen(event, false);
}

Clear the given interrupt event flag.

Clear all interrupt events.

Enable or disable overrun detection

When overrun detection is disabled and new data is received while the Event::ReceiveDataRegisterNotEmpty flag is still set, the Event::OverrunError flag is not set and the new received data overwrites the previous content of the RDR register.

Configuring the UART to match each received character, with the configured one.

If the character is matched Event::CharacterMatch is generated, which can fire an interrupt, if enabled via Serial::configure_interrupt()

Read out the configured match character.

Set the receiver timeout value.

The RTOF flag (Event::ReceiverTimeout) is set if, after the last received character, no new start bit is detected for more than the receiver timeout value, where the value is being a counter, which is decreased by the configured baud rate.

A simple calculation might be time_per_counter_value = 1 / configured_baud_rate

Note
  • If the value is None, the receiver timeout feature is disabled.
  • This value must only be programmed once per received character.
  • Can be written on the fly. If the new value is lower than or equal to the counter, the RTOF flag is set.
  • Values higher than 24 bits are truncated to 24 bit max (16_777_216).

Read out the currently set timeout value

The relationship between the unit value and time is described in Serial::receiver_timeout.

  • If the value is None, the receiver timeout feature is disabled.

Fill the buffer with received data using DMA.

Transmit all data in the buffer using DMA.

Splits the Serial abstraction into a transmitter and a receiver half.

This allows using Tx and Rx related actions to be handled independently and even use these safely in different contexts (like interrupt routines) without needing to do synchronization work between them.

Splits the Serial abstraction into a transmitter and a receiver half.

This allows using Tx and Rx related actions to be handled independently and even use these safely in different contexts (like interrupt routines) without needing to do synchronization work between them.

Splits the Serial abstraction into a transmitter and a receiver half.

This allows using Tx and Rx related actions to be handled independently and even use these safely in different contexts (like interrupt routines) without needing to do synchronization work between them.

Splits the Serial abstraction into a transmitter and a receiver half.

This allows using Tx and Rx related actions to be handled independently and even use these safely in different contexts (like interrupt routines) without needing to do synchronization work between them.

Splits the Serial abstraction into a transmitter and a receiver half.

This allows using Tx and Rx related actions to be handled independently and even use these safely in different contexts (like interrupt routines) without needing to do synchronization work between them.

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Getting back an error means that the error is defined as “handled”:

This implementation has the side effect for error handling, that the Event flag of the returned Error is cleared.

This might be a problem, because if an interrupt is enabled for this particular flag, the interrupt handler might not have the chance to find out from which flag the interrupt originated.

So this function is only intended to be used for direct error handling and not leaving it up to the interrupt handler.

To read out the content of the read register without internal error handling, use Serial::raw_read(). …

Read error

Enable DMA on the target

Disable DMA on the target

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

Write error

Ensures that none of the previously written words are still buffered

Writes a single word to the serial interface

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

Performs the conversion.

Performs the conversion.

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.

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