串口DMA 收发测试(部分代码)

本文介绍了如何使用STM32单片机进行串口DMA的收发测试,提供了严谨的1.5Mbps波特率串口通信机制,并引用了相关代码库作为参考。
摘要由CSDN通过智能技术生成

可参考例程:一个严谨的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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值