在使用STM32的UART的DMA功能总结如下:
首先上代码,这里采用STM32 的USART1作为Demo,RX的DMA为DMA1_Channel5,TX的DMA为DMA1_Channel4.初始化如下,红色的标记需要注意:
RX-DMA初始化
1 //DMA Rx
2 USART_DMACmd(USART1,USART_DMAReq_Rx,ENABLE);3 DMA_Cmd(DMA1_Channel5,DISABLE);4 DMA_InitStruct.DMA_PeripheralBaseAddr = (u32)(&USART1->DR);5 DMA_InitStruct.DMA_MemoryBaseAddr =(u32)RxBuf0;6 DMA_InitStruct.DMA_DIR =DMA_DIR_PeripheralSRC;7 DMA_InitStruct.DMA_BufferSize = 10;8 DMA_InitStruct.DMA_PeripheralInc =DMA_PeripheralInc_Disable;9 DMA_InitStruct.DMA_MemoryInc =DMA_MemoryInc_Enable;10 DMA_InitStruct.DMA_PeripheralDataSize =DMA_PeripheralDataSize_HalfWord;11 DMA_InitStruct.DMA_MemoryDataSize =DMA_PeripheralDataSize_Byte;12 DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;13 DMA_InitStruct.DMA_Priority =DMA_Priority_High;14 DMA_InitStruct.DMA_M2M =DMA_M2M_Disable;15 DMA_Init(DMA1_Channel5,&D