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.
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 Event
s.
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.
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.
pub fn read_exact<B, C>(self, buffer: B, channel: C) -> Transfer<B, C, Self> where
Self: OnChannel<C>,
B: WriteBuffer<Word = u8> + 'static,
C: Channel,
pub fn read_exact<B, C>(self, buffer: B, channel: C) -> Transfer<B, C, Self> where
Self: OnChannel<C>,
B: WriteBuffer<Word = u8> + 'static,
C: Channel,
Fill the buffer with received data using DMA.
Trait Implementations
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()
.
…
Enable DMA on the target
Disable DMA on the target
Writes a string slice into this writer, returning whether the write succeeded. Read more
type Error = Infallible
type Error = Infallible
Write error
Ensures that none of the previously written words are still buffered