UARTDriver

Description

Serial UART Interface driver.

Flexible UART driver implementation for communication with external devices.

This driver supports both blocking and non-blocking operation with LDMA backing the background transfers to support nonblocking. Additionally, support for hardware flow control is included.

Functions

void uart_init (void)
 
void uart_deinit (void)
 
int32_t uart_sendBuffer (uint8_t *buffer, size_t length, bool blocking)
 
int32_t uart_sendByte (uint8_t byte)
 
bool uart_isTxIdle (void)
 
size_t uart_getRxAvailableBytes (void)
 
int32_t uart_receiveBuffer (uint8_t *buffer, size_t requestedLength, size_t *receivedLength, bool blocking, uint32_t timeout)
 
int32_t uart_receiveByte (uint8_t *byte)
 
int32_t uart_receiveByteTimeout (uint8_t *byte, uint32_t timeout)
 
int32_t uart_flush (bool flushTx, bool flushRx)
 

Function Documentation

void uart_init ( void  )

Initialize the configured USART peripheral for UART operation. Also sets up GPIO settings for TX, RX, and, if configured, flow control.

void uart_deinit ( void  )

Disable the configured USART peripheral for UART operation.

int32_t uart_sendBuffer ( uint8_t *  buffer,
size_t  length,
bool  blocking 
)

Write a data buffer to the UART.

Parameters
[in]bufferThe data buffer to send
[in]lengthNumber of bytes in the buffer to send
[in]blockingIndicates whether this transfer can be offloaded to LDMA and return, or whether to wait on completion before returning.
Returns
BOOTLOADER_OK if successful, error code otherwise
int32_t uart_sendByte ( uint8_t  byte)

Write one byte to the UART in a blocking fashion.

Parameters
[in]byteThe byte to send
Returns
BOOTLOADER_OK if successful, error code otherwise
bool uart_isTxIdle ( void  )

Find out whether the UART can accept more data to send.

Returns
true if the UART is not currently transmitting
size_t uart_getRxAvailableBytes ( void  )

Get the number of bytes ready for reading.

Returns
Number of bytes in the receive buffer available for reading with uart_receiveBuffer
int32_t uart_receiveBuffer ( uint8_t *  buffer,
size_t  requestedLength,
size_t *  receivedLength,
bool  blocking,
uint32_t  timeout 
)

Read from the UART into a data buffer

Parameters
[out]bufferThe data buffer to receive into
[in]requestedLengthNumber of bytes to read
[out]receivedLengthNumber of bytes read
[in]blockingIndicates whether to wait for requestedLength bytes to be available and read before returning, or whether to read out data currently in the buffer and return.
[in]timeoutNumber of milliseconds to wait for data in blocking mode
Returns
BOOTLOADER_OK if successful, error code otherwise
int32_t uart_receiveByte ( uint8_t *  byte)

Get one byte from the UART in a blocking fashion.

Parameters
[out]byteThe byte to send
Returns
BOOTLOADER_OK if successful, error code otherwise
int32_t uart_receiveByteTimeout ( uint8_t *  byte,
uint32_t  timeout 
)

Get one byte from the UART in a blocking fashion.

Parameters
[out]byteThe byte to send
[in]timeoutMaximum timeout before aborting transfer
Returns
BOOTLOADER_OK if successful, error code otherwise
int32_t uart_flush ( bool  flushTx,
bool  flushRx 
)

Flush one or both UART buffers.

Parameters
[in]flushTxFlush the transmit buffer when true
[in]flushRxFlush the receive buffer when true
Returns
BOOTLOADER_OK