This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the SERCOM module in its USART mode to transfer or receive USART data frames.
The following driver API modes are covered by this manual:
The following peripheral is used by this module:
The following devices can use this module:
The outline of this documentation is as follows:
To use the USART you need to have a GCLK generator enabled and running that can be used as the SERCOM clock source. This can either be configured in conf_clocks.h or by using the system clock driver.
This driver will use one (or more) SERCOM interface(s) in the system and configure it to run as a USART interface in either synchronous or asynchronous mode.
Driver Feature Macro | Supported devices |
---|---|
FEATURE_USART_SYNC_SCHEME_V2 | SAM D21/R21/D09/D10/D11/L21/L22/DA1/C20/C21/R30/R34/R35 |
FEATURE_USART_OVER_SAMPLE | SAM D21/R21/D09/D10/D11/L21/L22/DA1/C20/C21/R30/R34/R35 |
FEATURE_USART_HARDWARE_FLOW_CONTROL | SAM D21/R21/D09/D10/D11/L21/L22/DA1/C20/C21/R30/R34/R35 |
FEATURE_USART_IRDA | SAM D21/R21/D09/D10/D11/L21/L22/DA1/C20/C21/R30/R34/R35 |
FEATURE_USART_LIN_SLAVE | SAM D21/R21/D09/D10/D11/L21/L22/DA1/C20/C21/R30/R34/R35 |
FEATURE_USART_COLLISION_DECTION | SAM D21/R21/D09/D10/D11/L21/L22/DA1/C20/C21/R30/R34/R35 |
FEATURE_USART_START_FRAME_DECTION | SAM D21/R21/D09/D10/D11/L21/L22/DA1/C20/C21/R30/R34/R35 |
FEATURE_USART_IMMEDIATE_BUFFER_OVERFLOW_NOTIFICATION | SAM D21/R21/D09/D10/D11/L21/L22/DA1/C20/C21/R30/R34/R35 |
FEATURE_USART_RS485 | SAM C20/C21 |
FEATURE_USART_LIN_MASTER | SAM L22/C20/C21 |
Communication is based on frames, where the frame format can be customized to accommodate a wide range of standards. A frame consists of a start bit, a number of data bits, an optional parity bit for error detection as well as a configurable length stop bit(s) - see the figure below. The table below shows the available parameters you can change in a frame.
Parameter | Options |
---|---|
Start bit | 1 |
Data bits | 5, 6, 7, 8, 9 |
Parity bit | None, Even, Odd |
Stop bits | 1, 2 |
In synchronous mode a dedicated clock line is provided; either by the USART itself if in master mode, or by an external master if in slave mode. Maximum transmission speed is the same as the GCLK clocking the USART peripheral when in slave mode, and the GCLK divided by two if in master mode. In synchronous mode the interface needs three lines to communicate:
In synchronous mode the data is sampled on either the rising or falling edge of the clock signal. This is configured by setting the clock polarity in the configuration struct.
In asynchronous mode no dedicated clock line is used, and the communication is based on matching the clock speed on the transmitter and receiver. The clock is generated from the internal SERCOM baudrate generator, and the frames are synchronized by using the frame start bits. Maximum transmission speed is limited to the SERCOM GCLK divided by 16. In asynchronous mode the interface only needs two lines to communicate:
For successful transmit and receive using the asynchronous mode the receiver and transmitter clocks needs to be closely matched. When receiving a frame that does not match the selected baudrate closely enough the receiver will be unable to synchronize the frame(s), and garbage transmissions will result.
Parity can be enabled to detect if a transmission was in error. This is done by counting the number of "1" bits in the frame. When using even parity the parity bit will be set if the total number of "1"s in the frame are an even number. If using odd parity the parity bit will be set if the total number of "1"s are odd.
When receiving a character the receiver will count the number of "1"s in the frame and give an error if the received frame and parity bit disagree.
The SERCOM module has four internal pads; the RX pin can be placed freely on any one of the four pads, and the TX and XCK pins have two predefined positions that can be selected as a pair. The pads can then be routed to an external GPIO pin using the normal pin multiplexing scheme on the SAM.
Never execute large portions of code in the callbacks. These are run from the interrupt routine, and thus having long callbacks will keep the processor in the interrupt handler for an equally long time. A common way to handle this is to use global flags signaling the main application that an interrupt event has happened, and only do the minimal needed processing in the callback.
For extra information, see Extra Information for SERCOM USART Driver. This includes:
For a list of examples related to this driver, see Examples for SERCOM USART Driver.
Modules | |
Related Project(s) | |
In this section you can find all the projects related to the SAM Serial USART (SERCOM USART) Driver. | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the SAM Serial USART (SERCOM USART) Driver. | |
Data Structures | |
struct | iso7816_config_t |
ISO7816 configuration struct. More... | |
struct | usart_config |
USART configuration struct. More... | |
struct | usart_module |
SERCOM USART driver software device instance structure. More... | |
Macros | |
#define | PINMUX_DEFAULT 0 |
Default pinmux. More... | |
#define | PINMUX_UNUSED 0xFFFFFFFF |
Unused pinmux. More... | |
#define | USART_TIMEOUT 0xFFFF |
USART timeout value. More... | |
Typedefs | |
typedef void(* | usart_callback_t )(struct usart_module *const module) |
USART callback type. More... | |
Enumerations | |
enum | iso7816_guard_time { ISO7816_GUARD_TIME_2_BIT = 2, ISO7816_GUARD_TIME_3_BIT, ISO7816_GUARD_TIME_4_BIT, ISO7816_GUARD_TIME_5_BIT, ISO7816_GUARD_TIME_6_BIT, ISO7816_GUARD_TIME_7_BIT } |
ISO7816 guard time. More... | |
enum | iso7816_inhibit_nack { ISO7816_INHIBIT_NACK_DISABLE = (0x0ul << SERCOM_USART_CTRLC_INACK_Pos), ISO7816_INHIBIT_NACK_ENABLE = SERCOM_USART_CTRLC_INACK } |
ISO7816 receive NACK inhibit. More... | |
enum | iso7816_protocol_type { ISO7816_PROTOCOL_T_0 = SERCOM_USART_CTRLA_CMODE, ISO7816_PROTOCOL_T_1 = (0x0ul << SERCOM_USART_CTRLA_CMODE_Pos) } |
ISO7816 protocol type. More... | |
enum | iso7816_successive_recv_nack { ISO7816_SUCCESSIVE_RECV_NACK_DISABLE = (0x0ul << SERCOM_USART_CTRLC_INACK_Pos), ISO7816_SUCCESSIVE_RECV_NACK_ENABLE = SERCOM_USART_CTRLC_DSNACK } |
ISO7816 disable successive receive NACK. More... | |
enum | lin_master_break_length { LIN_MASTER_BREAK_LENGTH_13_BIT = SERCOM_USART_CTRLC_BRKLEN(0x0), LIN_MASTER_BREAK_LENGTH_17_BIT = SERCOM_USART_CTRLC_BRKLEN(0x1), LIN_MASTER_BREAK_LENGTH_21_BIT = SERCOM_USART_CTRLC_BRKLEN(0x2), LIN_MASTER_BREAK_LENGTH_26_BIT = SERCOM_USART_CTRLC_BRKLEN(0x3) } |
LIN master break length. More... | |
enum | lin_master_cmd { LIN_MASTER_SOFTWARE_CONTROL_TRANSMIT_CMD = SERCOM_USART_CTRLB_LINCMD(0x01), LIN_MASTER_AUTO_TRANSMIT_CMD = SERCOM_USART_CTRLB_LINCMD(0x02) } |
LIN master command enum. More... | |
enum | lin_master_header_delay { LIN_MASTER_HEADER_DELAY_0 = SERCOM_USART_CTRLC_HDRDLY(0x0), LIN_MASTER_HEADER_DELAY_1 = SERCOM_USART_CTRLC_HDRDLY(0x01), LIN_MASTER_HEADER_DELAY_2 = SERCOM_USART_CTRLC_HDRDLY(0x02), LIN_MASTER_HEADER_DELAY_3 = SERCOM_USART_CTRLC_HDRDLY(0x03) } |
LIN master header delay. More... | |
enum | lin_node_type { LIN_MASTER_NODE = SERCOM_USART_CTRLA_FORM(0x02), LIN_SLAVE_NODE = SERCOM_USART_CTRLA_FORM(0x04), LIN_INVALID_MODE = SERCOM_USART_CTRLA_FORM(0x00) } |
LIN node type. More... | |
enum | rs485_guard_time { RS485_GUARD_TIME_0_BIT = 0, RS485_GUARD_TIME_1_BIT, RS485_GUARD_TIME_2_BIT, RS485_GUARD_TIME_3_BIT, RS485_GUARD_TIME_4_BIT, RS485_GUARD_TIME_5_BIT, RS485_GUARD_TIME_6_BIT, RS485_GUARD_TIME_7_BIT } |
RS485 Guard Time. More... | |
enum | usart_callback { USART_CALLBACK_BUFFER_TRANSMITTED, USART_CALLBACK_BUFFER_RECEIVED, USART_CALLBACK_ERROR, USART_CALLBACK_BREAK_RECEIVED, USART_CALLBACK_CTS_INPUT_CHANGE, USART_CALLBACK_START_RECEIVED } |
USART callback enum. More... | |
enum | usart_character_size { USART_CHARACTER_SIZE_5BIT = SERCOM_USART_CTRLB_CHSIZE(5), USART_CHARACTER_SIZE_6BIT = SERCOM_USART_CTRLB_CHSIZE(6), USART_CHARACTER_SIZE_7BIT = SERCOM_USART_CTRLB_CHSIZE(7), USART_CHARACTER_SIZE_8BIT = SERCOM_USART_CTRLB_CHSIZE(0), USART_CHARACTER_SIZE_9BIT = SERCOM_USART_CTRLB_CHSIZE(1) } |
USART Character Size. More... | |
enum | usart_dataorder { USART_DATAORDER_MSB = 0, USART_DATAORDER_LSB = SERCOM_USART_CTRLA_DORD } |
USART Data Order enum. More... | |
enum | usart_parity { USART_PARITY_ODD = SERCOM_USART_CTRLB_PMODE, USART_PARITY_EVEN = 0, USART_PARITY_NONE = 0xFF } |
USART Parity enum. More... | |
enum | usart_sample_adjustment { USART_SAMPLE_ADJUSTMENT_7_8_9 = SERCOM_USART_CTRLA_SAMPA(0), USART_SAMPLE_ADJUSTMENT_9_10_11 = SERCOM_USART_CTRLA_SAMPA(1), USART_SAMPLE_ADJUSTMENT_11_12_13 = SERCOM_USART_CTRLA_SAMPA(2), USART_SAMPLE_ADJUSTMENT_13_14_15 = SERCOM_USART_CTRLA_SAMPA(3) } |
USART Sample Adjustment. More... | |
enum | usart_sample_rate { USART_SAMPLE_RATE_16X_ARITHMETIC = SERCOM_USART_CTRLA_SAMPR(0), USART_SAMPLE_RATE_16X_FRACTIONAL = SERCOM_USART_CTRLA_SAMPR(1), USART_SAMPLE_RATE_8X_ARITHMETIC = SERCOM_USART_CTRLA_SAMPR(2), USART_SAMPLE_RATE_8X_FRACTIONAL = SERCOM_USART_CTRLA_SAMPR(3), USART_SAMPLE_RATE_3X_ARITHMETIC = SERCOM_USART_CTRLA_SAMPR(4) } |
USART Sample Rate. More... | |
enum | usart_signal_mux_settings { USART_RX_0_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(0)), USART_RX_0_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(1)), USART_RX_0_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(2)), USART_RX_1_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(0)), USART_RX_1_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(1)), USART_RX_1_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(2)), USART_RX_2_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(0)), USART_RX_2_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(1)), USART_RX_2_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(2)), USART_RX_3_TX_0_XCK_1 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(0)), USART_RX_3_TX_2_XCK_3 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(1)), USART_RX_3_TX_0_RTS_2_CTS_3 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(2)), USART_RX_0_TX_0_XCK_1_TE_2 = (SERCOM_USART_CTRLA_RXPO(0) | SERCOM_USART_CTRLA_TXPO(3)), USART_RX_1_TX_0_XCK_1_TE_2 = (SERCOM_USART_CTRLA_RXPO(1) | SERCOM_USART_CTRLA_TXPO(3)), USART_RX_2_TX_0_XCK_1_TE_2 = (SERCOM_USART_CTRLA_RXPO(2) | SERCOM_USART_CTRLA_TXPO(3)), USART_RX_3_TX_0_XCK_1_TE_2 = (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(3)) } |
USART signal MUX settings. More... | |
enum | usart_stopbits { USART_STOPBITS_1 = 0, USART_STOPBITS_2 = SERCOM_USART_CTRLB_SBMODE } |
USART Stop Bits enum. More... | |
enum | usart_transceiver_type { USART_TRANSCEIVER_RX, USART_TRANSCEIVER_TX } |
USART Transceiver. More... | |
enum | usart_transfer_mode { USART_TRANSFER_SYNCHRONOUSLY = (SERCOM_USART_CTRLA_CMODE), USART_TRANSFER_ASYNCHRONOUSLY = (0x0ul << SERCOM_USART_CTRLA_CMODE_Pos) } |
USART Transfer mode enum. More... | |
Functions | |
static void | usart_disable (const struct usart_module *const module) |
Disable module. More... | |
static void | usart_enable (const struct usart_module *const module) |
Enable the module. More... | |
static void | usart_get_config_defaults (struct usart_config *const config) |
Initializes the device to predefined defaults. More... | |
enum status_code | usart_init (struct usart_module *const module, Sercom *const hw, const struct usart_config *const config) |
Initializes the device. More... | |
static bool | usart_is_syncing (const struct usart_module *const module) |
Check if peripheral is busy syncing registers across clock domains. More... | |
static void | usart_reset (const struct usart_module *const module) |
Resets the USART module. More... | |
Driver Feature Definition | |
Define SERCOM USART features set according to different device family. | |
#define | FEATURE_USART_SYNC_SCHEME_V2 |
USART sync scheme version 2. More... | |
#define | FEATURE_USART_OVER_SAMPLE |
USART oversampling. More... | |
#define | FEATURE_USART_HARDWARE_FLOW_CONTROL |
USART hardware control flow. More... | |
#define | FEATURE_USART_IRDA |
IrDA mode. More... | |
#define | FEATURE_USART_LIN_SLAVE |
LIN slave mode. More... | |
#define | FEATURE_USART_COLLISION_DECTION |
USART collision detection. More... | |
#define | FEATURE_USART_START_FRAME_DECTION |
USART start frame detection. More... | |
#define | FEATURE_USART_IMMEDIATE_BUFFER_OVERFLOW_NOTIFICATION |
USART start buffer overflow notification. More... | |
#define | FEATURE_USART_ISO7816 |
ISO7816 for smart card interfacing. More... | |
#define | FEATURE_USART_LIN_MASTER |
LIN master mode. More... | |
#define | FEATURE_USART_RS485 |
RS485 mode. More... | |
Lock/Unlock | |
static enum status_code | usart_lock (struct usart_module *const module) |
Attempt to get lock on driver instance. More... | |
static void | usart_unlock (struct usart_module *const module) |
Unlock driver instance. More... | |
Writing and Reading | |
enum status_code | usart_write_wait (struct usart_module *const module, const uint16_t tx_data) |
Transmit a character via the USART. More... | |
enum status_code | usart_read_wait (struct usart_module *const module, uint16_t *const rx_data) |
Receive a character via the USART. More... | |
enum status_code | usart_write_buffer_wait (struct usart_module *const module, const uint8_t *tx_data, uint16_t length) |
Transmit a buffer of characters via the USART. More... | |
enum status_code | usart_read_buffer_wait (struct usart_module *const module, uint8_t *rx_data, uint16_t length) |
Receive a buffer of length characters via the USART. More... | |
Enabling/Disabling Receiver and Transmitter | |
static void | usart_enable_transceiver (struct usart_module *const module, enum usart_transceiver_type transceiver_type) |
Enable Transceiver. More... | |
static void | usart_disable_transceiver (struct usart_module *const module, enum usart_transceiver_type transceiver_type) |
Disable Transceiver. More... | |
LIN Master Command and Status | |
static void | lin_master_send_cmd (struct usart_module *const module, enum lin_master_cmd cmd) |
Sending LIN command. More... | |
static bool | lin_master_transmission_status (struct usart_module *const module) |
Get LIN transmission status. More... | |
Callback Management | |
void | usart_register_callback (struct usart_module *const module, usart_callback_t callback_func, enum usart_callback callback_type) |
Registers a callback. More... | |
void | usart_unregister_callback (struct usart_module *module, enum usart_callback callback_type) |
Unregisters a callback. More... | |
static void | usart_enable_callback (struct usart_module *const module, enum usart_callback callback_type) |
Enables callback. More... | |
static void | usart_disable_callback (struct usart_module *const module, enum usart_callback callback_type) |
Disable callback. More... | |
Writing and Reading | |
enum status_code | usart_write_job (struct usart_module *const module, const uint16_t *tx_data) |
Asynchronous write a single char. More... | |
enum status_code | usart_read_job (struct usart_module *const module, uint16_t *const rx_data) |
Asynchronous read a single char. More... | |
enum status_code | usart_write_buffer_job (struct usart_module *const module, uint8_t *tx_data, uint16_t length) |
Asynchronous buffer write. More... | |
enum status_code | usart_read_buffer_job (struct usart_module *const module, uint8_t *rx_data, uint16_t length) |
Asynchronous buffer read. More... | |
void | usart_abort_job (struct usart_module *const module, enum usart_transceiver_type transceiver_type) |
Cancels ongoing read/write operation. More... | |
enum status_code | usart_get_job_status (struct usart_module *const module, enum usart_transceiver_type transceiver_type) |
Get status from the ongoing or last asynchronous transfer operation. More... | |
#define FEATURE_USART_COLLISION_DECTION |
USART collision detection.
#define FEATURE_USART_HARDWARE_FLOW_CONTROL |
USART hardware control flow.
#define FEATURE_USART_IMMEDIATE_BUFFER_OVERFLOW_NOTIFICATION |
USART start buffer overflow notification.
#define FEATURE_USART_IRDA |
IrDA mode.
#define FEATURE_USART_ISO7816 |
ISO7816 for smart card interfacing.
Referenced by _usart_set_config().
#define FEATURE_USART_LIN_MASTER |
LIN master mode.
#define FEATURE_USART_LIN_SLAVE |
LIN slave mode.
#define FEATURE_USART_OVER_SAMPLE |
USART oversampling.
#define FEATURE_USART_RS485 |
RS485 mode.
#define FEATURE_USART_START_FRAME_DECTION |
USART start frame detection.
Referenced by _usart_set_config().
#define FEATURE_USART_SYNC_SCHEME_V2 |
USART sync scheme version 2.
#define PINMUX_DEFAULT 0 |
Default pinmux.
Referenced by usart_get_config_defaults().
#define PINMUX_UNUSED 0xFFFFFFFF |
Unused pinmux.
Referenced by _spi_check_config(), _spi_set_config(), adp_interface_init(), HAL_RadioSpiInit(), run_baud_test(), run_spi_init_test(), setup_transfer_9bit_test(), and usart_init().
#define USART_TIMEOUT 0xFFFF |
USART timeout value.
Referenced by usart_read_buffer_wait(), and usart_write_buffer_wait().
typedef void(* usart_callback_t)(struct usart_module *const module) |
USART callback type.
Type of the callback functions.
enum iso7816_guard_time |
ISO7816 guard time.
The value of ISO7816 guard time.
enum iso7816_inhibit_nack |
LIN master break length.
Length of the break field transmitted when in LIN master mode
enum lin_master_cmd |
LIN master header delay.
LIN master header delay between break and sync transmission, and between the sync and identifier (ID) fields. This field is only valid when using automatically transmission command
enum lin_node_type |
enum rs485_guard_time |
RS485 Guard Time.
The value of RS485 guard time.
enum usart_callback |
USART callback enum.
Callbacks for the Asynchronous USART driver.
enum usart_character_size |
USART Character Size.
Number of bits for the character sent in a frame.
enum usart_dataorder |
USART Data Order enum.
The data order decides which MSB or LSB is shifted out first when data is transferred.
enum usart_parity |
USART Parity enum.
Select parity USART parity mode.
USART Sample Adjustment.
The value of sample number used for majority voting.
enum usart_sample_rate |
USART Sample Rate.
The value of sample rate and baudrate generation mode.
USART signal MUX settings.
Set the functionality of the SERCOM pins.
See SERCOM USART MUX Settings for a description of the various MUX setting options.
enum usart_stopbits |
enum usart_transfer_mode |
|
inlinestatic |
Sending LIN command.
Sending LIN command.
[in] | module | Pointer to USART software instance struct |
[in] | cmd | Cammand type |
|
inlinestatic |
Get LIN transmission status.
Get LIN transmission status.
[in] | module | Pointer to USART software instance struct |
true | Data transmission completed |
false | Transmission is ongoing |
void usart_abort_job | ( | struct usart_module *const | module, |
enum usart_transceiver_type | transceiver_type | ||
) |
Cancels ongoing read/write operation.
Cancels the ongoing read/write operation modifying parameters in the USART software struct.
[in] | module | Pointer to USART software instance struct |
[in] | transceiver_type | Transfer type to cancel |
References Assert, USART_TRANSCEIVER_RX, and USART_TRANSCEIVER_TX.
|
inlinestatic |
Disable module.
Disables the USART module.
[in] | module | Pointer to USART software instance struct |
References _sercom_get_interrupt_vector(), Assert, and system_interrupt_disable().
Referenced by enter_wifi_firmware_download(), run_transfer_single_9bit_char_test(), sio2host_deinit(), sio2host_disable(), uart_close(), uart_config(), usart_close(), and usart_reset().
|
inlinestatic |
Disable callback.
Disables the callback function registered by the usart_register_callback, and the callback will not be called from the interrupt routine.
[in] | module | Pointer to USART software instance struct |
[in] | callback_type | Callback type given by an enum |
References Assert.
Referenced by mqtt_callback(), run_buffer_write_blocking_read_interrupt_test(), and usart_tx_callback().
|
inlinestatic |
Disable Transceiver.
Disable the given transceiver (RX or TX).
[in] | module | Pointer to USART software instance struct |
[in] | transceiver_type | Transceiver type |
References Assert, USART_TRANSCEIVER_RX, and USART_TRANSCEIVER_TX.
Referenced by platform_set_ble_rts_high(), sio2host_deinit(), and usart_close().
|
inlinestatic |
Enable the module.
Enables the USART module.
[in] | module | Pointer to USART software instance struct |
References _sercom_get_interrupt_vector(), Assert, and system_interrupt_enable().
Referenced by cdc_rx_init(), cdc_uart_init(), configure_console(), configure_serial_drv(), configure_usart(), main(), run_transfer_single_9bit_char_test(), serial_bridge_init(), serial_console_init(), sio2host_enable(), sio2host_init(), test_system_init(), uart_config(), uart_open(), usart_configure(), usart_configure_flowcontrol(), and usart_open().
|
inlinestatic |
Enables callback.
Enables the callback function registered by the usart_register_callback. The callback function will be called from the interrupt handler when the conditions for the callback type are met.
[in] | module | Pointer to USART software instance struct |
[in] | callback_type | Callback type given by an enum |
References Assert.
Referenced by configure_console(), configure_serial_drv(), configure_usart_callbacks(), mqtt_callback(), run_buffer_read_write_interrupt_test(), run_buffer_write_blocking_read_interrupt_test(), serial_bridge_init(), uart_config(), uart_rx_notify(), usart_configure(), and usart_configure_flowcontrol().
|
inlinestatic |
Enable Transceiver.
Enable the given transceiver. Either RX or TX.
[in] | module | Pointer to USART software instance struct |
[in] | transceiver_type | Transceiver type |
References Assert, USART_TRANSCEIVER_RX, and USART_TRANSCEIVER_TX.
Referenced by cdc_rx_init(), platform_set_ble_rts_low(), sio2host_init(), and usart_open().
|
inlinestatic |
Initializes the device to predefined defaults.
Initialize the USART device to predefined defaults:
The configuration struct will be updated with the default configuration.
[in,out] | config | Pointer to configuration struct |
References Assert, usart_config::baudrate, usart_config::character_size, usart_config::clock_polarity_inverted, usart_config::collision_detection_enable, usart_config::data_order, iso7816_config_t::enable_inverse, iso7816_config_t::enabled, usart_config::encoding_format_enable, usart_config::ext_clock_freq, GCLK_GENERATOR_0, usart_config::generator_source, iso7816_config_t::guard_time, usart_config::immediate_buffer_overflow_notification, iso7816_config_t::inhibit_nack, usart_config::iso7816_config, ISO7816_GUARD_TIME_2_BIT, ISO7816_INHIBIT_NACK_DISABLE, ISO7816_PROTOCOL_T_0, ISO7816_SUCCESSIVE_RECV_NACK_DISABLE, usart_config::lin_break_length, usart_config::lin_header_delay, LIN_INVALID_MODE, LIN_MASTER_BREAK_LENGTH_13_BIT, LIN_MASTER_HEADER_DELAY_0, usart_config::lin_node, usart_config::lin_slave_enable, iso7816_config_t::max_iterations, usart_config::mux_setting, usart_config::parity, PINMUX_DEFAULT, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, iso7816_config_t::protocol_t, usart_config::receive_pulse_length, usart_config::receiver_enable, usart_config::rs485_guard_time, RS485_GUARD_TIME_0_BIT, usart_config::run_in_standby, usart_config::sample_adjustment, usart_config::sample_rate, usart_config::start_frame_detection_enable, usart_config::stopbits, iso7816_config_t::successive_recv_nack, usart_config::transfer_mode, usart_config::transmitter_enable, USART_CHARACTER_SIZE_8BIT, USART_DATAORDER_LSB, USART_PARITY_NONE, USART_RX_1_TX_2_XCK_3, USART_SAMPLE_ADJUSTMENT_7_8_9, USART_SAMPLE_RATE_16X_ARITHMETIC, USART_STOPBITS_1, USART_TRANSFER_ASYNCHRONOUSLY, and usart_config::use_external_clock.
Referenced by cdc_rx_init(), cdc_uart_init(), configure_console(), configure_serial_drv(), configure_usart(), main(), serial_bridge_init(), serial_console_init(), sio2host_init(), test_system_init(), uart_config(), usart_configure(), usart_configure_flowcontrol(), and usart_open().
enum status_code usart_get_job_status | ( | struct usart_module *const | module, |
enum usart_transceiver_type | transceiver_type | ||
) |
Get status from the ongoing or last asynchronous transfer operation.
Returns the error from a given ongoing or last asynchronous transfer operation. Either from a read or write transfer.
[in] | module | Pointer to USART software instance struct |
[in] | transceiver_type | Transfer type to check |
STATUS_OK | No error occurred during the last transfer |
STATUS_BUSY | A transfer is ongoing |
STATUS_ERR_BAD_DATA | The last operation was aborted due to a parity error. The transfer could be affected by external noise |
STATUS_ERR_BAD_FORMAT | The last operation was aborted due to a frame error |
STATUS_ERR_OVERFLOW | The last operation was aborted due to a buffer overflow |
STATUS_ERR_INVALID_ARG | An invalid transceiver enum given |
References Assert, STATUS_ERR_INVALID_ARG, USART_TRANSCEIVER_RX, and USART_TRANSCEIVER_TX.
Referenced by platform_serial_drv_tx_status(), serial_bridge_task(), and serial_drv_send().
enum status_code usart_init | ( | struct usart_module *const | module, |
Sercom *const | hw, | ||
const struct usart_config *const | config | ||
) |
Initializes the device.
Initializes the USART device based on the setting specified in the configuration struct.
[out] | module | Pointer to USART device |
[in] | hw | Pointer to USART hardware instance |
[in] | config | Pointer to configuration struct |
STATUS_OK | The initialization was successful |
STATUS_BUSY | The USART module is busy resetting |
STATUS_ERR_DENIED | The USART has not been disabled in advance of initialization |
STATUS_ERR_INVALID_ARG | The configuration struct contains invalid configuration |
STATUS_ERR_ALREADY_INITIALIZED | The SERCOM instance has already been initialized with different clock configuration |
STATUS_ERR_BAUD_UNAVAILABLE | The BAUD rate given by the configuration struct cannot be reached with the current clock configuration |
References _sercom_get_default_pad(), _sercom_get_sercom_inst_index(), _sercom_instances, _sercom_set_handler(), _usart_interrupt_handler(), _usart_set_config(), Assert, usart_config::character_size, system_pinmux_config::direction, iso7816_config_t::enabled, usart_config::generator_source, i, system_pinmux_config::input_pull, usart_config::iso7816_config, usart_config::lin_slave_enable, system_pinmux_config::mux_position, NULL, PINMUX_DEFAULT, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, PINMUX_UNUSED, usart_config::receiver_enable, sercom_set_gclk_generator(), system_gclk_chan_config::source_generator, usart_config::start_frame_detection_enable, STATUS_BUSY, STATUS_ERR_DENIED, STATUS_OK, system_apb_clock_set_mask(), SYSTEM_CLOCK_APB_APBC, SYSTEM_CLOCK_APB_APBD, system_gclk_chan_enable(), system_gclk_chan_get_config_defaults(), system_gclk_chan_set_config(), system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_DIR_INPUT, SYSTEM_PINMUX_PIN_PULL_NONE, system_pinmux_pin_set_config(), and usart_config::transmitter_enable.
Referenced by cdc_rx_init(), configure_serial_drv(), configure_usart(), run_transfer_single_9bit_char_test(), serial_bridge_init(), test_system_init(), uart_config(), usart_configure(), usart_configure_flowcontrol(), usart_open(), and usart_serial_init().
|
inlinestatic |
Check if peripheral is busy syncing registers across clock domains.
Return peripheral synchronization status. If doing a non-blocking implementation this function can be used to check the sync state and hold of any new actions until sync is complete. If this function is not run; the functions will block until the sync has completed.
[in] | module | Pointer to peripheral module |
true | Peripheral is busy syncing |
false | Peripheral is not busy syncing and can be read/written without stalling the bus |
References Assert.
|
inlinestatic |
Attempt to get lock on driver instance.
This function checks the instance's lock, which indicates whether or not it is currently in use, and sets the lock if it was not already set.
The purpose of this is to enable exclusive access to driver instances, so that, e.g., transactions by different services will not interfere with each other.
[in,out] | module | Pointer to the driver instance to lock |
STATUS_OK | If the module was locked |
STATUS_BUSY | If the module was already locked |
References STATUS_BUSY, STATUS_OK, system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().
enum status_code usart_read_buffer_job | ( | struct usart_module *const | module, |
uint8_t * | rx_data, | ||
uint16_t | length | ||
) |
Asynchronous buffer read.
Sets up the driver to read from the USART to a given buffer. If registered and enabled, a callback function will be called.
[in] | module | Pointer to USART software instance struct |
[out] | rx_data | Pointer to data buffer to receive |
[in] | length | Data buffer length |
STATUS_OK | If operation was completed |
STATUS_BUSY | If operation was not completed, due to the USART module being busy |
STATUS_ERR_INVALID_ARG | If operation was not completed, due to invalid arguments |
STATUS_ERR_DENIED | If the transmitter is not enabled |
References _usart_read_buffer(), Assert, STATUS_ERR_DENIED, and STATUS_ERR_INVALID_ARG.
Referenced by main(), nm_usart_protocol_handler(), run_buffer_read_write_interrupt_test(), run_buffer_write_blocking_read_interrupt_test(), serial_read_data(), uart_config(), usart_rx_callback(), and usart_tx_complete_handler().
enum status_code usart_read_buffer_wait | ( | struct usart_module *const | module, |
uint8_t * | rx_data, | ||
uint16_t | length | ||
) |
Receive a buffer of length
characters via the USART.
This blocking function will receive a block of length
characters via the USART.
*_job
) functions is not recommended as it has no functionality to check if there is an ongoing interrupt driven operation running or not.[in] | module | Pointer to USART software instance struct |
[out] | rx_data | Pointer to receive buffer |
[in] | length | Number of characters to receive |
STATUS_OK | If operation was completed |
STATUS_ERR_INVALID_ARG | If operation was not completed, due to an invalid argument being supplied |
STATUS_ERR_TIMEOUT | If operation was not completed, due to USART module timing out |
STATUS_ERR_BAD_FORMAT | If the operation was not completed, due to a configuration mismatch between USART and the sender |
STATUS_ERR_BAD_OVERFLOW | If the operation was not completed, due to the baudrate being too low or the system frequency being too high |
STATUS_ERR_BAD_DATA | If the operation was not completed, due to data being corrupted |
STATUS_ERR_DENIED | If the receiver is not enabled |
References Assert, i, STATUS_ERR_DENIED, STATUS_ERR_INVALID_ARG, STATUS_ERR_TIMEOUT, STATUS_OK, USART_CHARACTER_SIZE_9BIT, usart_read_wait(), and USART_TIMEOUT.
Referenced by usart_serial_read_packet().
enum status_code usart_read_job | ( | struct usart_module *const | module, |
uint16_t *const | rx_data | ||
) |
Asynchronous read a single char.
Sets up the driver to read data from the USART module to the data pointer given. If registered and enabled, a callback will be called when the receiving is completed.
[in] | module | Pointer to USART software instance struct |
[out] | rx_data | Pointer to where received data should be put |
STATUS_OK | If operation was completed |
STATUS_BUSY | If operation was not completed |
References _usart_read_buffer(), and Assert.
Referenced by configure_console(), main(), nm_usart_protocol_handler(), serial_eread_byte(), serial_read_byte(), uart_read_data(), and usart_tx_complete_handler().
enum status_code usart_read_wait | ( | struct usart_module *const | module, |
uint16_t *const | rx_data | ||
) |
Receive a character via the USART.
This blocking function will receive a character via the USART.
[in] | module | Pointer to the software instance struct |
[out] | rx_data | Pointer to received data |
STATUS_OK | If the operation was completed |
STATUS_BUSY | If the operation was not completed, due to the USART module being busy |
STATUS_ERR_BAD_FORMAT | If the operation was not completed, due to configuration mismatch between USART and the sender |
STATUS_ERR_BAD_OVERFLOW | If the operation was not completed, due to the baudrate being too low or the system frequency being too high |
STATUS_ERR_BAD_DATA | If the operation was not completed, due to data being corrupted |
STATUS_ERR_DENIED | If the receiver is not enabled |
References Assert, STATUS_BUSY, STATUS_ERR_BAD_DATA, STATUS_ERR_BAD_FORMAT, STATUS_ERR_DENIED, STATUS_ERR_OVERFLOW, STATUS_ERR_PACKET_COLLISION, STATUS_ERR_PROTOCOL, and STATUS_OK.
Referenced by getchar_timeout(), iso7816_get_char(), main(), run_transfer_single_8bit_char_test(), run_transfer_single_9bit_char_test(), usart_getc(), usart_read_buffer_wait(), and usart_serial_getchar().
void usart_register_callback | ( | struct usart_module *const | module, |
usart_callback_t | callback_func, | ||
enum usart_callback | callback_type | ||
) |
Registers a callback.
Registers a callback function, which is implemented by the user.
[in] | module | Pointer to USART software instance struct |
[in] | callback_func | Pointer to callback function |
[in] | callback_type | Callback type given by an enum |
References Assert.
Referenced by configure_console(), configure_serial_drv(), configure_usart_callbacks(), run_buffer_read_write_interrupt_test(), run_buffer_write_blocking_read_interrupt_test(), serial_bridge_init(), uart_config(), usart_configure(), and usart_configure_flowcontrol().
|
inlinestatic |
Resets the USART module.
Disables and resets the USART module.
[in] | module | Pointer to the USART software instance struct |
References Assert, and usart_disable().
Referenced by configure_serial_drv(), main(), test_standby_mode_dynamic_power_sleepwalking(), test_standby_mode_static_power_sleepwalking(), usart_configure(), and usart_configure_flowcontrol().
|
inlinestatic |
Unlock driver instance.
This function clears the instance lock, indicating that it is available for use.
[in,out] | module | Pointer to the driver instance to lock |
void usart_unregister_callback | ( | struct usart_module *const | module, |
enum usart_callback | callback_type | ||
) |
Unregisters a callback.
Unregisters a callback function, which is implemented by the user.
[in,out] | module | Pointer to USART software instance struct |
[in] | callback_type | Callback type given by an enum |
Referenced by run_buffer_write_blocking_read_interrupt_test().
enum status_code usart_write_buffer_job | ( | struct usart_module *const | module, |
uint8_t * | tx_data, | ||
uint16_t | length | ||
) |
Asynchronous buffer write.
Sets up the driver to write a given buffer over the USART. If registered and enabled, a callback function will be called.
[in] | module | Pointer to USART software instance struct |
[in] | tx_data | Pointer do data buffer to transmit |
[in] | length | Length of the data to transmit |
STATUS_OK | If operation was completed successfully. |
STATUS_BUSY | If operation was not completed, due to the USART module being busy |
STATUS_ERR_INVALID_ARG | If operation was not completed, due to invalid arguments |
STATUS_ERR_DENIED | If the transmitter is not enabled |
References _usart_write_buffer(), Assert, STATUS_ERR_DENIED, and STATUS_ERR_INVALID_ARG.
Referenced by enter_wifi_firmware_download(), nm_usart_send_regval(), run_buffer_read_write_interrupt_test(), serial_drv_send(), uart_rx_notify(), usart_read_callback(), and usart_tx_callback().
enum status_code usart_write_buffer_wait | ( | struct usart_module *const | module, |
const uint8_t * | tx_data, | ||
uint16_t | length | ||
) |
Transmit a buffer of characters via the USART.
This blocking function will transmit a block of length
characters via the USART.
_job
) functions is not recommended as it has no functionality to check if there is an ongoing interrupt driven operation running or not.[in] | module | Pointer to USART software instance struct |
[in] | tx_data | Pointer to data to transmit |
[in] | length | Number of characters to transmit |
STATUS_OK | If operation was completed |
STATUS_ERR_INVALID_ARG | If operation was not completed, due to invalid arguments |
STATUS_ERR_TIMEOUT | If operation was not completed, due to USART module timing out |
STATUS_ERR_DENIED | If the transmitter is not enabled |
References Assert, i, STATUS_ERR_DENIED, STATUS_ERR_INVALID_ARG, STATUS_ERR_TIMEOUT, STATUS_OK, USART_CHARACTER_SIZE_9BIT, USART_TIMEOUT, and usart_write_wait().
Referenced by main(), run_buffer_write_blocking_read_interrupt_test(), and usart_serial_write_packet().
enum status_code usart_write_job | ( | struct usart_module *const | module, |
const uint16_t * | tx_data | ||
) |
Asynchronous write a single char.
Sets up the driver to write the data given. If registered and enabled, a callback function will be called when the transmit is completed.
[in] | module | Pointer to USART software instance struct |
[in] | tx_data | Data to transfer |
STATUS_OK | If operation was completed |
STATUS_BUSY | If operation was not completed, due to the USART module being busy |
STATUS_ERR_DENIED | If the transmitter is not enabled |
References _usart_write_buffer(), Assert, and STATUS_ERR_DENIED.
Referenced by enter_wifi_firmware_download(), nm_usart_protocol_handler(), serial_bridge_task(), and serial_drv_edbg_write_cb().
enum status_code usart_write_wait | ( | struct usart_module *const | module, |
const uint16_t | tx_data | ||
) |
Transmit a character via the USART.
This blocking function will transmit a single character via the USART.
[in] | module | Pointer to the software instance struct |
[in] | tx_data | Data to transfer |
STATUS_OK | If the operation was completed |
STATUS_BUSY | If the operation was not completed, due to the USART module being busy |
STATUS_ERR_DENIED | If the transmitter is not enabled |
References Assert, STATUS_BUSY, STATUS_ERR_DENIED, STATUS_OK, and tx_data.
Referenced by iso7816_send_char(), main(), run_transfer_single_8bit_char_test(), run_transfer_single_9bit_char_test(), usart_putc(), usart_serial_putchar(), and usart_write_buffer_wait().