I/O Stream UART#

I/O Stream UART.

Overview#

UART layer provides a set of standard APIs that can be used with all type of UART interface.

Initialization#

Each UART stream type provides its initalization with parameters specific to them. Note

  • Each UART stream requires a dedicated (L)DMA channel through DMADRV.

Configuration#

RX Buffer Size#

The SL_IOSTREAM_<Peripheral>_<Instance>_RX_BUFFER_SIZE parameter should be chosen based on the time it takes for the MCU to consume the RX buffer, otherwise flow control will have to be asserted to avoid data loss. If hardware flow control is unavailable, data will be dropped.

Let's assume that the MCU is able to call the IOStream Read function with a maximum delay of 1ms. We have:

(1) MaximumDelay = RXBufferSize * TimePerDatum

Where TimePerDatum is defined by (#startBits + #dataBits + #parityBits + #stopBits)/BaudRate.
With default settings, we have 1 start & stop bit, 8 data bits and no parity.

Rewriting (1), we have:

(2) MaximumDelay = RXBufferSize * 10/BaudRate <=> RXBufferSize = MaximumDelay*Baudrate/10

With a baudrate of 921,600 and a maximum consumption delay of 1ms, we have
a recommended RXBufferSize of:

(3) RXBufferSize = 0.001*921600/10 = 93Bytes

This should ensure that flow control does not have to be asserted, slowing down the bus and if unavailable, that no data will be dropped.

Baudrate#

IOStream UART leverages the DMA in order consume data from the UART peripheral. When user reads data from IOStream, the internal reception buffer gets more room for receiving new data. However, this update process pauses the DMA, meaning that any new data coming from the bus will remain in the UART peripheral's FIFO. If too much data is received before the update can complete, hardware flow control will have be enforces, or data will be dropped if unavailable.

Measurements show that the DMA update executes in ~23.7us with -O3 optimization (-Os gives slightly worst performance of ~32.7us). With these, the following equations can be followed to understand the maximum baudrate supported by the current design, when no flow control is available:

The number of bytes received during the ring buffer update is given by:

(1) UpdateTime = FIFOSize * TimePerDatum

Where TimePerDatum is defined by (#startBits + #dataBits + #parityBits + #stopBits)/BaudRate.
With default settings, we have 1 start & stop bit, 8 data bits and no parity.
Rewriting (1), we have:

(2) UpdateTime = FIFOSize * 10/Baudrate

For USART, we have a FIFO of size 2. This means that for an update time of
23.7us, we have a max baudrate of:

(3) 23.7 = 2 * 10/Baudrate <=> Baudrate = 2*10/23.7 = 843,881Baud.

The maximum "real" baudrate is then 460,800 Baud, otherwise hardware flow control will have to be asserted, or data will be dropped.

To achieve higher throughput without flow control assertion, users can use the EUSART peripheral, which boasts a 16Bytes FIFO, allow for baudrate of upwards of 921600 without data loss with no hardware flow control.

Modules#

sl_iostream_uart_t

sl_iostream_dma_config_t

sl_iostream_dma_context_t

sl_iostream_uart_config_t

sl_iostream_uart_context_t

Functions#

sl_status_t
sl_iostream_uart_deinit(sl_iostream_uart_t *iostream_uart)

UART Stream De-init.

void
sl_iostream_uart_set_auto_cr_lf(sl_iostream_uart_t *iostream_uart, bool on)

Configure Automatic line conversion.

bool
sl_iostream_uart_get_auto_cr_lf(sl_iostream_uart_t *iostream_uart)

Get Automatic line conversion.

void
sl_iostream_uart_prepare_for_sleep(sl_iostream_uart_t *iostream_uart)

Set next byte detect IRQ.

void
sl_iostream_uart_wakeup(sl_iostream_uart_t *iostream_uart)

Restore the UART for normal operation after wakeup.

void
sl_iostream_uart_set_rx_energy_mode_restriction(sl_iostream_uart_t *iostream_uart, bool on)

Add or remove energy mode restriction to enable/disable reception when the system goes to sleep.

bool
sl_iostream_uart_get_rx_energy_mode_restriction(sl_iostream_uart_t *iostream_uart)

Get reception energy mode restriction configuration.

void
sl_iostream_uart_set_read_block(sl_iostream_uart_t *iostream_uart, bool on)

Configure Read blocking mode.

bool
sl_iostream_uart_get_read_block(sl_iostream_uart_t *iostream_uart)

Get read API block configuration.

Macros#

#define

uart flow control none

#define

uart flow control software

#define
UARTXON 0x11

uartx on

#define

uartx off

Function Documentation#

sl_iostream_uart_deinit#

sl_status_t sl_iostream_uart_deinit (sl_iostream_uart_t * iostream_uart)

UART Stream De-init.

Parameters
[in]iostream_uart

UART stream object.

Returns

  • Status result


Definition at line 248 of file platform/service/iostream/inc/sl_iostream_uart.h

sl_iostream_uart_set_auto_cr_lf#

void sl_iostream_uart_set_auto_cr_lf (sl_iostream_uart_t * iostream_uart, bool on)

Configure Automatic line conversion.

Parameters
[in]iostream_uart

UART stream object.

[in]on

If true, automatic LF to CRLF conversion will be enabled.


Definition at line 263 of file platform/service/iostream/inc/sl_iostream_uart.h

sl_iostream_uart_get_auto_cr_lf#

bool sl_iostream_uart_get_auto_cr_lf (sl_iostream_uart_t * iostream_uart)

Get Automatic line conversion.

Parameters
[in]iostream_uart

UART stream object.

Returns

  • Auto-conversion mode.


Definition at line 276 of file platform/service/iostream/inc/sl_iostream_uart.h

sl_iostream_uart_prepare_for_sleep#

void sl_iostream_uart_prepare_for_sleep (sl_iostream_uart_t * iostream_uart)

Set next byte detect IRQ.

Parameters
[in]iostream_uart

UART stream object.


Definition at line 287 of file platform/service/iostream/inc/sl_iostream_uart.h

sl_iostream_uart_wakeup#

void sl_iostream_uart_wakeup (sl_iostream_uart_t * iostream_uart)

Restore the UART for normal operation after wakeup.

Parameters
[in]iostream_uart

UART stream object.


Definition at line 294 of file platform/service/iostream/inc/sl_iostream_uart.h

sl_iostream_uart_set_rx_energy_mode_restriction#

void sl_iostream_uart_set_rx_energy_mode_restriction (sl_iostream_uart_t * iostream_uart, bool on)

Add or remove energy mode restriction to enable/disable reception when the system goes to sleep.

Parameters
[in]iostream_uart

UART context.

[in]on

If true, will be able to receive data when sleeping. i.e it affects the lowest power level that the system can go. Otherwise, it might not be possible to receive data when sleeping.


Definition at line 306 of file platform/service/iostream/inc/sl_iostream_uart.h

sl_iostream_uart_get_rx_energy_mode_restriction#

bool sl_iostream_uart_get_rx_energy_mode_restriction (sl_iostream_uart_t * iostream_uart)

Get reception energy mode restriction configuration.

Parameters
[in]iostream_uart

UART context.

Returns

  • Sleep configuration.


Definition at line 319 of file platform/service/iostream/inc/sl_iostream_uart.h

sl_iostream_uart_set_read_block#

void sl_iostream_uart_set_read_block (sl_iostream_uart_t * iostream_uart, bool on)

Configure Read blocking mode.

Parameters
[in]iostream_uart

UART context.

[in]on

If false, the read API will be non-blocking. Otherwise the read API will block until data is received.


Definition at line 334 of file platform/service/iostream/inc/sl_iostream_uart.h

sl_iostream_uart_get_read_block#

bool sl_iostream_uart_get_read_block (sl_iostream_uart_t * iostream_uart)

Get read API block configuration.

Parameters
[in]iostream_uart

UART context.

Returns

  • Block mode.


Definition at line 347 of file platform/service/iostream/inc/sl_iostream_uart.h

Macro Definition Documentation#

uartFlowControlNone#

#define uartFlowControlNone
Value:
0

uart flow control none


Definition at line 148 of file platform/service/iostream/inc/sl_iostream_uart.h

uartFlowControlSoftware#

#define uartFlowControlSoftware
Value:
0xFFFF

uart flow control software


Definition at line 149 of file platform/service/iostream/inc/sl_iostream_uart.h

UARTXON#

#define UARTXON
Value:
0x11

uartx on


Definition at line 150 of file platform/service/iostream/inc/sl_iostream_uart.h

UARTXOFF#

#define UARTXOFF
Value:
0x13

uartx off


Definition at line 151 of file platform/service/iostream/inc/sl_iostream_uart.h