CLI tool
MaJerle/stm32-usart-uart-dma-rx-tx avatar
MaJerle/stm32-usart-uart-dma-rx-tx

STM32 USART UART DMA RX and TX Examples

STM32 examples for USART using DMA for efficient RX and TX transmission

1,839 stars398 forksCMIT

At a glance

What is it?
MaJerle/stm32-usart-uart-dma-rx-tx is a collection of STM32 C examples for UART DMA reception and transmission, aimed at embedded developers who need to handle variable-length input and offload transfers from the CPU. Its examples use CMake, Ninja and GCC, with a particular focus on IDLE line and RTO receive events.
Who is it for?
Adopt this repository when you need reference examples for STM32 UART DMA, especially unknown-length reception with IDLE or RTO events. Do not treat it as a complete protocol stack or a substitute for device-specific reference-manual work.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 41 days ago.
What is it written in?
Mainly C, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 22, 2026, and from our analysis. They are not legal advice.

Editorial analysis

Why STM32 UART DMA Examples Exist

This repository addresses two embedded communication problems. The first is receiving data when the application does not know the packet length before the transfer begins. The second is transmitting data without keeping the CPU occupied while the UART moves bytes. The target audience is developers working directly with STM32 C firmware, especially applications using USART, UART or LPUART peripherals and a DMA controller.

The README contrasts polling, interrupt-driven and DMA-based communication. Polling requires the CPU to inspect status bits and can lose received data when the application cannot read registers quickly enough. Interrupt mode handles each received character but creates an interrupt for every byte, which can reduce performance at higher baud rates. DMA moves data between the UART data register and memory at the hardware level. According to the application note, this approach is intended for higher baud rates, operating systems, low-power systems and large bursts.

DMA does not remove the protocol problem. A DMA transfer normally requires a transfer length, while UART data does not inherently announce how many bytes form one message. The examples therefore focus on receiving an indeterminate stream and determining when a useful group of bytes has arrived. They also assume a reliable low-level protocol, although the repository does not document a complete framing protocol.

UART DMA Receive and Transmit Data Flow

For reception, the peripheral writes incoming UART bytes into a memory buffer through DMA. The application must still decide when the accumulated bytes should be processed. The README describes two STM32 mechanisms that can mark a pause in the incoming stream. An IDLE line event occurs after the RX line remains inactive for one UART frame time following the last received byte. A Receiver Timeout, or RTO, event occurs after a programmable idle period and can be configured by firmware.

These events can trigger interrupts, which is the central mechanism in the variable-length receive examples. At 115200 baud, the README gives an example in which three bytes take approximately 300 microseconds to arrive, followed by an IDLE event after approximately one frame time. The exact timing depends on the UART configuration and the MCU, so the example should be read as an explanation of the sequence rather than as a universal timing guarantee.

The transmit path is simpler. The application sets the DMA destination pointer, defines the number of bytes and starts the transfer. The README describes this as a straightforward implementation because, unlike an unknown-length receive stream, the sender normally knows how much data it is transmitting. CPU involvement is reduced once DMA is configured, but the repository does not claim that the CPU has no other work at all. Peripheral setup, interrupt handling and buffer management remain software responsibilities.

CMake, Ninja and GCC Setup for the Examples

The README says to clone the repository or download its zip package, install CMake, Ninja and the ARM GCC compiler, and make sure the tools are available on `PATH`. It also names `STM32CubeCLT` as a way to obtain the command-line tools for STM32 development. The examples are C projects generated with CMake and Ninja, and each project includes a `.vscode` folder with basic task, launch and debug configuration.

A Python helper can build all examples at once. It accepts an optional `--clean` switch and an optional `--path` value for a project directory:

bash
python3 scripts/build.py [--clean] [--path projects/project-folder]

The repository presents this as the path for building all examples. The placeholder names are shown in the README command, so the reader should replace them with the actual project path and the actual preset name required by that project.

For a selected project, the documented command-line sequence first enters the project directory, lists available presets, configures one preset and builds it:

bash
cd projects/projects-folder
cmake --list-presets
cmake --preset <preset_name>
cmake --build --preset <preset_name>

`cmake --list-presets` should reveal the presets defined by that project. The next command configures the selected preset, and the build command produces the configured target. The README does not provide a hardware wiring procedure, board-specific flashing command or complete device initialization tutorial.

IDLE Line and RTO Support Are Device-Dependent

The receive strategy has a hardware boundary. The README explicitly warns that not every STM32 has IDLE line or RTO functionality. An example based on either feature may therefore be unusable on a particular part even when the MCU has a UART and DMA controller. Before selecting a project, check the device reference manual and application notes for UART event support, interrupt vectors and DMA channel or stream availability.

There is also a configuration dependency between baud rate and event interpretation. IDLE detection is tied to a UART frame time, so changing the baud rate changes how long the line must remain inactive before the event occurs. RTO is programmable, but the firmware must configure it according to the selected MCU. The repository documentation focuses on the event mechanism, not on a portable timing configuration for every STM32 family.

The examples should therefore be read as device-oriented references. They are useful when your target has the required peripheral feature and the project configuration matches its pinout, clock tree and DMA resources. They are less suitable as a generic UART library that can be moved between STM32 products without reviewing the hardware configuration.

Where the Examples Are the Wrong Tool

This repository is not a complete serial protocol implementation. The README assumes that the application needs to identify received data at a low level, but it does not provide a documented packet format, checksum scheme, timeout policy for higher-level messages or flow-control protocol. If the data is already framed with a fixed length, another DMA arrangement may be simpler. If the protocol already supplies explicit length information, the application can use that information instead of relying primarily on idle-line detection.

It is also not a general-purpose STM32 board support package. The documented build tools and examples are useful, but the repository entries show separate drivers, middlewares, projects, CMake files and scripts. That structure indicates a collection of examples rather than a single installable library with a stable public API. Consumers should expect to inspect project-specific startup code, linker files, peripheral initialization and CMake presets.

For very low baud rates or small messages, polling or interrupts may be sufficient. DMA introduces buffer configuration, event handling and the need to distinguish complete data from partially filled buffers. For systems where every byte requires immediate application processing, an interrupt-driven design may be easier to reason about. The README presents DMA advantages, but it does not quantify memory use, interrupt latency or throughput for a specific board and buffer size.

Maintenance, Releases and the MIT License

The repository is not archived, and its last push was on 2026-09-12. That establishes the latest recorded repository activity, but the README does not describe a release cadence or a compatibility policy. The repository has no GitHub releases, so users should not assume that tagged releases or a published upgrade path exist. Upgrade cost is therefore tied to inspecting changes in source, adapting project configuration to the target MCU and checking whether the peripheral assumptions still match the hardware.

The project is licensed under the MIT License. That identifier permits reuse and modification under the license terms, but this review does not provide legal advice. Consumers still need to review the repository's `LICENSE` file and preserve any notices required by it when redistributing code.

The top-level layout includes `drivers/`, `middlewares/`, `projects/`, `cmake/`, `docs/` and `scripts/`. Based on that layout, adoption involves selecting an example project and understanding its local files rather than installing one package into an unrelated application. The documentation does not state which STM32 families are supported across all examples, so the chosen project directory and its device configuration are the first compatibility checks.

Choosing an STM32 UART DMA Example

The repository is most relevant when an STM32 application receives variable-length UART data and needs a documented approach to detecting an idle stream through IDLE or RTO events. It is also relevant when the sender can provide a known length and the receiver should transfer bytes without polling every UART register. The examples give developers a concrete C and CMake starting point rather than a hardware-independent abstraction.

Adopt one project only after checking the target's UART event support, DMA mappings, buffer placement and CMake preset. Do not adopt it as a complete protocol implementation, a portable STM32 library or a replacement for the MCU reference manual. If your product requires automatic protocol framing, retry handling, detailed error recovery or documented long-term release compatibility, those requirements must be evaluated outside this repository. For a matching MCU and protocol boundary, the IDLE or RTO examples provide a useful reference implementation to inspect and adapt.

Editorial conclusion

Adopt this repository when you need reference examples for STM32 UART DMA, especially unknown-length reception with IDLE or RTO events. Do not treat it as a complete protocol stack or a substitute for device-specific reference-manual work. Verify first that your MCU supports the required UART events, DMA routing and memory arrangement, then confirm the build preset and peripheral configuration for the selected project.

Frequently asked questions

What problem does the STM32 UART DMA RX and TX repository solve?

It provides STM32 examples for receiving UART data when the byte count is not known in advance and for transmitting data with DMA instead of CPU polling. Its receive examples use IDLE line or Receiver Timeout events to identify pauses in the stream.

Which STM32 devices support the IDLE line and RTO examples?

The README says that not every STM32 supports IDLE line or RTO features. Check the device reference manual and select a project that matches the target MCU and its available UART and DMA resources.

How are the STM32 UART DMA examples built?

The README documents CMake, Ninja and GCC with `arm-none-eabi-gcc`, and provides `python3 scripts/build.py [--clean] [--path projects/project-folder]` for a helper build. It also documents listing a project's presets with `cmake --list-presets`, then configuring and building the selected preset.

Official sources

  1. Issues
  2. License: MIT
  3. MaJerle/stm32-usart-uart-dma-rx-tx on GitHub
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/majerle-stm32-usart-uart-dma-rx-tx.svg)](https://hysenlabs.com/projects/majerle-stm32-usart-uart-dma-rx-tx)

Was this useful?