Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM Serial USART (SERCOM USART) Driver

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:

Prerequisites

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.

Module Overview

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 Definition

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
Note
The specific features are only available in the driver when the selected device supports those features.

Frame Format

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.

USART Frame Parameters
Parameter Options
Start bit 1
Data bits 5, 6, 7, 8, 9
Parity bit None, Even, Odd
Stop bits 1, 2

usart_frame.svg
USART Frame Overview

Synchronous Mode

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:

Data Sampling

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.

Asynchronous Mode

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:

Transmitter/receiver Clock Matching

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

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.

GPIO Configuration

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.

Special Considerations

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.

Extra Information

For extra information, see Extra Information for SERCOM USART Driver. This includes:

Examples

For a list of examples related to this driver, see Examples for SERCOM USART Driver.

API Overview

Modules

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

ISO7816 guard time.

The value of ISO7816 guard time.

Enumerator
ISO7816_GUARD_TIME_2_BIT 

The guard time is 2-bit times.

ISO7816_GUARD_TIME_3_BIT 

The guard time is 3-bit times.

ISO7816_GUARD_TIME_4_BIT 

The guard time is 4-bit times.

ISO7816_GUARD_TIME_5_BIT 

The guard time is 5-bit times.

ISO7816_GUARD_TIME_6_BIT 

The guard time is 6-bit times.

ISO7816_GUARD_TIME_7_BIT 

The guard time is 7-bit times.

ISO7816 receive NACK inhibit.

The value of ISO7816 receive NACK inhibit.

Enumerator
ISO7816_INHIBIT_NACK_DISABLE 

The NACK is generated.

ISO7816_INHIBIT_NACK_ENABLE 

The NACK is not generated.

ISO7816 protocol type.

ISO7816 protocol type.

Enumerator
ISO7816_PROTOCOL_T_0 

ISO7816 protocol type 0.

ISO7816_PROTOCOL_T_1 

ISO7816 protocol type 1.

ISO7816 disable successive receive NACK.

The value of ISO7816 disable successive receive NACK.

Enumerator
ISO7816_SUCCESSIVE_RECV_NACK_DISABLE 

The successive receive NACK is enable.

ISO7816_SUCCESSIVE_RECV_NACK_ENABLE 

The successive receive NACK is disable.

LIN master break length.

Length of the break field transmitted when in LIN master mode

Enumerator
LIN_MASTER_BREAK_LENGTH_13_BIT 

Break field transmission is 13 bit times.

LIN_MASTER_BREAK_LENGTH_17_BIT 

Break field transmission is 17 bit times.

LIN_MASTER_BREAK_LENGTH_21_BIT 

Break field transmission is 21 bit times.

LIN_MASTER_BREAK_LENGTH_26_BIT 

Break field transmission is 26 bit times.

LIN master command enum.

LIN master command enum.

Enumerator
LIN_MASTER_SOFTWARE_CONTROL_TRANSMIT_CMD 

LIN master software control transmission command.

LIN_MASTER_AUTO_TRANSMIT_CMD 

LIN master automatically transmission command.

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

Enumerator
LIN_MASTER_HEADER_DELAY_0 

Delay between break and sync transmission is 1 bit time.

Delay between sync and ID transmission is 1 bit time.

LIN_MASTER_HEADER_DELAY_1 

Delay between break and sync transmission is 4 bit time.

Delay between sync and ID transmission is 4 bit time.

LIN_MASTER_HEADER_DELAY_2 

Delay between break and sync transmission is 8 bit time.

Delay between sync and ID transmission is 4 bit time.

LIN_MASTER_HEADER_DELAY_3 

Delay between break and sync transmission is 14 bit time.

Delay between sync and ID transmission is 4 bit time.

LIN node type.

LIN node type.

Enumerator
LIN_MASTER_NODE 

LIN master mode.

LIN_SLAVE_NODE 

LIN slave mode.

LIN_INVALID_MODE 

Neither LIN master nor LIN slave mode.

RS485 Guard Time.

The value of RS485 guard time.

Enumerator
RS485_GUARD_TIME_0_BIT 

The guard time is 0-bit time.

RS485_GUARD_TIME_1_BIT 

The guard time is 1-bit time.

RS485_GUARD_TIME_2_BIT 

The guard time is 2-bit times.

RS485_GUARD_TIME_3_BIT 

The guard time is 3-bit times.

RS485_GUARD_TIME_4_BIT 

The guard time is 4-bit times.

RS485_GUARD_TIME_5_BIT 

The guard time is 5-bit times.

RS485_GUARD_TIME_6_BIT 

The guard time is 6-bit times.

RS485_GUARD_TIME_7_BIT 

The guard time is 7-bit times.

USART callback enum.

Callbacks for the Asynchronous USART driver.

Enumerator
USART_CALLBACK_BUFFER_TRANSMITTED 

Callback for buffer transmitted.

USART_CALLBACK_BUFFER_RECEIVED 

Callback for buffer received.

USART_CALLBACK_ERROR 

Callback for error.

USART_CALLBACK_BREAK_RECEIVED 

Callback for break character is received.

USART_CALLBACK_CTS_INPUT_CHANGE 

Callback for a change is detected on the CTS pin.

USART_CALLBACK_START_RECEIVED 

Callback for a start condition is detected on the RxD line.

USART Character Size.

Number of bits for the character sent in a frame.

Enumerator
USART_CHARACTER_SIZE_5BIT 

The char being sent in a frame is five bits long.

USART_CHARACTER_SIZE_6BIT 

The char being sent in a frame is six bits long.

USART_CHARACTER_SIZE_7BIT 

The char being sent in a frame is seven bits long.

USART_CHARACTER_SIZE_8BIT 

The char being sent in a frame is eight bits long.

USART_CHARACTER_SIZE_9BIT 

The char being sent in a frame is nine bits long.

USART Data Order enum.

The data order decides which MSB or LSB is shifted out first when data is transferred.

Enumerator
USART_DATAORDER_MSB 

The MSB will be shifted out first during transmission, and shifted in first during reception.

USART_DATAORDER_LSB 

The LSB will be shifted out first during transmission, and shifted in first during reception.

USART Parity enum.

Select parity USART parity mode.

Enumerator
USART_PARITY_ODD 

For odd parity checking, the parity bit will be set if number of ones being transferred is even.

USART_PARITY_EVEN 

For even parity checking, the parity bit will be set if number of ones being received is odd.

USART_PARITY_NONE 

No parity checking will be executed, and there will be no parity bit in the received frame.

USART Sample Adjustment.

The value of sample number used for majority voting.

Enumerator
USART_SAMPLE_ADJUSTMENT_7_8_9 

The first, middle and last sample number used for majority voting is 7-8-9.

USART_SAMPLE_ADJUSTMENT_9_10_11 

The first, middle and last sample number used for majority voting is 9-10-11.

USART_SAMPLE_ADJUSTMENT_11_12_13 

The first, middle and last sample number used for majority voting is 11-12-13.

USART_SAMPLE_ADJUSTMENT_13_14_15 

The first, middle and last sample number used for majority voting is 13-14-15.

USART Sample Rate.

The value of sample rate and baudrate generation mode.

Enumerator
USART_SAMPLE_RATE_16X_ARITHMETIC 

16x over-sampling using arithmetic baudrate generation

USART_SAMPLE_RATE_16X_FRACTIONAL 

16x over-sampling using fractional baudrate generation

USART_SAMPLE_RATE_8X_ARITHMETIC 

8x over-sampling using arithmetic baudrate generation

USART_SAMPLE_RATE_8X_FRACTIONAL 

8x over-sampling using fractional baudrate generation

USART_SAMPLE_RATE_3X_ARITHMETIC 

3x over-sampling using arithmetic baudrate generation

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.

Enumerator
USART_RX_0_TX_0_XCK_1 

MUX setting RX_0_TX_0_XCK_1.

USART_RX_0_TX_2_XCK_3 

MUX setting RX_0_TX_2_XCK_3.

USART_RX_0_TX_0_RTS_2_CTS_3 

MUX setting USART_RX_0_TX_0_RTS_2_CTS_3.

USART_RX_1_TX_0_XCK_1 

MUX setting RX_1_TX_0_XCK_1.

USART_RX_1_TX_2_XCK_3 

MUX setting RX_1_TX_2_XCK_3.

USART_RX_1_TX_0_RTS_2_CTS_3 

MUX setting USART_RX_1_TX_0_RTS_2_CTS_3.

USART_RX_2_TX_0_XCK_1 

MUX setting RX_2_TX_0_XCK_1.

USART_RX_2_TX_2_XCK_3 

MUX setting RX_2_TX_2_XCK_3.

USART_RX_2_TX_0_RTS_2_CTS_3 

MUX setting USART_RX_2_TX_0_RTS_2_CTS_3.

USART_RX_3_TX_0_XCK_1 

MUX setting RX_3_TX_0_XCK_1.

USART_RX_3_TX_2_XCK_3 

MUX setting RX_3_TX_2_XCK_3.

USART_RX_3_TX_0_RTS_2_CTS_3 

MUX setting USART_RX_3_TX_0_RTS_2_CTS_3.

USART_RX_0_TX_0_XCK_1_TE_2 

MUX setting USART_RX_0_TX_0_XCK_1_TE_2.

USART_RX_1_TX_0_XCK_1_TE_2 

MUX setting USART_RX_1_TX_0_XCK_1_TE_2.

USART_RX_2_TX_0_XCK_1_TE_2 

MUX setting USART_RX_2_TX_0_XCK_1_TE_2.

USART_RX_3_TX_0_XCK_1_TE_2 

MUX setting USART_RX_3_TX_0_XCK_1_TE_2.

USART Stop Bits enum.

Number of stop bits for a frame.

Enumerator
USART_STOPBITS_1 

Each transferred frame contains one stop bit.

USART_STOPBITS_2 

Each transferred frame contains two stop bits.

USART Transceiver.

Select Receiver or Transmitter.

Enumerator
USART_TRANSCEIVER_RX 

The parameter is for the Receiver.

USART_TRANSCEIVER_TX 

The parameter is for the Transmitter.

USART Transfer mode enum.

Select USART transfer mode.

Enumerator
USART_TRANSFER_SYNCHRONOUSLY 

Transfer of data is done synchronously.

USART_TRANSFER_ASYNCHRONOUSLY 

Transfer of data is done asynchronously.

static void lin_master_send_cmd ( struct usart_module *const  module,
enum lin_master_cmd  cmd 
)
inlinestatic

Sending LIN command.

Sending LIN command.

Parameters
[in]modulePointer to USART software instance struct
[in]cmdCammand type
static bool lin_master_transmission_status ( struct usart_module *const  module)
inlinestatic

Get LIN transmission status.

Get LIN transmission status.

Parameters
[in]modulePointer to USART software instance struct
Returns
Status of LIN master transmission.
Return values
trueData transmission completed
falseTransmission 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.

Parameters
[in]modulePointer to USART software instance struct
[in]transceiver_typeTransfer type to cancel

References Assert, USART_TRANSCEIVER_RX, and USART_TRANSCEIVER_TX.

static void usart_disable ( const struct usart_module *const  module)
inlinestatic

Disable module.

Disables the USART module.

Parameters
[in]modulePointer 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().

static void usart_disable_callback ( struct usart_module *const  module,
enum usart_callback  callback_type 
)
inlinestatic

Disable callback.

Disables the callback function registered by the usart_register_callback, and the callback will not be called from the interrupt routine.

Parameters
[in]modulePointer to USART software instance struct
[in]callback_typeCallback type given by an enum

References Assert.

Referenced by mqtt_callback(), run_buffer_write_blocking_read_interrupt_test(), and usart_tx_callback().

static void usart_disable_transceiver ( struct usart_module *const  module,
enum usart_transceiver_type  transceiver_type 
)
inlinestatic

Disable Transceiver.

Disable the given transceiver (RX or TX).

Parameters
[in]modulePointer to USART software instance struct
[in]transceiver_typeTransceiver type

References Assert, USART_TRANSCEIVER_RX, and USART_TRANSCEIVER_TX.

Referenced by platform_set_ble_rts_high(), sio2host_deinit(), and usart_close().

static void usart_enable ( const struct usart_module *const  module)
inlinestatic
static void usart_enable_callback ( struct usart_module *const  module,
enum usart_callback  callback_type 
)
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.

Parameters
[in]modulePointer to USART software instance struct
[in]callback_typeCallback 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().

static void usart_enable_transceiver ( struct usart_module *const  module,
enum usart_transceiver_type  transceiver_type 
)
inlinestatic

Enable Transceiver.

Enable the given transceiver. Either RX or TX.

Parameters
[in]modulePointer to USART software instance struct
[in]transceiver_typeTransceiver 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().

static void usart_get_config_defaults ( struct usart_config *const  config)
inlinestatic

Initializes the device to predefined defaults.

Initialize the USART device to predefined defaults:

  • 8-bit asynchronous USART
  • No parity
  • One stop bit
  • 9600 baud
  • Transmitter enabled
  • Receiver enabled
  • GCLK generator 0 as clock source
  • Default pin configuration

The configuration struct will be updated with the default configuration.

Parameters
[in,out]configPointer 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.

Parameters
[in]modulePointer to USART software instance struct
[in]transceiver_typeTransfer type to check
Returns
Status of the given job.
Return values
STATUS_OKNo error occurred during the last transfer
STATUS_BUSYA transfer is ongoing
STATUS_ERR_BAD_DATAThe last operation was aborted due to a parity error. The transfer could be affected by external noise
STATUS_ERR_BAD_FORMATThe last operation was aborted due to a frame error
STATUS_ERR_OVERFLOWThe last operation was aborted due to a buffer overflow
STATUS_ERR_INVALID_ARGAn 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.

Parameters
[out]modulePointer to USART device
[in]hwPointer to USART hardware instance
[in]configPointer to configuration struct
Returns
Status of the initialization.
Return values
STATUS_OKThe initialization was successful
STATUS_BUSYThe USART module is busy resetting
STATUS_ERR_DENIEDThe USART has not been disabled in advance of initialization
STATUS_ERR_INVALID_ARGThe configuration struct contains invalid configuration
STATUS_ERR_ALREADY_INITIALIZEDThe SERCOM instance has already been initialized with different clock configuration
STATUS_ERR_BAUD_UNAVAILABLEThe 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().

static bool usart_is_syncing ( const struct usart_module *const  module)
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.

Parameters
[in]modulePointer to peripheral module
Returns
Peripheral sync status.
Return values
truePeripheral is busy syncing
falsePeripheral is not busy syncing and can be read/written without stalling the bus

References Assert.

static enum status_code usart_lock ( struct usart_module *const  module)
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.

Parameters
[in,out]modulePointer to the driver instance to lock
Return values
STATUS_OKIf the module was locked
STATUS_BUSYIf 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.

Parameters
[in]modulePointer to USART software instance struct
[out]rx_dataPointer to data buffer to receive
[in]lengthData buffer length
Note
If using 9-bit data, the array that rx_data point to should be defined as uint16_t array and should be casted to uint8_t pointer. Because it is an address pointer, the highest byte is not discarded. For example:
#define RX_LEN 3
uint16_t rx_buf[RX_LEN] = {0x0,};
usart_read_buffer_job(&module, (uint8_t*)rx_buf, RX_LEN);
Returns
Status of the operation.
Return values
STATUS_OKIf operation was completed
STATUS_BUSYIf operation was not completed, due to the USART module being busy
STATUS_ERR_INVALID_ARGIf operation was not completed, due to invalid arguments
STATUS_ERR_DENIEDIf 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.

Note
Using this function in combination with the interrupt (*_job) functions is not recommended as it has no functionality to check if there is an ongoing interrupt driven operation running or not.
Parameters
[in]modulePointer to USART software instance struct
[out]rx_dataPointer to receive buffer
[in]lengthNumber of characters to receive
Note
If using 9-bit data, the array that rx_data point to should be defined as uint16_t array and should be casted to uint8_t pointer. Because it is an address pointer, the highest byte is not discarded. For example:
#define RX_LEN 3
uint16_t rx_buf[RX_LEN] = {0x0,};
usart_read_buffer_wait(&module, (uint8_t*)rx_buf, RX_LEN);
Returns
Status of the operation.
Return values
STATUS_OKIf operation was completed
STATUS_ERR_INVALID_ARGIf operation was not completed, due to an invalid argument being supplied
STATUS_ERR_TIMEOUTIf operation was not completed, due to USART module timing out
STATUS_ERR_BAD_FORMATIf the operation was not completed, due to a configuration mismatch between USART and the sender
STATUS_ERR_BAD_OVERFLOWIf the operation was not completed, due to the baudrate being too low or the system frequency being too high
STATUS_ERR_BAD_DATAIf the operation was not completed, due to data being corrupted
STATUS_ERR_DENIEDIf 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.

Parameters
[in]modulePointer to USART software instance struct
[out]rx_dataPointer to where received data should be put
Returns
Status of the operation.
Return values
STATUS_OKIf operation was completed
STATUS_BUSYIf 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.

Parameters
[in]modulePointer to the software instance struct
[out]rx_dataPointer to received data
Returns
Status of the operation.
Return values
STATUS_OKIf the operation was completed
STATUS_BUSYIf the operation was not completed, due to the USART module being busy
STATUS_ERR_BAD_FORMATIf the operation was not completed, due to configuration mismatch between USART and the sender
STATUS_ERR_BAD_OVERFLOWIf the operation was not completed, due to the baudrate being too low or the system frequency being too high
STATUS_ERR_BAD_DATAIf the operation was not completed, due to data being corrupted
STATUS_ERR_DENIEDIf 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.

Note
The callback must be enabled by usart_enable_callback in order for the interrupt handler to call it when the conditions for the callback type are met.
Parameters
[in]modulePointer to USART software instance struct
[in]callback_funcPointer to callback function
[in]callback_typeCallback 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().

static void usart_reset ( const struct usart_module *const  module)
inlinestatic

Resets the USART module.

Disables and resets the USART module.

Parameters
[in]modulePointer 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().

static void usart_unlock ( struct usart_module *const  module)
inlinestatic

Unlock driver instance.

This function clears the instance lock, indicating that it is available for use.

Parameters
[in,out]modulePointer 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.

Parameters
[in,out]modulePointer to USART software instance struct
[in]callback_typeCallback type given by an enum

References Assert, and NULL.

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.

Parameters
[in]modulePointer to USART software instance struct
[in]tx_dataPointer do data buffer to transmit
[in]lengthLength of the data to transmit
Note
If using 9-bit data, the array that tx_data point to should be defined as uint16_t array and should be casted to uint8_t pointer. Because it is an address pointer, the highest byte is not discarded. For example:
#define TX_LEN 3
uint16_t tx_buf[TX_LEN] = {0x0111, 0x0022, 0x0133};
usart_write_buffer_job(&module, (uint8_t*)tx_buf, TX_LEN);
Returns
Status of the operation.
Return values
STATUS_OKIf operation was completed successfully.
STATUS_BUSYIf operation was not completed, due to the USART module being busy
STATUS_ERR_INVALID_ARGIf operation was not completed, due to invalid arguments
STATUS_ERR_DENIEDIf 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.

Note
Using this function in combination with the interrupt (_job) functions is not recommended as it has no functionality to check if there is an ongoing interrupt driven operation running or not.
Parameters
[in]modulePointer to USART software instance struct
[in]tx_dataPointer to data to transmit
[in]lengthNumber of characters to transmit
Note
If using 9-bit data, the array that tx_data point to should be defined as uint16_t array and should be casted to uint8_t pointer. Because it is an address pointer, the highest byte is not discarded. For example:
#define TX_LEN 3
uint16_t tx_buf[TX_LEN] = {0x0111, 0x0022, 0x0133};
usart_write_buffer_wait(&module, (uint8_t*)tx_buf, TX_LEN);
Returns
Status of the operation.
Return values
STATUS_OKIf operation was completed
STATUS_ERR_INVALID_ARGIf operation was not completed, due to invalid arguments
STATUS_ERR_TIMEOUTIf operation was not completed, due to USART module timing out
STATUS_ERR_DENIEDIf 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.

Parameters
[in]modulePointer to USART software instance struct
[in]tx_dataData to transfer
Returns
Status of the operation.
Return values
STATUS_OKIf operation was completed
STATUS_BUSYIf operation was not completed, due to the USART module being busy
STATUS_ERR_DENIEDIf 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.

Parameters
[in]modulePointer to the software instance struct
[in]tx_dataData to transfer
Returns
Status of the operation.
Return values
STATUS_OKIf the operation was completed
STATUS_BUSYIf the operation was not completed, due to the USART module being busy
STATUS_ERR_DENIEDIf 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().