串口2使用DMA方式打印串口信息
DMA配置
????DMA_InitTypeDef DMA_InitStructure = {0};
? ? RCC_AHBPeriphClockCmd( RCC_AHBPeriph_DMA1, ENABLE );
? ? /* UART2 Tx DMA initialization */
? ? DMA_Cmd( DMA1_Channel7, DISABLE );
? ? DMA_DeInit( DMA1_Channel7 );
? ? DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&USART2->DATAR);
? ? DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Tx_Buffer;//Tx_Buffer;
? ? DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
? ? DMA_InitStructure.DMA_BufferSize = RX_BUFFER_LEN;//RX_BUFFER_LEN;
? ? DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
? ? DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
? ? DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
? ? DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
? ? DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
? ? DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
? ? DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
? ? DMA_Init( DMA1_Channel7, &DMA_InitStructure );
DMA发送函数
void UART2_DMA_SendBuf(uint8_t *buf, uint16_t len)
{
//if(UART2_Tx_Flag==0)
{
//UART2_Tx_Flag = 1;
memcpy(Tx_Buffer,buf,len);
? ? DMA_Cmd( DMA1_Channel7, DISABLE );
? ? DMA_ClearFlag(DMA1_FLAG_TC7);
DMA_SetCurrDataCounter(DMA1_Channel7,len);
? ? DMA_Cmd( DMA1_Channel7, ENABLE );?
? ? /* 等待发送完成,这里没有使用DMA发送完成中断 */
while(!DMA_GetFlagStatus(DMA1_FLAG_TC7));
}
}