|
| fsp_err_t | R_UART_W_Open (uart_ctrl_t *const p_api_ctrl, uart_cfg_t const *const p_cfg) |
| |
| fsp_err_t | R_UART_W_Close (uart_ctrl_t *const p_api_ctrl) |
| |
| fsp_err_t | R_UART_W_Write (uart_ctrl_t *const p_api_ctrl, uint8_t const *const p_src, uint32_t const bytes) |
| |
| fsp_err_t | R_UART_W_Read (uart_ctrl_t *const p_api_ctrl, uint8_t *const p_dest, uint32_t const bytes) |
| |
| fsp_err_t | R_UART_W_ConfSet (uart_ctrl_t *const p_api_ctrl, uart_cfg_t const *const p_cfg) |
| |
| fsp_err_t | R_UART_W_InfoGet (uart_ctrl_t *const p_api_ctrl, uart_info_t *const p_info) |
| |
| fsp_err_t | R_UART_W_BaudSet (uart_ctrl_t *const p_api_ctrl, void const *const p_baud_setting) |
| |
| fsp_err_t | R_UART_W_Abort (uart_ctrl_t *const p_api_ctrl, uart_dir_t communication_to_abort) |
| |
| fsp_err_t | R_UART_W_CallbackSet (uart_ctrl_t *const p_api_ctrl, void(*p_callback)(uart_callback_args_t *), void *const p_context, uart_callback_args_t *const p_callback_memory) |
| |
| fsp_err_t | R_UART_W_ReadStop (uart_ctrl_t *const p_api_ctrl, uint32_t *remaining_bytes) |
| |
| fsp_err_t | R_UART_W_BaudCalculate (uint32_t baudrate, uart_w_baud_setting_t *const p_baud_setting) |
| |
| void | hw_clk_enable_uart_w_clk (uint8_t channel) |
| | Enable clock for specific UART channel. More...
|
| |
Driver for the UART peripheral on RAFW MCUs. This module implements the UART Interface.
Overview
Features
The UART_W module supports the following features:
- APB data bus widths of 32 bits
- Use PERI_CLK with separate system resets for each clock domain to prevent metastability
- Programmable FIFO enable/disable
- Internal transceiver FIFO depths are 32 bytes
- DMA interface signals with high polarity
- Auto Flow Control mode support
- False start bit detection
- UART busy or idle functionality
- Full-duplex UART communication
- Invoking the user-callback function with an event code (RX/TX complete, TX data empty, RX char, error, etc)
- Baud-rate change at run-time
Configuration
Build Time Configurations for r_uart_w
The following build time configurations are defined in fsp_cfg/r_uart_w_cfg.h:
| Configuration | Options | Default | Description |
| Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
| DMA Support |
| Disable | Enable DMA support for the UART_W module. |
Configurations for Connectivity > UART (r_uart_w)
This module can be added to the Stacks tab via New Stack > Connectivity > UART (r_uart_w). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.
| Configuration | Options | Default | Description |
| General |
| Name | Name must be a valid C symbol | g_uart0 | Module name. |
| Channel | Value must be an integer greater than 0 | 1 | Select the UART channel. |
| Data Bits |
| 8bits | Select the number of bits per word. |
| Parity |
| None | Select the parity mode. |
| Stop Bits |
| 1bit | Select the number of stop bits. |
| Baud |
| Baud Rate | Value must be an integer greater than 0 | 115200 | Enter the desired baud rate.
|
| Extra |
| Extended Data Bits |
| 8bits | Select the number of bits per word (extended configuration). Unused if the channel has no extended bits per word configuration support. |
| Uart Loopback Enable |
| Disable | Enable or disable uart loopback mode for test |
| Uart FIFO Enable |
| Enable | Enable or disable uart FIFO |
| Receive FIFO Trigger Level |
-
1/8 Full
-
1/4 Full
-
1/2 Full
-
3/4 Full
-
7/8 Full
| 7/8 Full | Unused if FIFO is disabled or DMA is used for reception |
| Send FIFO Trigger Level |
-
1/8 Full
-
1/4 Full
-
1/2 Full
-
3/4 Full
-
7/8 Full
| 1/8 Full | Unused if FIFO is disabled or DMA is used for transmission |
| Uart extended data bits Enable |
| Disable | Enable or disable UART extended word length configuration. |
| RS-485 Support |
| Disable | Enable support for controlling the RS-485 DE pin. |
| Flow Control |
| Auto Flow Control |
| Disable | Enable or disable flow control of UART channel n. |
| Interrupts |
| Interrupt Priority | MCU Specific Options | | Select the interrupt priority. |
| Callback | Name must be a valid C symbol | NULL | A user callback function can be provided. If this callback function is provided, it will be called from the interrupt service routine (ISR). |
Clock Configuration
The UART_W peripheral uses the PERI_CLK for for the baud-rate clock generator
Pin Configuration
This module uses the TXD,RTS,CST,and RXD pins to communicate with external devices. When autoflow control is configured, the pins of rts and cts must be pinmux as corresponding functions. When in RS-485 mode, an additional TXDOE signal is provided to indicate the TXD active intervals. This signal can be assigned to any of the unused GPIO pins through the PPA.
Usage Notes
When the auto flow control is enabled, the RTS pin will be automatically pulled up. When the receiving water level of the fifo reaches the set threshold. If need to use auto flow control, also need to configure the corresponding pinmux for RTS and CTS.
Examples
UART_W Example
uint8_t g_dest[TRANSFER_LENGTH];
uint8_t g_src[TRANSFER_LENGTH];
uint8_t g_out_of_band_received[TRANSFER_LENGTH];
uint32_t g_transfer_complete = 0;
uint32_t g_receive_complete = 0;
uint32_t g_out_of_band_index = 0;
void r_uart_w_basic_example (void)
{
for (uint32_t i = 0; i < TRANSFER_LENGTH; i++)
{
g_src[i] = (uint8_t) ('A' + (i % 26));
}
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
while (!g_transfer_complete)
{
}
while (!g_receive_complete)
{
}
}
{
{
{
if (sizeof(g_out_of_band_received) > g_out_of_band_index)
{
g_out_of_band_received[g_out_of_band_index++] = (uint8_t) p_args->
data;
}
break;
}
{
g_receive_complete = 1;
break;
}
{
g_transfer_complete = 1;
break;
}
default:
{
}
}
}
UART_W Baud Set Example
#define UART_W_BAUDRATE_19200 (19200)
void r_uart_w_baud_example (void)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
}
◆ uart_w_instance_ctrl_t
| struct uart_w_instance_ctrl_t |
UART channel control block.
◆ uart_w_baud_setting_t
| struct uart_w_baud_setting_t |
Register settings to achieve a desired baud rate and modulation duty.
| Data Fields |
|
uint32_t |
fra_baud |
Baud rate fractional part. |
|
uint32_t |
int_baud |
Baud rate integer part. |
◆ uart_w_extended_cfg_t
| struct uart_w_extended_cfg_t |
UART on SCI device Configuration
◆ uart_w_auto_flow_control_t
UART flow control mode definition
| Enumerator |
|---|
| UART_W_AUTO_FLOW_CONTROL_DISABLED | Disable auto flow control.
|
| UART_W_AUTO_FLOW_CONTROL_ENABLED | Enable auto flow control.
|
◆ uart_w_loop_back_t
| Enumerator |
|---|
| UART_W_LOOP_BACK_DISABLE | Disable loop back.
|
| UART_W_LOOP_BACK_ENABLE | Enable loop back.
|
◆ uart_w_fifo_enable_t
| Enumerator |
|---|
| UART_W_FIFO_DISABLE | Disable fifo.
|
| UART_W_FIFO_ENABLE | Enable fifo.
|
◆ uart_w_extended_data_bits_t
| Enumerator |
|---|
| UART_W_EXTENDED_DATA_BITS_DISABLE | Disable extended word length configuration.
|
| UART_W_EXTENDED_DATA_BITS_ENABLE | Enable extended word length configuration.
|
◆ uart_w_data_bits_t
UART Data bit length definition
| Enumerator |
|---|
| UART_W_DATA_BITS_5 | Data bits 5-bit.
|
| UART_W_DATA_BITS_6 | Data bits 6-bit.
|
| UART_W_DATA_BITS_7 | Data bits 7-bit.
|
| UART_W_DATA_BITS_8 | Data bits 8-bit.
|
◆ uart_w_rx_fifo_trigger_t
Receive FIFO trigger configuration.
| Enumerator |
|---|
| UART_W_RX_FIFO_TRIGGER_EIGHTH | Received Data Available Interrupt when FIFO is 1/8 full.
|
| UART_W_RX_FIFO_TRIGGER_QUARTER | Received Data Available Interrupt when FIFO is 1/4 full.
|
| UART_W_RX_FIFO_TRIGGER_HALF | Received Data Available Interrupt when FIFO is 1/2 full.
|
| UART_W_RX_FIFO_TRIGGER_THREE_QUARTERS | Received Data Available Interrupt when FIFO is 3/4 full.
|
| UART_W_RX_FIFO_TRIGGER_SEVEN_EIGHTHS | Received Data Available Interrupt when FIFO is 7/8 full.
|
◆ uart_w_tx_fifo_trigger_t
Transmit FIFO trigger configuration.
| Enumerator |
|---|
| UART_W_TX_FIFO_TRIGGER_EIGHTH | Transmit Data Interrupt when FIFO is 1/8 full.
|
| UART_W_TX_FIFO_TRIGGER_QUARTER | Transmit Data Interrupt when FIFO is 1/4 full.
|
| UART_W_TX_FIFO_TRIGGER_HALF | Transmit Data Interrupt when FIFO is 1/2 full.
|
| UART_W_TX_FIFO_TRIGGER_THREE_QUARTERS | Transmit Data Interrupt when FIFO is 3/4 full.
|
| UART_W_TX_FIFO_TRIGGER_SEVEN_EIGHTHS | Transmit Data Interrupt when FIFO is 7/8 full.
|
◆ uart_w_rs485_enable_t
RS-485 Enable/Disable.
| Enumerator |
|---|
| UART_W_RS485_DISABLE | RS-485 disabled.
|
| UART_W_RS485_ENABLE | RS-485 enabled.
|
◆ R_UART_W_Open()
Configures the UART driver based on the input configurations. If reception is enabled at compile time, reception is enabled at the end of this function. Implements uart_api_t::open
- Return values
-
| FSP_SUCCESS | Channel opened successfully. |
| FSP_ERR_ASSERTION | Pointer to UART control block or configuration structure is NULL. |
| FSP_ERR_IP_CHANNEL_NOT_PRESENT | The requested channel does not exist on this MCU. |
| FSP_ERR_INVALID_ARGUMENT | Data bits specified is not supported by the driver. |
| FSP_ERR_ALREADY_OPEN | Control block has already been opened or channel is being used by another instance. Call close() then open() to reconfigure. |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes. This function calls:
◆ R_UART_W_Close()
Aborts any in progress transfers. Disables interrupts, receiver, and transmitter. Closes lower level transfer drivers if used. Reduces power consumption. Implements uart_api_t::close
- Return values
-
| FSP_SUCCESS | Channel successfully closed. |
| FSP_ERR_ASSERTION | Pointer to UART control block is NULL. |
| FSP_ERR_NOT_OPEN | The control block has not been opened |
◆ R_UART_W_Write()
| fsp_err_t R_UART_W_Write |
( |
uart_ctrl_t *const |
p_api_ctrl, |
|
|
uint8_t const *const |
p_src, |
|
|
uint32_t const |
bytes |
|
) |
| |
Transmits user specified number of bytes from the source buffer pointer. Implements uart_api_t::write
- Return values
-
| FSP_SUCCESS | Data transmission finished successfully. |
| FSP_ERR_ASSERTION | Pointer to UART control block is NULL. Number of transfers outside the max or min boundary when transfer instance used |
| FSP_ERR_NOT_OPEN | The control block has not been opened |
| FSP_ERR_IN_USE | A UART transmission is in progress |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes. This function calls:
◆ R_UART_W_Read()
| fsp_err_t R_UART_W_Read |
( |
uart_ctrl_t *const |
p_api_ctrl, |
|
|
uint8_t *const |
p_dest, |
|
|
uint32_t const |
bytes |
|
) |
| |
Receives user specified number of bytes into destination buffer pointer. Implements uart_api_t::read
- Return values
-
| FSP_SUCCESS | Data reception successfully ends. |
| FSP_ERR_ASSERTION | Pointer to UART control block is NULL. Number of transfers outside the max or min boundary when transfer instance used |
| FSP_ERR_NOT_OPEN | The control block has not been opened |
| FSP_ERR_IN_USE | A previous read operation is still in progress. |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes. This function calls:
◆ R_UART_W_ConfSet()
Updates the Uart configuration. p_baud_setting is a pointer to a uart_w_baud_setting_t structure.
- Warning
- This terminates any in-progress transmission.
- Return values
-
| FSP_SUCCESS | Uart been reconfiugred was successfully changed. |
| FSP_ERR_ASSERTION | Pointer to UART control block is NULL or the UART is not configured to use the internal clock. |
| FSP_ERR_NOT_OPEN | The control block has not been opened |
◆ R_UART_W_InfoGet()
Provides the driver information, including the maximum number of bytes that can be received or transmitted at a time. Implements uart_api_t::infoGet
- Return values
-
| FSP_SUCCESS | Information stored in provided p_info. |
| FSP_ERR_ASSERTION | Pointer to UART control block is NULL. |
| FSP_ERR_NOT_OPEN | The control block has not been opened |
◆ R_UART_W_BaudSet()
Updates the baud rate using the clock selected in Open. p_baud_setting is a pointer to a uart_w_baud_setting_t structure. Implements uart_api_t::baudSet
- Warning
- This terminates any in-progress transmission.
- Return values
-
| FSP_SUCCESS | Baud rate was successfully changed. |
| FSP_ERR_ASSERTION | Pointer to UART control block is NULL or the UART is not configured to use the internal clock. |
| FSP_ERR_NOT_OPEN | The control block has not been opened |
◆ R_UART_W_Abort()
Provides API to abort ongoing transfer. Transmission is aborted after the current character is transmitted. Reception is still enabled after abort(). Any characters received after abort() and before the transfer is reset in the next call to read(), will arrive via the callback function with event UART_W_EVENT_RX_CHAR. Implements uart_api_t::communicationAbort
- Return values
-
| FSP_SUCCESS | UART transaction aborted successfully. |
| FSP_ERR_ASSERTION | Pointer to UART control block is NULL. |
| FSP_ERR_NOT_OPEN | The control block has not been opened. |
| FSP_ERR_UNSUPPORTED | The requested Abort direction is unsupported. |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes. This function calls: transfer_api_t::disable
◆ R_UART_W_CallbackSet()
Updates the user callback and has option of providing memory for callback structure. Implements uart_api_t::callbackSet
- Return values
-
| FSP_SUCCESS | Callback updated successfully. |
| FSP_ERR_ASSERTION | A required pointer is NULL. |
| FSP_ERR_NOT_OPEN | The control block has not been opened. |
| FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |
◆ R_UART_W_ReadStop()
Provides API to abort ongoing read. Reception is still enabled after abort(). Any characters received after abort() and before the transfer is reset in the next call to read(), will arrive via the callback function with event UART_EVENT_RX_CHAR. Implements uart_api_t::readStop
- Return values
-
| FSP_SUCCESS | UART transaction aborted successfully. |
| FSP_ERR_ASSERTION | Pointer to UART control block is NULL. |
| FSP_ERR_NOT_OPEN | The control block has not been opened. |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes. This function calls:
◆ R_UART_W_BaudCalculate()
Calculates baud rate register settings. Evaluates and determines the best possible settings set to the baud rate related registers.
- Parameters
-
| [in] | baudrate | Baud rate [bps]. For example, 19200, 57600, 115200, etc. |
| [out] | p_baud_setting | Baud setting information stored here if successful |
- Return values
-
| FSP_SUCCESS | Baud rate is set successfully |
| FSP_ERR_ASSERTION | Null pointer |
| FSP_ERR_INVALID_ARGUMENT | Invalid baudrate |
◆ hw_clk_enable_uart_w_clk()
| void hw_clk_enable_uart_w_clk |
( |
uint8_t |
channel | ) |
|
Enable clock for specific UART channel.
- Parameters
-
| [in] | channel | UART channel to activate clock |
(end addtogroup UART_W)
- Parameters
-
| [in] | channel | UART channel to activate clock |
(end addtogroup UART_W)
- Parameters
-
| [in] | channel | UART channel to activate clock |