Phipps Electronics

Order within the next 

FREE SHIPPING OVER $199

50,000+ ORDERS

WORLDWIDE SHIPPING

SSL SECURED

STM32 UART Interrupt & DMA on STM32Cube IDE (Part 1)

Contents

Start running UART transmit and receive functions using interrupt or DMA on your favorite STM32 Blue Pill or Black Pill devices using STM32Cube IDE

Introduction

The STM32F1XX/STM32F4XX series of microcontrollers are powerful devices that employ different kinds of peripherals inside them. One of these indispensable peripherals is the UART. UART stands for Universal Asynchronous Receiver-Transmitter. It’s a classic and time-tested serial protocol used by electronic enthusiasts for their electronic projects.

The BluePill and Black Pill's UART Peripheral

The Blue Pill has an STM32F103C8T6 while the Black Pill has an STM32F411CEU/STM32F406CEU microcontroller. Both of these MCUs have several UART peripherals. Below you can see the UART block diagram for the STM32F411CEU6 (Black Pill)

STM32Cube IDE Black Pill UART Block Diagram

Setup STM32Cube IDE

Please refer to the Basic setup of STM32Cube IDE that was discussed previously as a reference for setting up your Blue Pill or Black Pill in STM32Cube IDE.

Open STM32CubeIDE and Choose your STM32 Microcontroller

STM32Cube IDE choose device

Setup your Clock Configuration

The maximum clock rate for an STM32F411CEU6 Black Pill is 100MHz while for the STM32F103C8T6 it’s 72MHz.

Setup your UART Port

On Connectivity, choose USART1. Setup Mode to Asynchronous, then go to Parameter Settings and check that the Basic and Advanced Parameters are set up like below.

  • Baud Rate: 115200
  • Word Length: 8bits
  • Parity: 1
  • Data Direction: Transmit & Receive
  • Data Sampling: 16 Samples

Once you’ve setup USART1 you should see pins A9 & A10 of your STM32 MCU being populated with the UART TX and RX functions in the Pinout window.

STM32F411 pinout UART pins

Choose Your UART Implementation

The STM32 UART port can be used in various ways (such as polling, interrupt, and DMA) in STM32Cube IDE, each with distinct advantages. These ways affect program execution, data gathering, and effective use of your chip’s resources.

Blocking Mode (No Interrupt)

This is the simplest mode of UART. Here, no interrupts are used. The user waits for the UART read or write operation to finish. After that, he or she can proceed with other operations in code. Nothing needs to be added to the basic UART configuration.

Interrupt Mode

In UART interrupt mode, you don’t have to wait for the entire UART string to finish before doing other operations. Enable this option on NVIC Settings. With this, you’ll need to wait for the interrupt, which signifies the UART operation has completed.

STM32 Black Pill UART Interrupt setting no DMA in STM32Cube IDE

DMA Mode

DMA mode uses another chip resource (the DMA) to store longer UART string data in static memory without any actual CPU intervention. This is the most efficient way to use UART to acquire large data. Wait for the DMA interrupt to happen to fetch the UART values.

Each UART Receive and Transmit port can have a DMA request. Enable each by clicking Add on the DMA Settings tab. Here, a Circular mode buffer is used so that the receive and transmit operations remain continuos.

STM32Cube IDE UART Interrupt DMA

You’ll also have to enable the USART and DMA interrupts for the HAL functions of the STM32 Cube framework to work correctly.

After choosing your desired UART operation proceed to generate code by pressing the save button above.

The next part will dissect the code for each UART implementation.

SUBSCRIBE FOR NEW POST ALERTS

Subscribe to be the first to know when we publish a new article!
List Subscriptions(Required)

POPULAR POSTS

Scroll to Top