Welcome to STM32-BoardCar repository
15. DMA:USART
DMA:USART
DMA:USART1、software-hardware2、Brief principle2.1、Hardware schematic diagram2.2、Physical connection diagram3.3、Principle of control3、Engineering configuration3.1、Notes3.2、Pin configuration4、Main Function4.1、User function4.2、LL library function analysis5、Experimental phenomenon
This tutorial demonstrates Serial (USART1) communication via DMA
1、software-hardware
STM32F103CubeIDE
STM32 robot expansion board
USART1, DMA: chip internal peripheral
Type-C cable or ST-Link
Download or simulate the program of the development board
2、Brief principle
2.1、Hardware schematic diagram
The schematic only shows the serial interface used in the tutorial (USART1)

2.2、Physical connection diagram

3.3、Principle of control
- USART1
The knowledge related to serial port will not be introduced, you can see before [Chapter 3:3.4 Serial communication]
- DMA(Direct Memory Access)
STM32F103ZET6 has a total of two DMA controllers, DMA1 has 7 channels, DMA2 has 5 channels;
It is used for high-speed data transfer between peripheral equipment and memory and between memory and memory.
DMA features
The initialization and start of DMA are completed by the CPU, and the transfer process is executed by the DMA controller without the participation of the CPU, so that the CPU resources are saved to do other operations
DMA1 requests per channel

DMA2 requests per channel

DMA1 channels 4 and 5 are used in this tutorial
3、Engineering configuration
Project Configuration: Prompts for configuration options in the STM32CubeIDE project configuration process
3.1、Notes
Omitted project configuration: New project, chip selection, project configuration, SYS for pin configuration, RCC configuration, clock configuration, and project configuration content
The project configuration part, which is not omitted, is the key point to configure in this tutorial.
Please refer to [2. Development environment construction and use: STM32CubeIDE installation and use] to understand how to configure the omitted parts of the project.
3.2、Pin configuration
- Configure the specified pin function
You can directly select the corresponding pin number in the pin view, and the corresponding option will appear when the mouse is left clicked

- USART1



NVIC
NVIC can modify interrupt priority

- Advanced Settings

- Generating code

4、Main Function
This section mainly introduces the functional code written by users. Detailed code can be opened by yourself in the project file we provide, and enter the Bsp folder to view the source code. .
4.1、User function
function:USART1_DataByte
| Function prototypes | void USART1_DataByte(uint8_t data_byte) |
|---|---|
| Functional Description | Sending a single byte |
| Input parameters | data_byte:Data to be sent |
| Return value | None |
| Tips | Define the DMA_USART macro to switch between DMA transfer and USART directly |
function:USART1_DataString
| Function prototypes | void USART1_DataString(uint8_t *data_str, uint16_t datasize) |
|---|---|
| Functional Description | Sending strings |
| Input parameters1 | data_str:The first address to send data to |
| Input parameters2 | datasize:Data size |
| Return value | None |
| Tips | Define the DMA_USART macro to switch between DMA transfer and USART directly |
4.2、LL library function analysis
LL library functions that have been covered in the previous tutorial will not be covered in the tutorial
xxxxxxxxxxIf you want to find the HAL library and LL library function analysis involved in the entire tutorial, you can view the documents in the folder [8. STM32 Manual: STM32F1_HAL Library and LL Library_User Manual]
function:LL_DMA_SetDataTransferDirection
| Function prototypes | void LL_DMA_SetDataTransferDirection(DMA_TypeDef *DMAx, uint32_t Channel, uint32_t Direction) |
|---|---|
| Functional Description | Set the direction of data transmission |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | Direction:Direction of data transmission |
| Return value | None |
function:LL_DMA_SetChannelPriorityLevel
| Function prototypes | void LL_DMA_SetChannelPriorityLevel(DMA_TypeDef *DMAx, uint32_t Channel, uint32_t Priority) |
|---|---|
| Functional Description | Set the priority of the DMA channel |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | Priority:priority |
| Return value | None |
function:LL_DMA_SetMode
| Function prototypes | void LL_DMA_SetMode(DMA_TypeDef *DMAx, uint32_t Channel, uint32_t Mode) |
|---|---|
| Functional Description | Set DMA working mode |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | Mode:Mode of work |
| Return value | None |
function:LL_DMA_SetPeriphIncMode
| Function prototypes | void LL_DMA_SetPeriphIncMode (DMA_TypeDef *DMAx, uint32_t Channel, uint32_t PeriphOrM2MSrcIncMode) |
|---|---|
| Functional Description | Set DMA peripheral delta mode |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | PeriphOrM2MSrcIncMode:Incremental mode selection |
| Return value | None |
function:LL_DMA_SetMemoryIncMode
| Function prototypes | void LL_DMA_SetMemoryIncMode (DMA_TypeDef *DMAx, uint32_t Channel, uint32_t MemoryOrM2MDstIncMode) |
|---|---|
| Functional Description | Set DMA memory increment mode |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | MemoryOrM2MDstIncMode:Incremental mode selection |
| Return value | None |
function:LL_DMA_SetPeriphSize
| Function prototypes | void LL_DMA_SetPeriphSize(DMA_TypeDef *DMAx, uint32_t Channel, uint32_t PeriphOrM2MSrcDataSize) |
|---|---|
| Functional Description | Set the peripheral data size |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | PeriphOrM2MSrcDataSize:Data size |
| Return value | None |
function:LL_DMA_SetMemorySize
| Function prototypes | void LL_DMA_SetMemorySize (DMA_TypeDef *DMAx, uint32_t Channel, uint32_t MemoryOrM2MDstDataSize) |
|---|---|
| Functional Description | Set the memory data size |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | MemoryOrM2MDstDataSize:Data size |
| Return value | None |
function:LL_DMA_SetMemoryAddress
| Function prototypes | void LL_DMA_SetMemoryAddress(DMA_TypeDef *DMAx, uint32_t Channel, uint32_t MemoryAddress) |
|---|---|
| Functional Description | Set the DMA memory address |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | MemoryAddress:Memory address |
| Return value | None |
function:LL_DMA_SetPeriphAddress
| Function prototypes | void LL_DMA_SetPeriphAddress(DMA_TypeDef *DMAx, uint32_t Channel, uint32_t PeriphAddress) |
|---|---|
| Functional Description | Set the DMA peripheral address |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | PeriphAddress:Peripheral device address |
| Return value | None |
function:LL_DMA_SetDataLength
| Function prototypes | void LL_DMA_SetDataLength(DMA_TypeDef *DMAx, uint32_t Channel, uint32_t NbData) |
|---|---|
| Functional Description | Set the length of DMA transfer data |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Input parameters3 | NbData:Data length |
| Return value | None |
function:LL_DMA_EnableChannel
| Function prototypes | void LL_DMA_EnableChannel(DMA_TypeDef *DMAx, uint32_t Channel) |
|---|---|
| Functional Description | Enable DMA channels |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Return value | None |
function:LL_DMA_DisableChannel
| Function prototypes | void LL_DMA_DisableChannel(DMA_TypeDef *DMAx, uint32_t Channel) |
|---|---|
| Functional Description | Closing the DMA channel |
| Input parameters1 | DMAx:DMA handle address |
| Input parameters2 | Channel:DMA channel number in the range 0 to 7 |
| Return value | None |
function:LL_USART_EnableDMAReq_RX
| Function prototypes | void LL_USART_EnableDMAReq_RX(USART_TypeDef *USARTx) |
|---|---|
| Functional Description | Enable DMA serial port reception |
| Input parameters | USARTx:USART handle address |
| Return value | None |
function:LL_USART_EnableDMAReq_TX
| Function prototypes | void LL_USART_EnableDMAReq_TX(USART_TypeDef *USARTx) |
|---|---|
| Functional Description | Enable DMA serial port sending |
| Input parameters | USARTx:USART handle address |
| Return value | None |
5、Experimental phenomenon
After downloading the program successfully, press the RESET button of the development board to open the serial debugging assistant to observe the phenomenon
xxxxxxxxxxFor program download, please refer to [2. Development environment construction and use: program download and simulation]
phenomenon:
Press RESET button, serial debugging assistant will print USRT+DMA Class! Character;
Then through the serial port debug assistant to send what information will print the corresponding information
