UARTDriver

Description

Serial UART Interface Driver.

Flexible UART driver implementation for communication with external devices.

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] buffer The data buffer to send
[in] length Number of bytes in the buffer to send
[in] blocking Indicates 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] byte The 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] buffer The data buffer to receive into
[in] requestedLength Number of bytes to read
[out] receivedLength Number of bytes read
[in] blocking Indicates 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] timeout Number 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 UART in a blocking fashion.

Parameters
[out] byte The 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 UART in a blocking fashion.

Parameters
[out] byte The byte to send
[in] timeout Maximum 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] flushTx Flush the transmit buffer when true
[in] flushRx Flush the receive buffer when true
Returns
BOOTLOADER_OK