Universal Asynchronous Receiver-Transmitter (UART)

Overview

Zephyr provides three different ways to access the UART peripheral. Depending on the method, different API functions are used according to below sections:

  1. Polling API

  2. Interrupt-driven API

  3. Asynchronous API using Direct Memory Access (DMA)

Polling is the most basic method to access the UART peripheral. The reading function, uart_poll_in, is a non-blocking function and returns a character or -1 when no valid data is available. The writing function, uart_poll_out, is a blocking function and the thread waits until the given character is sent.

With the Interrupt-driven API, possibly slow communication can happen in the background while the thread continues with other tasks. The Kernel’s Data Passing features can be used to communicate between the thread and the UART driver.

The Asynchronous API allows to read and write data in the background using DMA without interrupting the MCU at all. However, the setup is more complex than the other methods.

Warning

Interrupt-driven API and the Asynchronous API should NOT be used at the same time for the same hardware peripheral, since both APIs require hardware interrupts to function properly. Using the callbacks for both APIs would result in interference between each other. CONFIG_UART_EXCLUSIVE_API_CALLBACKS is enabled by default so that only the callbacks associated with one API is active at a time.

Configuration Options

Most importantly, the Kconfig options define whether the polling API (default), the interrupt-driven API or the asynchronous API can be used. Only enable the features you need in order to minimize memory footprint.

Related configuration options:

API Reference

UART Interface

Polling API

Polling UART API

Interrupt-driven API

Interrupt-driven UART API

Asynchronous API

Async UART API