16.8.1.1.3 Workflow
- Create a module software instance structure for the USART module to store the USART driver state while it is in use.
struct
usart_module usart_instance;
Note: This should never go out of scope as long as the module is in use. In most cases, this should be global. - Configure the USART module.
- Create a USART module configuration struct, which can be filled out to adjust the configuration of a physical USART peripheral.
struct
usart_config config_usart;
- Initialize the USART configuration struct with the module's default values.
usart_get_config_defaults(&config_usart);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings. - Alter the USART settings to configure the physical pinout, baudrate, and other relevant parameters.
config_usart.baudrate = 9600;
config_usart.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
- Configure the USART module with the desired settings, retrying while the driver is busy until the configuration is stressfully set.
while
(usart_init(&usart_instance,
EDBG_CDC_MODULE, &config_usart) != STATUS_OK) {
}
- Enable the USART module.
usart_enable(&usart_instance);