GD32E230C USART0串口用PB6 PB7引脚 ,并使用DMA传输,用的DMA_CH3作为上发到上位机和DMA_CH4接收,能上发,但无法通过DMA_CH4接收
static int BSP_DmaConfig(dma_channel_enum dma_channelx,uint32_t peripheralAddr,uint32_t memoryAddr,uint32_t dir,uint32_t datasize)
{
dma_parameter_struct dma_init_struct;
rcu_periph_clock_enable(RCU_DMA);
dma_deinit(dma_channelx);
dma_init_struct.direction=dir;
dma_init_struct.memory_addr=memoryAddr;
dma_init_struct.memory_inc=DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.memory_width=DMA_MEMORY_WIDTH_8BIT;
dma_init_struct.number=datasize;
dma_init_struct.periph_addr=peripheralAddr;
dma_init_struct.periph_inc=DMA_PERIPH_INCREASE_DISABLE;
dma_init_struct.periph_width=DMA_PERIPHERAL_WIDTH_8BIT;
dma_init_struct.priority=DMA_PRIORITY_ULTRA_HIGH;
/* configure DMA mode */
dma_circulation_disable(dma_channelx); //禁止循环模式
dma_memory_to_memory_disable(dma_channelx); //禁止内存到内存
dma_init(dma_channelx,&dma_init_struct);
/* enable DMA channel */
dma_channel_enable(dma_channelx);
if(dma_channelx==DMA_CH3)
{
syscfg_dma_remap_enable(SYSCFG_DMA_REMAP_USART0TX);
}
else if(dma_channelx==DMA_CH4)
{
syscfg_dma_remap_enable(SYSCFG_DMA_REMAP_USART0RX);
}
return 0;
}
void USART0_IRQHandler(void)
{
volatile uint32_t clear;
volatile uint16_t msgLength = 0;
if(usart_interrupt_flag_get(USART0x, USART_INT_FLAG_IDLE) != RESET){
printf("recive\r\n");
usart_interrupt_flag_clear(USART0x,USART_INT_FLAG_IDLE);
//使用长度=总长度-剩余的长度
msgLength = (uint16_t)(DMA_UART0_DATASIZE-dma_transfer_number_get(DMA_CH2));
printf("channel%d %d %d\r\n",msgLength,sizeof(gUartData.USART0_RxData),dma_transfer_number_get(DMA_CH2));
//清除中断
clear=USART_STAT(USART0x);
clear=USART_RDATA(USART0x);
dma_channel_disable(DMA_CH2); //关闭DMA传输
Control_Upper_Computer((uint8_t*)gUartData.USART0_RxData, msgLength);
//由于是单次传输,需要再次初始化
dma_interrupt_flag_clear(DMA_CH2,DMA_INT_FLAG_FTF);
dma_interrupt_flag_clear(DMA_CH2,DMA_INT_FLAG_ERR);
dma_flag_clear(DMA_CH2,DMA_FLAG_FTF);
dma_flag_clear(DMA_CH2,DMA_FLAG_ERR);
// dma_memory_address_config(DMA_CH2,(uint32_t)gUartData.USART0_RxData[DMA_UART0_DATASIZE]);
// dma_transfer_number_config(DMA_CH2,DMA_UART0_DATASIZE); //数据传输量
// dma_channel_enable(DMA_CH2); //开启DMA传输
dma_memory_address_config(DMA_CH2,(uint32_t)gUartData.USART0_RxData);
dma_transfer_number_config(DMA_CH2,sizeof(gUartData.USART0_RxData)); //数据传输量
dma_channel_enable(DMA_CH2);
}
}