/* enable COM GPIO clock */
rcu_periph_clock_enable(RCU_GPIOB);/**/
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART0);
/* connect port to USARTx_Tx */
gpio_af_set(GPIOB, GPIO_AF_0, GPIO_PIN_6);
/* connect port to USARTx_Rx */
gpio_af_set(GPIOB, GPIO_AF_0, GPIO_PIN_7);
/* configure USART Tx as alternate function push-pull */
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_PULLUP,GPIO_PIN_6);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
/* configure USART Rx as alternate function push-pull */
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_7);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_7);
/* USART configure */
usart_deinit(com);
usart_baudrate_set(com, baudrate);
usart_parity_config(com,USART_PM_NONE);//校验
usart_word_length_set(com,USART_WL_8BIT);//数据位
usart_stop_bit_set(com,USART_STB_1BIT);//停止位
usart_transmit_config(com,USART_TRANSMIT_ENABLE);//使能发送
usart_receive_config(com,USART_RECEIVE_ENABLE);//接收使能
usart_interrupt_enable(com, USART_INT_RBNE);
usart_interrupt_enable(com, USART_INT_IDLE);
usart_hardware_flow_rts_config(com, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(com, USART_CTS_DISABLE);
usart_enable(com); |