可参考例程:一个严谨的STM32串口DMA发送&接收(1.5Mbps波特率)机制_1.5mbps串口_Acuity.的博客-CSDN博客
参考 代码库:mirrors / Prry / stm32f0-uart-dma · GitCode
/*
************************************* Copyright ******************************
*
* (C) Copyright 2023,Wenkic,China, GCU.
* All Rights Reserved
*
* By(Wenkic)
* https://blog.csdn.net/Wekic
*
* FileName : dri_UsartDMA.c
* Version : v1.0
* Author : Wenkic
* Date : 2023-03-27
* Description : 芯片型号:N32G55 (国民技术)
* Function List:
******************************************************************************
*/
/********************************End of Head************************************/
#include "dri_UsartDMA.h"
#include "lw_N32NVIC.h"
typedef struct _UsartBase
{
u8 ID; //编号
USART_Module* USARTx; //串口端口
GPIO_Module* GPIOxTxPort; //发送端口
uint16_t GPIOxTxPin ;
GPIO_Module* GPIOxRxPort; //接收端口
uint16_t GPIOxRxPin ;
IRQn_Type BSP_IRQn ; //中断枚举
uint32_t PERIPH_USARTx; //时钟
}UsartBaseType_t;
static const UsartBaseType_t UsartCom[7] = {
{0,USART1,GPIOA,GPIO_PIN_9 ,GPIOA,GPIO_PIN_10,USART1_IRQn,RCC_APB2_PERIPH_USART1},
{1,USART2,GPIOA,GPIO_PIN_2 ,GPIOA,GPIO_PIN_3 ,USART2_IRQn,RCC_APB1_PERIPH_USART2},
{2,USART3,GPIOB,GPIO_PIN_10,GPIOB,GPIO_PIN_11,USART3_IRQn,RCC_APB1_PERIPH_USART3},
{3,UART4 ,GPIOC,GPIO_PIN_10,GPIOC,GPIO_PIN_11,UART4_IRQn ,RCC_APB1_PERIPH_UART4 },
{4,UART5 ,GPIOC,GPIO_PIN_12,GPIOD,GPIO_PIN_2 ,UART5_IRQn ,RCC_APB1_PERIPH_UART5 },
{5,UART6 ,GPIOE,GPIO_PIN_2 ,GPIOE,GPIO_PIN_3 ,UART6_IRQn ,RCC_APB2_PERIPH_UART6 },
{6,UART7 ,GPIOC,GPIO_PIN_4 ,GPIOC,GPIO_PIN_5 ,UART7_IRQn ,RCC_APB2_PERIPH_UART7 },
};
static uint8_t UsartEnable[7] = { 0 };
//获取端口编号
static uint16_t TM_GPIO_GetPortSource(GPIO_Module* GPIOx) {
/* Offset from GPIOA Difference between 2 GPIO addresses */
return ((uint32_t)GPIOx - (GPIOA_BASE)) / ((GPIOB_BASE) - (GPIOA_BASE));
}
//使能GPIO端口时钟
static void TM_GPIO_INT_EnableClock(GPIO_Module* GPIOx) {
/* Set bit according to the 1 << portsourcenumber */
RCC->APB2PCLKEN |= (1 << (TM_GPIO_GetPortSource(GPIOx)+2));
}
/*串口1*/
void UsartInit(USART_Module* USARTx, uint32_t baud, uint8_t PreemptionPriority, uint8_t SubPriority)
{
u