DMA:USART

The tutorial demonstrates serial port (USART1) communication via DMA.

Hardware connection

image-20240825210510331

PeripheralsDevelopment boardDescription
USART1_TXPA9USART1 sends data
USART1_RXPA10USART1 receives data

Control principle

STM32F103RCT6 has two DMA controllers, DMA1 has 7 channels and DMA2 has 5 channels;

It is used for high-speed data transmission between peripherals and memory and between memory and memory.

DMA features

DMA initialization and startup are completed by the CPU, and the transfer process is performed by the DMA controller without CPU involvement, thus saving CPU resources for other operations.

DMA1 requests for each channel

image-20240903164920640

DMA2 requests for each channel

image-20240903164934222

This tutorial uses DMA1 channel 4.

Pin definition

Main control chipPinMain function (after reset)Default multiplexing functionRedefine function
STM32F103RCT6PA9PA9USART1_TX/TIM1_CH2 
STM32F103RCT6PA10PA10USART1_RX/TIM1_CH3 

Software code

Since the default function of the PA9/10 pin is a normal IO pin function, we need to use the multiplexing function.

Control function

The tutorial only briefly introduces the code, and you can open the project source code to read it in detail.

uart_init

USARTx_DMA_Config

Experimental phenomenon

The USART_DMA.hex file generated by the project compilation is located in the OBJ folder of the [USART+DMA] project. Find the USART_DMA.hex file corresponding to the project and use the FlyMcu software to download the program to the development board.

After the program is successfully downloaded: Use the serial port debugging assistant to view the information, and you can see that the serial port prints Usart1 DMA Class! and Hello (Hello prints for about 300ms).

image-20240802114954578