把COM0的通道,由1,2、换到3,4。
我按例程上,加入了下面两句。
syscfg_dma_remap_enable(SYSCFG_DMA_REMAP_USART0RX);
syscfg_dma_remap_enable(SYSCFG_DMA_REMAP_USART0TX);
结果程序上DMA发送不成功。一直停在while (RESET == dma_flag_get(DMA_CH3, DMA_FLAG_FTF));
请问下,这个要怎么修改才能行?谢谢!
int main(void)
{
dma_parameter_struct dma_init_struct;
/* enable DMA clock */
rcu_periph_clock_enable(RCU_DMA);
syscfg_dma_remap_enable(SYSCFG_DMA_REMAP_USART0RX);
syscfg_dma_remap_enable(SYSCFG_DMA_REMAP_USART0TX);
#ifdef GD32F130_150
gd_eval_com_init(EVAL_COM1);
#elif defined GD32F170_190
gd_eval_com_init(EVAL_COM2);
#endif /* GD32F130_150 */
printf("\n\ra usart dma function test example!\n\r");
#ifdef GD32F130_150
/* deinitialize DMA channel1 */
dma_deinit(DMA_CH3);
dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL;
dma_init_struct.memory_addr = (uint32_t)txbuffer;
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT;
dma_init_struct.number = ARRAYNUM(txbuffer);
dma_init_struct.periph_addr = USART0_TDATA_ADDRESS;
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;
dma_init(DMA_CH3, dma_init_struct);
/* configure DMA mode */
dma_circulation_disable(DMA_CH3);
dma_memory_to_memory_disable(DMA_CH3);
/* enable DMA channel1 */
dma_channel_enable(DMA_CH3);
/* USART DMA enable for transmission and reception */
usart_dma_transmit_config(USART0, USART_DENT_ENABLE);
/* wait DMA channel transfer complete */
while (RESET == dma_flag_get(DMA_CH3, DMA_FLAG_FTF));
while(1){
/* deinitialize DMA channel2 */
dma_deinit(DMA_CH4);
dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY;
dma_init_struct.memory_addr = (uint32_t)rxbuffer;
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT;
dma_init_struct.number = 10;
dma_init_struct.periph_addr = USART0_RDATA_ADDRESS;
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;
dma_init(DMA_CH4, dma_init_struct);
dma_circulation_disable(DMA_CH4);
dma_memory_to_memory_disable(DMA_CH4);
dma_channel_enable(DMA_CH4);
usart_dma_receive_config(USART0, USART_DENR_ENABLE);
/* wait DMA channel transfer complete */
while (RESET == dma_flag_get(DMA_CH4, DMA_FLAG_FTF));
printf("\n\r%s\n\r",rxbuffer);
}
} |