int32_t uart_dma_init(void)
{
usart_deinit(USART0);
usart_disable(USART0);
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_USART1);
gpio_af_set(GPIOA,GPIO_AF_7,GPIO_PIN_9|GPIO_PIN_10);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART1_TX_PIN|USART1_RX_PIN);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART1_TX_PIN|USART1_RX_PIN);
nvic_irq_enable(USART1_IRQn,5,0);
usart_baudrate_set(USART0,2250000U);
usart_parity_config(USART0,USART_PM_NONE);
usart_word_length_set(USART0,USART_WL_8BIT);
usart_stop_bit_set(USART0,USART_STB_1BIT);
usart_hardware_flow_coherence_config(USART0,USART_HCM_NONE);
usart_data_first_config(USART0,USART_MSBF_LSB);
usart_enable(USART0);
usart_transmit_config(USART0,USART_TRANSMIT_ENABLE);
usart_receive_config(USART0,USART_RECEIVE_ENABLE);
usart_dma_transmit_config(USART0, USART_DENT_ENABLE);//打开串口DMA发送
usart_dma_receive_config(USART0, USART_DENR_ENABLE);//打开串口DMA接收
usart_flag_clear(USART0, USART_FLAG_TC);
usart_interrupt_enable(USART0,USART_INT_IDLE);//使用串口空闲中断
return 0;
} |