RA Flexible Software Package Documentation
Release v5.7.0
|
|
Functions | |
fsp_err_t | R_SAU_UART_Open (uart_ctrl_t *const p_api_ctrl, uart_cfg_t const *const p_cfg) |
fsp_err_t | R_SAU_UART_Close (uart_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_SAU_UART_Read (uart_ctrl_t *const p_api_ctrl, uint8_t *const p_dest, uint32_t const bytes) |
fsp_err_t | R_SAU_UART_Write (uart_ctrl_t *const p_api_ctrl, uint8_t const *const p_src, uint32_t const bytes) |
fsp_err_t | R_SAU_UART_BaudSet (uart_ctrl_t *const p_api_ctrl, void const *const p_baud_setting) |
fsp_err_t | R_SAU_UART_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_SAU_UART_InfoGet (uart_ctrl_t *const p_api_ctrl, uart_info_t *const p_info) |
fsp_err_t | R_SAU_UART_Abort (uart_ctrl_t *const p_api_ctrl, uart_dir_t communication_to_abort) |
fsp_err_t | R_SAU_UART_ReadStop (uart_ctrl_t *const p_api_ctrl, uint32_t *remaining_bytes) |
fsp_err_t | R_SAU_UART_BaudCalculate (sau_uart_instance_ctrl_t *const p_ctrl, uint32_t baudrate, sau_uart_baudrate_setting_t *const p_baud_setting) |
UART driver for the SAU peripheral on RA MCUs. This module implements the UART Interface.
The SAU UART module supports the following features:
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Critical Section Guarding |
| Disabled | Enable critical section guarding around peripheral configuration updates. This should be enabled if the R_SAU_I2C module is being used simultaneously with this module. |
DTC Support |
| Disable | Enable DTC support for the SAU_UART module. |
Enable Single Channel |
| Disable | Enable single channel to reduce code size if only channel 0, 1, or 2 is needed. |
Enable Fixed Baudrate |
| Enable | Disable baudrate calculation and setter functions to reduce code size. |
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 UART channel. |
Data Bits |
| 8 bits | Select the number of bits per word. |
Parity |
| None | Select the parity mode. |
Stop Bits |
| 1 bit | Select the number of stop bits. In receive, 2 bit is not available. |
Bit Order |
| LSB First | Select of data transfer sequence. |
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, adjust the operation clock frequency until the baud rate is achievable. The calculated baud rate is printed in a comment in the generated sau_uart_baudrate_setting_t structure. |
Extra | |||
Operation Clock |
| CKm0 | Select the operation clock. Use the Clocks tab to set the operation clock divider. |
Tx Signal Level |
| Standard | Select the level of transmitted signal. |
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). |
Transmit End Interrupt Priority | MCU Specific Options | Select the transmit end interrupt priority. | |
Receive End Interrupt Priority | MCU Specific Options | Select the receive end interrupt priority. | |
Error Interrupt Priority | MCU Specific Options | Select the error interrupt priority. |
The SAU clock uses the system clock (ICLK) as its clock source.
A prescaler is applied to the ICLK in order to produce the operation clock frequency. The operation clock is used to generate the desired transfer period of the SAU module.
SAU operation clocks are shared among all channels within a SAU unit. Check the Hardware User's Manual for your MCU for available units and channels. SAU operation clock dividers are configurable in the Clocks tab.
The operation clock dividers are named SAU CKmn where m is the SAU unit, and n is the operation clock. For example, SAU CK01 applies to all SAU0 instances using CK1 as the operation clock (m=0, n=1).
This module uses TXD and RXD to communicate to external devices.
The relationship between operation clock frequency and bitrate is: bitrate = f_mck / [ 2 * (SDRmn.STCLK + 1) ]
where:
SDRmn.STCLK
is an integer in the range [2, 127] for SAU UARTf_mck
is the operation clock (SAU CKmn) frequencyBy plugging in the minimum and maximum SDRmn.STCLK
values, the range of bitrates for a given operation clock frequency can be obtained.
Note that due to STCLK being set as discrete integers, the actual bitrate may not be exact. The actual bitrate and percent errors can be calculated by the formulas:
Using the fastest possible operation clock for the desired bitrate will result in the lowest deviation from the requested baud rate. Set the CKmn operation clock divider in the Clocks tab to select the desired operation clock frequency.
Suppose an example application with a 32MHz ICLK requires:
The following operation clocks could be used:
An operation clock of 250 kHz works for UART0 because 1000 is in the range [976, 41.6k]. An operation clock of 16 MHz works for UART1 because 115200 is in the range [62.5k, 2.6M].
Applying the settings:
In order to change the baud rate at runtime, "Common > Enable Fixed Baudrate" must be set to "Disabled" in the module properties.
If changing the baud rate is required at runtime, use a unique operation clock for each SAU instance. This is required because R_SAU_UART_BaudSet may change the operation clock divider. Since the operation clocks are shared between SAU channels on each SAU unit, changing a shared operation clock of one instance will cause an incorrect bitrate to be generated on the other instance(s).
If the system clock frequency is changed at runtime, this setting should be disabled, as the baud rate settings will need to be updated after the system clock change.
Data Structures | |
struct | sau_uart_extended_cfg_t |
struct | sau_uart_instance_ctrl_t |
Enumerations | |
enum | sau_uart_data_sequence_t |
enum | sau_operation_clock_t |
enum | sau_uart_signal_level_t |
struct sau_uart_extended_cfg_t |
UART Configuration
Data Fields | ||
---|---|---|
sau_uart_data_sequence_t | sequence | Transfer sequence (LSB or MSB) |
sau_uart_signal_level_t | signal_level | Transfer data signal level (standard or inverted) |
sau_uart_baudrate_setting_t * | p_baudrate | Baud rate setting (SPS and SDR value) |
struct sau_uart_instance_ctrl_t |
UART instance control block. DO NOT INITIALIZE.
Data Fields | |
uint8_t | extra_data_byte |
0 for 7 or 8 bit data length(1-byte), 1 for 9 bit data length(2-byte) | |
uint32_t | open |
Used to determine if the channel is configured. | |
uart_cfg_t const * | p_cfg |
Pointer to the configuration block. | |
R_SAU0_Type * | p_reg |
Base register for the transmit channel. | |
uint8_t | sau_unit |
SAU unit information. | |
uint8_t | sau_tx_channel |
SAU channel information. | |
uint8_t * | p_src |
Source buffer pointer. | |
uint32_t | tx_count |
Size of destination buffer pointer from transmit ISR. | |
uint8_t * | p_dest |
Destination buffer pointer. | |
uint32_t | rx_count |
Size of destination buffer pointer used for receiving data. | |
fsp_err_t R_SAU_UART_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
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 | Flow control is enabled but flow control pin is not defined or selected channel does not support "Hardware CTS and Hardware RTS" flow control. |
FSP_ERR_ALREADY_OPEN | Control block has already been opened or channel is being used by another instance. Call close() then open() to reconfigure. |
fsp_err_t R_SAU_UART_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. Removes power. Implements uart_api_t::close
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 |
fsp_err_t R_SAU_UART_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
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_INVALID_ARGUMENT | Destination address or data size is not valid for 9-bit mode. |
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 | current operation mode is transmission only. |
fsp_err_t R_SAU_UART_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
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_INVALID_ARGUMENT | Source address or data size is not valid for 9-bit mode. |
FSP_ERR_NOT_OPEN | The control block has not been opened |
FSP_ERR_IN_USE | A UART transmission is in progress |
FSP_ERR_UNSUPPORTED | SAU_UART_CFG_TX_ENABLE is set to 0 |
fsp_err_t R_SAU_UART_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 sau_uart_baudrate_setting_t structure. Implements uart_api_t::baudSet
FSP_SUCCESS | Baud rate was successfully changed. |
FSP_ERR_ASSERTION | Pointer p_ctrl is NULL |
FSP_ERR_INVALID_ARGUMENT | p_api_ctrl is empty. |
FSP_ERR_NOT_OPEN | The control block has not been opened |
FSP_ERR_UNSUPPORTED | Fixed baud rate is enabled |
fsp_err_t R_SAU_UART_CallbackSet | ( | uart_ctrl_t *const | p_api_ctrl, |
void(*)(uart_callback_args_t *) | p_callback, | ||
void const *const | p_context, | ||
uart_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback for callback structure. Implements uart_api_t::callbackSet
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | Pointer p_ctrl is NULL or p_callback_memory is not NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
fsp_err_t R_SAU_UART_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
FSP_SUCCESS | Information stored in provided p_info. |
FSP_ERR_INVALID_ARGUMENT | Pointer to UART control block is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened |
fsp_err_t R_SAU_UART_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_EVENT_RX_CHAR. Implements uart_api_t::communicationAbort
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. |
fsp_err_t R_SAU_UART_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
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. |
fsp_err_t R_SAU_UART_BaudCalculate | ( | sau_uart_instance_ctrl_t *const | p_ctrl, |
uint32_t | baudrate, | ||
sau_uart_baudrate_setting_t *const | p_baud_setting | ||
) |
Calculates baud rate register settings (SDR.STCLK) for the specified SAU unit.
[in] | p_ctrl | Pointer to the SAU UART control block. |
[in] | baudrate | Baud rate [bps]. For example, 19200, 57600, 115200, etc. |
[out] | p_baud_setting | Baud setting information stored here if successful |
FSP_SUCCESS | Baud rate is successfully calculated |
FSP_ERR_UNSUPPORTED | Fixed baudrate is being used |
FSP_ERR_ASSERTION | Null pointer |
FSP_ERR_INVALID_ARGUMENT | Baud rate is not achievable with selected operation clock frequency |