|
fsp_err_t | R_UARTA_Open (uart_ctrl_t *const p_api_ctrl, uart_cfg_t const *const p_cfg) |
|
fsp_err_t | R_UARTA_Close (uart_ctrl_t *const p_api_ctrl) |
|
fsp_err_t | R_UARTA_Read (uart_ctrl_t *const p_api_ctrl, uint8_t *const p_dest, uint32_t const bytes) |
|
fsp_err_t | R_UARTA_Write (uart_ctrl_t *const p_api_ctrl, uint8_t const *const p_src, uint32_t const bytes) |
|
fsp_err_t | R_UARTA_CallbackSet (uart_ctrl_t *const p_api_ctrl, void(*p_callback)(uart_callback_args_t *), void const *const p_context, uart_callback_args_t *const p_callback_memory) |
|
fsp_err_t | R_UARTA_BaudSet (uart_ctrl_t *const p_api_ctrl, void const *const p_baud_setting) |
|
fsp_err_t | R_UARTA_InfoGet (uart_ctrl_t *const p_api_ctrl, uart_info_t *const p_info) |
|
fsp_err_t | R_UARTA_Abort (uart_ctrl_t *const p_api_ctrl, uart_dir_t communication_to_abort) |
|
fsp_err_t | R_UARTA_ReadStop (uart_ctrl_t *const p_api_ctrl, uint32_t *p_remaining_bytes) |
|
fsp_err_t | R_UARTA_BaudCalculate (uint32_t baudrate, uint32_t baud_rate_percent_error_x1000, uarta_clock_source_t clock_source, uarta_baud_setting_t *const p_baud_setting) |
|
Driver for the UARTA peripheral on RA MCUs. This module implements the UART Interface.
Overview
Features
The UARTA module supports the following features:
- Full-duplex UART communication
- Interrupt-driven data transmission and reception
- Baud-rate change at run-time
- Integration with the DTC transfer module
- Abort in-progress read/write operations
- MSB or LSB first transfer selectable
- Inversion control of communication logic level provided
- Clock output function (Not available on all MCUs)
Configuration
Build Time Configurations for r_uarta
The following build time configurations are defined in fsp_cfg/r_uarta_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. |
DTC Support | MCU Specific Options | | Enable DTC support for the UARTA module. |
Receive Error Interrupt Mode |
| Enabled | Selection receive interrupt mode .
Disabled: The UARTA0_ERRI interrupt is generated when a reception error occurs.
Enabled: The UARTA0_RXI interrupt is generated when a reception error occurs. |
Configurations for Connectivity > UART (r_uarta)
This module can be added to the Stacks tab via New Stack > Connectivity > UART (r_uarta).
Configuration | Options | Default | Description |
General |
Name | Name must be a valid C symbol | g_uart0 | Module name. |
Channel | Value must be a non-negative integer | 0 | Select the UARTA 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.
Note: For the receive data, only the first 1 bit of the stop bits is checked regardless of the stop bit length. |
Baud |
Baud Rate | Value must be an integer greater than 0 | 115200 | Enter the desired baud rate.
If the requested baud rate cannot be achieved, the settings with the smallest percent error are used. The theoretical calculated baud rate and percent error are printed in a comment in the generated baud_setting_t structure. |
Extra |
Transfer Order |
| LSB first | Selection of the transmission/reception order. |
Transfer level |
-
Positive logic
-
Negative logic
| Positive logic | Selection of the transmission/reception level. |
Clock output | MCU Specific Options | | Enable Clock output |
Interrupts |
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). |
Receive Interrupt Priority | MCU Specific Options | | Select the receive interrupt priority. |
Transmit Interrupt Priority | MCU Specific Options | | Select the transmit interrupt priority. |
Error Interrupt Priority | MCU Specific Options | | Select the error interrupt priority. |
Clock Configuration
The baud-rate clock generator can be selected from the clock source MOSC, HOCO, MOCO, SOSC/LOCO.
Pin Configuration
This module uses TXDA and RXDA pin to communicate to external devices.
Usage Notes
Limitations
- Reception is still enabled after uart_api_t::communicationAbort API is called. Any characters received after abort and before the next call to read will arrive via the callback function with event UART_EVENT_RX_CHAR.
- The UARTA module does not have CTS or RTS signals.
DTC Limitations
- DTC support is available for reception, but labeled as [Not recommended]. This is because the UART bytes are received asynchronously. Bytes can be received between calls to R_UARTA_Read(). The logic required to combine bytes received through R_UARTA_Read() (UART_EVENT_RX_COMPLETE) and bytes received between calls (UART_EVENT_RX_CHAR) is complex. Reception length may also be unknown, and the driver will not issue an interrupt unless the entire DTC buffer is filled.
- Transfer size must be less than or equal to 64K bytes if DTC interface is used for transfer. uart_api_t::infoGet API can be used to get the max transfer size allowed.
Examples
UARTA 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_uarta_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;
}
else
{
uint16_t * p_dest = (uint16_t *) &g_out_of_band_received[g_out_of_band_index];
*p_dest = (uint16_t) p_args->
data;
g_out_of_band_index += 2;
}
}
break;
}
{
g_receive_complete = 1;
break;
}
{
g_transfer_complete = 1;
break;
}
default:
{
}
}
}
UARTA Baud Set Example
#define UARTA_BAUDRATE_19200 (19200)
#define UARTA_BAUDRATE_ERROR_PERCENT_4740 (4740)
void r_uarta_baud_example (void)
{
uint32_t baud_rate = UARTA_BAUDRATE_19200;
uint32_t error_rate_x_1000 = UARTA_BAUDRATE_ERROR_PERCENT_4740;
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
}
◆ uarta_baud_setting_t
struct uarta_baud_setting_t |
Register settings to acheive a desired baud rate and modulation duty.
Data Fields |
union uarta_baud_setting_t |
__unnamed__ |
|
uint8_t |
brgca |
Baud rate generator control setting. |
uint16_t |
delay_time |
Delay time (us) required to enable TX at open. |
◆ uarta_extended_cfg_t
struct uarta_extended_cfg_t |
UART on UARTA device Configuration
◆ uarta_instance_ctrl_t
struct uarta_instance_ctrl_t |
UARTA instance control block.
◆ uarta_clock_source_t
Enumeration for UARTA clock source
Enumerator |
---|
UARTA_CLOCK_SOURCE_SOSC_LOCO | SOSC/LOCO.
|
UARTA_CLOCK_SOURCE_LOCO | LOCO.
|
UARTA_CLOCK_SOURCE_MOSC | MOSC.
|
UARTA_CLOCK_SOURCE_HOCO | HOCO.
|
UARTA_CLOCK_SOURCE_MOCO | MOCO.
|
UARTA_CLOCK_SOURCE_SOSC | SOSC.
|
◆ uarta_clock_div_t
Enumeration for UARTA clock divider
Enumerator |
---|
UARTA_CLOCK_DIV_1 | fSEL/1
|
UARTA_CLOCK_DIV_2 | fSEL/2
|
UARTA_CLOCK_DIV_4 | fSEL/4
|
UARTA_CLOCK_DIV_8 | fSEL/8
|
UARTA_CLOCK_DIV_16 | fSEL/16
|
UARTA_CLOCK_DIV_32 | fSEL/32
|
UARTA_CLOCK_DIV_64 | fSEL/64
|
UARTA_CLOCK_DIV_COUNT | Total number of clock divider options.
|
◆ uarta_clock_out_t
Enabled/Disabled Clock output
Enumerator |
---|
UARTA_CLOCK_OUTPUT_DISABLED | Disables CLKAn output.
|
UARTA_CLOCK_OUTPUT_ENABLED | Enables CLKAn output.
|
◆ uarta_dir_bit_t
Transmission/reception order configuration.
Enumerator |
---|
UARTA_DIR_BIT_MSB_FIRST | MSB first.
|
UARTA_DIR_BIT_LSB_FIRST | LSB first.
|
◆ uarta_alv_bit_t
Transmission/reception level configuration.
Enumerator |
---|
UARTA_ALV_BIT_POSITIVE_LOGIC | Positive logic (wait state = high level, start bit = low level, stop bit = high level)
|
UARTA_ALV_BIT_NEGATIVE_LOGIC | Negative logic (wait state = low level, start bit = high level, stop bit = low level)
|
◆ R_UARTA_Open()
Configures the UARTA driver based on the input configurations. If transmission/reception is enabled at compile time, transmission/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 UARTA 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 | Invalid clock select (f_UTA0) and baudrate configuration. |
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_UARTA_Close()
Aborts any in progress transfers. Disables interrupts, receiver, and transmitter. Closes lower level transfer drivers if used. Removes power. Implements uart_api_t::close
- Return values
-
FSP_SUCCESS | Channel successfully closed. |
FSP_ERR_ASSERTION | Pointer to UARTA control block is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened |
◆ R_UARTA_Read()
fsp_err_t R_UARTA_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 UARTA 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. |
FSP_ERR_UNSUPPORTED | UARTA_CFG_RX_ENABLE is set to 0 |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes. This function calls:
◆ R_UARTA_Write()
fsp_err_t R_UARTA_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 UARTA 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 UARTA transmission is in progress |
FSP_ERR_UNSUPPORTED | UART_CFG_TX_ENABLE is set to 0 |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes. This function calls:
◆ R_UARTA_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. |
◆ R_UARTA_BaudSet()
Updates the baud rate using the clock selected in Open. p_baud_setting is a pointer to a uarta_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 UARTA control block is NULL or the UART is not configured to use the internal clock. |
FSP_ERR_INVALID_ARGUMENT | Invalid clock select (f_UTA0) and baudrate configuration. |
FSP_ERR_NOT_OPEN | The control block has not been opened |
◆ R_UARTA_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_UARTA_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_EVENT_RX_CHAR. Implements uart_api_t::communicationAbort
- Return values
-
FSP_SUCCESS | UARTA transaction aborted successfully. |
FSP_ERR_ASSERTION | Pointer to UARTA 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_UARTA_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 | UARTA transaction aborted successfully. |
FSP_ERR_ASSERTION | Pointer to UARTA 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_UARTA_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. |
[in] | baud_rate_percent_error_x1000 | Max baud rate error. At most baud_rate_percent_error x 1000 required for module to function. Absolute max baud_rate_error is 4740 (4.74%). |
[in] | clock_source | Clock Source. Required for module to generate baudrate. The clock sources can be select include UARTA_CLOCK_SOURCE_MOSC, UARTA_CLOCK_SOURCE_HOCO, UARTA_CLOCK_SOURCE_MOCO, UARTA_CLOCK_SOURCE_SOSC_LOCO. |
[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 | Argument is out of available range, baud rate is '0'. |
FSP_ERR_INVALID_RATE | Baud rate error is outside the range or the baud rate could not be set given the current clock source. |