|
STM32 core 3.0.1-dev
Arduino core for STM32 based boards: API reference
|
← STM32duino documentation
|
STM32 hardware UART. More...
#include <Serial.h>
Public Member Functions | |
| Uart (pin_size_t _rx, pin_size_t _tx, pin_size_t _rts=NUM_DIGITAL_PINS, pin_size_t _cts=NUM_DIGITAL_PINS) | |
| Create a UART from Arduino digital pin numbers. | |
| Uart (PinName _rx, PinName _tx, PinName _rts=NC, PinName _cts=NC) | |
| Create a UART from STM32 pin names. | |
| Uart (void *peripheral, HalfDuplexMode_t halfDuplex=HALF_DUPLEX_DISABLED) | |
| Create a UART from an STM32 USART/UART peripheral. | |
| Uart (pin_size_t _rxtx) | |
| Create a half-duplex UART on a single digital pin. | |
| Uart (PinName _rxtx) | |
| Create a half-duplex UART on a single STM32 pin. | |
| void | begin (unsigned long baud) override |
| Start the UART with 8 data bits, no parity and 1 stop bit (SERIAL_8N1). | |
| void | begin (unsigned long baud, uint16_t config) override |
| Start the UART with the given baud rate and frame format. | |
| void | end () override |
| Wait for pending transmission, stop the UART, release its pins and clear the receive buffer. | |
| int | available (void) override |
| Get the number of bytes available to read. | |
| int | peek (void) override |
| Read the next byte without removing it from the receive buffer. | |
| int | read (void) override |
| Read and remove the next byte from the receive buffer. | |
| void | flush () override |
| Wait until all queued bytes are transmitted. | |
| size_t | write (uint8_t c) override |
| Write one byte. | |
| operator bool () override | |
| Check whether the UART is started. | |
| int | availableForWrite (void) |
| Get the number of bytes that can be written without blocking. | |
| void | flush (uint32_t timeout) |
| Wait until all queued bytes are transmitted, or until a timeout elapses. | |
| size_t | write (unsigned long n) |
| Write one byte, truncating the value to 8 bits. | |
| size_t | write (long n) |
| Write one byte, truncating the value to 8 bits. | |
| size_t | write (unsigned int n) |
| Write one byte, truncating the value to 8 bits. | |
| size_t | write (int n) |
| Write one byte, truncating the value to 8 bits. | |
| size_t | write (const uint8_t *buffer, size_t size) |
| Write a buffer of bytes. | |
| void | setRx (pin_size_t _rx) |
| Set the RX pin by Arduino pin number. | |
| void | setTx (pin_size_t _tx) |
| Set the TX pin by Arduino pin number. | |
| void | setRx (PinName _rx) |
| Set the RX pin by STM32 pin name. | |
| void | setTx (PinName _tx) |
| Set the TX pin by STM32 pin name. | |
| void | setRts (pin_size_t _rts) |
| Enable hardware RTS flow control on a digital pin. | |
| void | setCts (pin_size_t _cts) |
| Enable hardware CTS flow control on a digital pin. | |
| void | setRtsCts (pin_size_t _rts, pin_size_t _cts) |
| Enable hardware RTS and CTS flow control on digital pins. | |
| void | setRts (PinName _rts) |
| Enable hardware RTS flow control on an STM32 pin. | |
| void | setCts (PinName _cts) |
| Enable hardware CTS flow control on an STM32 pin. | |
| void | setRtsCts (PinName _rts, PinName _cts) |
| Enable hardware RTS and CTS flow control on STM32 pins. | |
| void | setHalfDuplex (void) |
| Enable half-duplex mode by setting the RX pin to NC. | |
| bool | isHalfDuplex (void) const |
| Check whether the UART is in half-duplex mode. | |
| void | enableHalfDuplexRx (void) |
| Enable reception in half-duplex mode after the pending transmission ends. | |
| void | setRxInvert (void) |
| Invert the RX line in hardware. | |
| void | setTxInvert (void) |
| Invert the TX line in hardware. | |
| void | setDataInvert (void) |
| Invert the data bits in hardware. | |
| UART_HandleTypeDef * | getHandle (void) |
| Get the underlying HAL UART handle. | |
Static Public Member Functions | |
| static void | _rx_complete_irq (serial_t *obj) |
| RX interrupt handler. | |
| static int | _tx_complete_irq (serial_t *obj) |
| TX interrupt handler. | |
Protected Attributes | |
| bool | _written |
| Has any byte been written to the UART since begin(). | |
| bool | _rx_invert |
| Hardware inversion of the RX line, set by setRxInvert(). | |
| bool | _tx_invert |
| Hardware inversion of the TX line, set by setTxInvert(). | |
| bool | _data_invert |
| Hardware inversion of the data bits, set by setDataInvert(). | |
| unsigned char | _rx_buffer [SERIAL_RX_BUFFER_SIZE] |
| Receive ring buffer, filled by _rx_complete_irq() and emptied by read(). | |
| unsigned char | _tx_buffer [SERIAL_TX_BUFFER_SIZE] |
| Transmit ring buffer, filled by write() and emptied by _tx_complete_irq(). | |
| serial_t | _serial |
| Low-level serial object: pins, ring buffer indexes and HAL handle. | |
Friends | |
| class | STM32LowPower |
STM32 hardware UART.
Implements the Arduino Stream and HardwareSerial API.
Use one of the constructors to bind a UART to pins or to a peripheral, then call begin().
| Uart::Uart | ( | pin_size_t | _rx, |
| pin_size_t | _tx, | ||
| pin_size_t | _rts = NUM_DIGITAL_PINS, |
||
| pin_size_t | _cts = NUM_DIGITAL_PINS |
||
| ) |
Create a UART from Arduino digital pin numbers.
| _rx | Digital pin used for RX. |
| _tx | Digital pin used for TX. |
| _rts | Digital pin used for RTS flow control, NUM_DIGITAL_PINS if unused. |
| _cts | Digital pin used for CTS flow control, NUM_DIGITAL_PINS if unused. |
| Uart::Uart | ( | PinName | _rx, |
| PinName | _tx, | ||
| PinName | _rts = NC, |
||
| PinName | _cts = NC |
||
| ) |
Create a UART from STM32 pin names.
| _rx | Pin used for RX. |
| _tx | Pin used for TX. |
| _rts | Pin used for RTS flow control, NC if unused. |
| _cts | Pin used for CTS flow control, NC if unused. |
| Uart::Uart | ( | void * | peripheral, |
| HalfDuplexMode_t | halfDuplex = HALF_DUPLEX_DISABLED |
||
| ) |
Create a UART from an STM32 USART/UART peripheral.
Pins are taken from the variant.
| peripheral | USART/UART peripheral instance, e.g. USART1. |
| halfDuplex | HALF_DUPLEX_ENABLED to use the TX pin only. |
| Uart::Uart | ( | pin_size_t | _rxtx | ) |
Create a half-duplex UART on a single digital pin.
The pin is used as TX and RX is NC.
| _rxtx | Digital pin used for TX. |
| Uart::Uart | ( | PinName | _rxtx | ) |
Create a half-duplex UART on a single STM32 pin.
The pin is used as TX and RX is NC.
| _rxtx | Pin used for TX. |
|
static |
RX interrupt handler.
Stores the received byte in the receive buffer.
| obj | UART object that received the byte. |
|
static |
TX interrupt handler.
Starts the next chunk of queued data, if any.
| obj | UART object whose transfer completed. |
|
override |
Get the number of bytes available to read.
| int Uart::availableForWrite | ( | void | ) |
Get the number of bytes that can be written without blocking.
|
inlineoverride |
Start the UART with 8 data bits, no parity and 1 stop bit (SERIAL_8N1).
| baud | Baud rate in bits per second. |
|
override |
Start the UART with the given baud rate and frame format.
| baud | Baud rate in bits per second. |
| config | Frame format, e.g. SERIAL_8N1 or SERIAL_8E1. |
| void Uart::flush | ( | uint32_t | timeout | ) |
Wait until all queued bytes are transmitted, or until a timeout elapses.
| timeout | Maximum wait in milliseconds. 0 waits without limit. On timeout, the pending transmit data is discarded. |
|
inline |
Get the underlying HAL UART handle.
| bool Uart::isHalfDuplex | ( | void | ) | const |
Check whether the UART is in half-duplex mode.
|
inlineoverride |
Check whether the UART is started.
|
override |
Read the next byte without removing it from the receive buffer.
|
override |
Read and remove the next byte from the receive buffer.
| void Uart::setCts | ( | pin_size_t | _cts | ) |
Enable hardware CTS flow control on a digital pin.
Call before begin().
| _cts | Digital pin used for CTS. |
| void Uart::setCts | ( | PinName | _cts | ) |
Enable hardware CTS flow control on an STM32 pin.
Call before begin().
| _cts | Pin used for CTS. |
| void Uart::setDataInvert | ( | void | ) |
Invert the data bits in hardware.
Call before begin().
| void Uart::setHalfDuplex | ( | void | ) |
Enable half-duplex mode by setting the RX pin to NC.
Call before begin().
| void Uart::setRts | ( | pin_size_t | _rts | ) |
Enable hardware RTS flow control on a digital pin.
Call before begin().
| _rts | Digital pin used for RTS. |
| void Uart::setRts | ( | PinName | _rts | ) |
Enable hardware RTS flow control on an STM32 pin.
Call before begin().
| _rts | Pin used for RTS. |
| void Uart::setRtsCts | ( | pin_size_t | _rts, |
| pin_size_t | _cts | ||
| ) |
Enable hardware RTS and CTS flow control on digital pins.
Call before begin().
| _rts | Digital pin used for RTS. |
| _cts | Digital pin used for CTS. |
| void Uart::setRtsCts | ( | PinName | _rts, |
| PinName | _cts | ||
| ) |
Enable hardware RTS and CTS flow control on STM32 pins.
Call before begin().
| _rts | Pin used for RTS. |
| _cts | Pin used for CTS. |
| void Uart::setRx | ( | pin_size_t | _rx | ) |
| void Uart::setRx | ( | PinName | _rx | ) |
| void Uart::setRxInvert | ( | void | ) |
Invert the RX line in hardware.
Call before begin().
| void Uart::setTx | ( | pin_size_t | _tx | ) |
| void Uart::setTx | ( | PinName | _tx | ) |
| void Uart::setTxInvert | ( | void | ) |
Invert the TX line in hardware.
Call before begin().
| size_t Uart::write | ( | const uint8_t * | buffer, |
| size_t | size | ||
| ) |
Write a buffer of bytes.
| buffer | Data to write. |
| size | Number of bytes in buffer. |
|
inline |
Write one byte, truncating the value to 8 bits.
| n | Value to write. |
|
inline |
Write one byte, truncating the value to 8 bits.
| n | Value to write. |
|
override |
Write one byte.
| c | Byte to write. |
|
inline |
Write one byte, truncating the value to 8 bits.
| n | Value to write. |
|
inline |
Write one byte, truncating the value to 8 bits.
| n | Value to write. |
|
protected |
Hardware inversion of the data bits, set by setDataInvert().
Applied by begin().
|
protected |
Hardware inversion of the RX line, set by setRxInvert().
Applied by begin().
|
protected |
Hardware inversion of the TX line, set by setTxInvert().
Applied by begin().
|
protected |