Driver API for Synaptics UART peripheral.
The UART (Universal Asynchronous Receiver/Transmitter) protocol is a serial communication protocol that allows full-duplex data exchange.
Features:
- Support for 5 to 8 data bits
- Configurable parity and stop bits
- Flow control support
- Interrupt-based and blocking/non-blocking communication APIs
- RX FIFOs and TX FIFOs
- Note
- UART APIs are divided into two categories:
- High-level APIs: These offer buffered I/O, interrupt-driven transfer, and automatic flow control. They are ideal for general application-layer use.
- Low-level APIs: These directly access hardware registers and offer minimal abstraction. Ideal for bootloaders, custom protocol stacks, or performance-critical operations.
- Warning
- Mixing high-level and low-level UART APIs in the same application is not supported. Each operates with different assumptions about interrupt handling, register state, and buffering. Using both on the same UART instance can lead to data loss, missed interrupts, and corrupted driver state. Choose one model per UART instance based on your use case.
Configuration Considerations
To initialize and use the UART driver:
PINMUX Configuration for UART
void sys_uart_config_mux(void)
{
#if CONFIG_MODULE_UART_0_ENABLED
HW_REG_FIELD_WRITE(GLOBAL_BASE_ADDRESS, GLOBAL_PERIF_UART_PORT_CTRL, UART0_RX_SEL, 0);
#endif
#if CONFIG_MODULE_UART_1_ENABLED
#endif
#if CONFIG_MODULE_UART_LP_ENABLED
pinmux_set_pin_func(
SPI_SLV_CLK, SPI_SLV_CLK__UART_LP_TX);
pinmux_set_pin_func(
SPI_SLV_CS, SPI_SLV_CS__UART_LP_RX);
#endif
}
General Functions.
uart_init
Initializes the UART hardware and internal driver structures for the specified UART instance.
uart_deinit
Deinitializes the UART hardware and releases any resources held by the driver for the specified UART instance.
uart_set_config
Sets the UART hardware configuration for the specified UART instance, including data bits, stop bits, parity, flow control, and baud rate. Programs the UART registers accordingly and returns the actual baud rate achieved.
.baud_rate = 230400,
.flow_control = 0,
};
{
}
High-level Functions.
uart_put_non_blocking
Initiates a non-blocking transmit operation over UART for the specified instance. Data is written to the UART transmit FIFO and the function returns immediately. Completion is handled via callback.
bool wait_for_tx_fifo_drain = true;
char uart_tx_buf[] = "UART_PUT_NON_BLOCKING_TESTING";
uint32_t tx_size = sizeof(uart_tx_buf);
.put_buff = uart_tx_buf,
.num = tx_size,
.callback = fp_event_cb,
.user_data = NULL,
.wait_for_tx_fifo_drain = wait_for_tx_fifo_drain
};
{
return rc;
}
uart_get_non_blocking
Initiates a non-blocking receive operation over UART for the specified instance. Attempts to read data from the UART receive FIFO into the provided buffer and returns immediately with the number of bytes received so far.
uint32_t received_chars = 0;
#define UART_RX_SIZE 10
char uart_rx_buf[UART_RX_SIZE];
uint32_t rx_size = UART_RX_SIZE;
.get_buff = uart_rx_buf,
.num = rx_size,
.callback = fp_event_cb,
.user_data = NULL
};
{
return rc;
}
Low-level Functions.
uart_put_blocking
Performs a blocking transmit operation over UART for the specified instance. Sends data from the provided buffer and blocks until all bytes are transmitted or the timeout occurs.
bool wait_for_tx_fifo_drain = true;
char uart_tx_buf[] = "UART_PUT_BLOCKING_TESTING";
uint32_t tx_size = sizeof(uart_tx_buf);
uint32_t timeout = 1000;
{
return rc;
}
uart_get_blocking
Performs a blocking receive operation over UART for the specified instance. Waits for the specified number of bytes to be received or until the timeout expires.
#define UART_RX_SIZE 10
char uart_rx_buf[UART_RX_SIZE];
uint32_t timeout = 1000;
uint32_t rx_size = UART_RX_SIZE;
{
return rc;
}