RAFW Flexible Software Package Documentation  Release v2.0.1

 
UART (r_uart_w)

Functions

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...
 

Detailed Description

Driver for the UART peripheral on RAFW MCUs. This module implements the UART Interface.

Overview

Features

The UART_W module supports the following features:

Configuration

Build Time Configurations for r_uart_w

The following build time configurations are defined in fsp_cfg/r_uart_w_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
DMA Support
  • Enable
  • Disable
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.

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_uart0 Module name.
ChannelValue must be an integer greater than 01 Select the UART channel.
Data Bits
  • 7bits
  • 8bits
8bits Select the number of bits per word.
Parity
  • None
  • Odd
  • Even
None Select the parity mode.
Stop Bits
  • 1bit
  • 2bits
1bit Select the number of stop bits.
Baud
Baud RateValue must be an integer greater than 0115200 Enter the desired baud rate.

Extra
Extended Data Bits
  • 5bits
  • 6bits
  • 7bits
  • 8bits
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
  • Enable
  • Disable
Disable Enable or disable uart loopback mode for test
Uart FIFO Enable
  • Enable
  • Disable
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
  • Enable
  • Disable
Disable Enable or disable UART extended word length configuration.
RS-485 Support
  • Enable
  • Disable
Disable Enable support for controlling the RS-485 DE pin.
Flow Control
Auto Flow Control
  • Disable
  • Enable
Disable Enable or disable flow control of UART channel n.
Interrupts
Interrupt PriorityMCU Specific OptionsSelect the interrupt priority.
CallbackName must be a valid C symbolNULL 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)
{
/* Initialize g_src to known data */
for (uint32_t i = 0; i < TRANSFER_LENGTH; i++)
{
g_src[i] = (uint8_t) ('A' + (i % 26));
}
/* Open the transfer instance with initial configuration. */
fsp_err_t err = R_UART_W_Open(&g_uart0_ctrl, &g_uart0_cfg);
assert(FSP_SUCCESS == err);
err = R_UART_W_Read(&g_uart0_ctrl, g_dest, TRANSFER_LENGTH);
assert(FSP_SUCCESS == err);
err = R_UART_W_Write(&g_uart0_ctrl, g_src, TRANSFER_LENGTH);
assert(FSP_SUCCESS == err);
while (!g_transfer_complete)
{
}
while (!g_receive_complete)
{
}
}
void example_callback (uart_callback_args_t * p_args)
{
/* Handle the UART event */
switch (p_args->event)
{
/* Received a character */
{
/* Only put the next character in the receive buffer if there is space for it */
if (sizeof(g_out_of_band_received) > g_out_of_band_index)
{
/* Write either the next one or two bytes depending on the receive data size */
g_out_of_band_received[g_out_of_band_index++] = (uint8_t) p_args->data;
}
break;
}
/* Receive complete */
{
g_receive_complete = 1;
break;
}
/* Transmit complete */
{
g_transfer_complete = 1;
break;
}
default:
{
}
}
}

UART_W Baud Set Example

#define UART_W_BAUDRATE_19200 (19200)
void r_uart_w_baud_example (void)
{
uart_w_baud_setting_t baud_setting;
fsp_err_t err;
err = R_UART_W_BaudCalculate(UART_W_BAUDRATE_19200, &baud_setting);
assert(FSP_SUCCESS == err);
err = R_UART_W_BaudSet(&g_uart0_ctrl, (void *) &baud_setting);
assert(FSP_SUCCESS == err);
}

Data Structures

struct  uart_w_instance_ctrl_t
 
struct  uart_w_baud_setting_t
 
struct  uart_w_extended_cfg_t
 

Enumerations

enum  uart_w_auto_flow_control_t
 
enum  uart_w_loop_back_t
 
enum  uart_w_fifo_enable_t
 
enum  uart_w_extended_data_bits_t
 
enum  uart_w_data_bits_t
 
enum  uart_w_rx_fifo_trigger_t
 
enum  uart_w_tx_fifo_trigger_t
 
enum  uart_w_rs485_enable_t
 

Data Structure Documentation

◆ 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

Data Fields
uart_w_baud_setting_t * p_baud_setting Register settings for a desired baud rate.
uart_w_loop_back_t loop_back_enable Enable loop back.
uart_w_fifo_enable_t fifo_enable Enable FIFO.
uart_w_rx_fifo_trigger_t rx_fifo_trigger RX FIFO trigger level.
uart_w_tx_fifo_trigger_t tx_fifo_trigger TX FIFO trigger level.
uart_w_auto_flow_control_t flow_control CTS/RTS function.
uart_w_rs485_enable_t rs485_enable RS-485 settings.
uart_w_extended_data_bits_t extended_data_bits_enable Enable extended data bits configuration.
uart_w_data_bits_t data_bits Data bit length (5, 6 or 7 or 8)
uint8_t gen_ipl Generic interrupt priority.
IRQn_Type gen_irq Generic interrupt IRQ number.

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ R_UART_W_Open()

fsp_err_t R_UART_W_Open ( uart_ctrl_t *const  p_api_ctrl,
uart_cfg_t const *const  p_cfg 
)

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_SUCCESSChannel opened successfully.
FSP_ERR_ASSERTIONPointer to UART control block or configuration structure is NULL.
FSP_ERR_IP_CHANNEL_NOT_PRESENTThe requested channel does not exist on this MCU.
FSP_ERR_INVALID_ARGUMENTData bits specified is not supported by the driver.
FSP_ERR_ALREADY_OPENControl 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()

fsp_err_t R_UART_W_Close ( uart_ctrl_t *const  p_api_ctrl)

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_SUCCESSChannel successfully closed.
FSP_ERR_ASSERTIONPointer to UART control block is NULL.
FSP_ERR_NOT_OPENThe 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_SUCCESSData transmission finished successfully.
FSP_ERR_ASSERTIONPointer to UART control block is NULL. Number of transfers outside the max or min boundary when transfer instance used
FSP_ERR_NOT_OPENThe control block has not been opened
FSP_ERR_IN_USEA 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_SUCCESSData reception successfully ends.
FSP_ERR_ASSERTIONPointer to UART control block is NULL. Number of transfers outside the max or min boundary when transfer instance used
FSP_ERR_NOT_OPENThe control block has not been opened
FSP_ERR_IN_USEA 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()

fsp_err_t R_UART_W_ConfSet ( uart_ctrl_t *const  p_api_ctrl,
uart_cfg_t const *const  p_cfg 
)

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_SUCCESSUart been reconfiugred was successfully changed.
FSP_ERR_ASSERTIONPointer to UART control block is NULL or the UART is not configured to use the internal clock.
FSP_ERR_NOT_OPENThe control block has not been opened

◆ R_UART_W_InfoGet()

fsp_err_t R_UART_W_InfoGet ( uart_ctrl_t *const  p_api_ctrl,
uart_info_t *const  p_info 
)

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_SUCCESSInformation stored in provided p_info.
FSP_ERR_ASSERTIONPointer to UART control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened

◆ R_UART_W_BaudSet()

fsp_err_t R_UART_W_BaudSet ( uart_ctrl_t *const  p_api_ctrl,
void const *const  p_baud_setting 
)

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_SUCCESSBaud rate was successfully changed.
FSP_ERR_ASSERTIONPointer to UART control block is NULL or the UART is not configured to use the internal clock.
FSP_ERR_NOT_OPENThe control block has not been opened

◆ R_UART_W_Abort()

fsp_err_t R_UART_W_Abort ( uart_ctrl_t *const  p_api_ctrl,
uart_dir_t  communication_to_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_SUCCESSUART transaction aborted successfully.
FSP_ERR_ASSERTIONPointer to UART control block is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_UNSUPPORTEDThe 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()

fsp_err_t R_UART_W_CallbackSet ( uart_ctrl_t *const  p_api_ctrl,
void(*)(uart_callback_args_t *)  p_callback,
void *const  p_context,
uart_callback_args_t *const  p_callback_memory 
)

Updates the user callback and has option of providing memory for callback structure. Implements uart_api_t::callbackSet

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_NO_CALLBACK_MEMORYp_callback is non-secure and p_callback_memory is either secure or NULL.

◆ R_UART_W_ReadStop()

fsp_err_t R_UART_W_ReadStop ( uart_ctrl_t *const  p_api_ctrl,
uint32_t *  remaining_bytes 
)

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_SUCCESSUART transaction aborted successfully.
FSP_ERR_ASSERTIONPointer to UART control block is NULL.
FSP_ERR_NOT_OPENThe 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()

fsp_err_t R_UART_W_BaudCalculate ( uint32_t  baudrate,
uart_w_baud_setting_t *const  p_baud_setting 
)

Calculates baud rate register settings. Evaluates and determines the best possible settings set to the baud rate related registers.

Parameters
[in]baudrateBaud rate [bps]. For example, 19200, 57600, 115200, etc.
[out]p_baud_settingBaud setting information stored here if successful
Return values
FSP_SUCCESSBaud rate is set successfully
FSP_ERR_ASSERTIONNull pointer
FSP_ERR_INVALID_ARGUMENTInvalid 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]channelUART channel to activate clock

(end addtogroup UART_W)

Parameters
[in]channelUART channel to activate clock

(end addtogroup UART_W)

Parameters
[in]channelUART channel to activate clock