重点在串口 DMA 的配置,代码如下/**
* @brief GPS_Interrupt_Config 配置GPS使用的DMA中断
* @param None.
* @retval None.
*/
static void GPS_Interrupt_Config(void)
{
exNVIC_Init_TypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStruct.NVIC_IRQChannel = GPS_DMA_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
exNVIC_Init(&NVIC_InitStruct);
}
/**
* @brief GPS_DMA_Config gps dma接收配置
* @param 无
* @retval 无
*/
static void GPS_DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
/*开启DMA时钟*/
RCC_AHBPeriphClockCmd(GPS_USART_DMA_CLK, ENABLE);
/* 复位初始化DMA数据流 */
DMA_DeInit(GPS_USART_DMA_STREAM);
DMA_StructInit(&DMA_InitStructure);
/*设置DMA源:串口数据寄存器地址*/
DMA_InitStructure.DMA_PeripheralBaseAddr = GPS_DATA_ADDR;
/*内存地址(要传输的变量的指针)*/
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)gps_rbuff;
/*方向:从外设到内存*/
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
/*传输大小DMA_BufferSize=SENDBUFF_SIZE*/
DMA_InitStructure.DMA_BufferSize = GPS_RBUFF_SIZE;
/*外设地址不增*/
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
/*内存地址自增*/
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
/*外设数据单位*/
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
/*内存数据单位 8bit*/
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
/*DMA模式:不断循环*/
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
/*优先级:中*/
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
//M2M mode is disabled
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // 非内存到内存模式
DMA_InitStructure.DMA_Auto_reload = DMA_Auto_Reload_Enable;
/*配置DMA2的数据流3*/
DMA_Init(GPS_USART_DMA_STREAM, &DMA_InitStructure);
// Enable UARTy_DMA1_Channel Transfer complete interrupt
DMA_ITConfig(GPS_USART_DMA_STREAM, DMA_IT_HT|DMA_IT_TC, ENABLE);
/* 配置串口 向 DMA发出请求 */
UART_DMACmd(UART4, UART_DMAReq_EN, ENABLE);
/*使能DMA*/
DMA_Cmd(GPS_USART_DMA_STREAM, ENABLE);
/*配置中断优先级*/
GPS_Interrupt_Config();
}
|