本帖最后由 ya1234 于 2022-9-29 14:18 编辑
GD32E230的datasheet中可以看到PB和PB7是可以复用到USART0的,然后使用官方的例程,将官方例程默认引进从PA9、PA10改成PB6、PB7,结果串口就不打印了。用PA9、PA10却可以。 请教一下有没有人知道PB6、PB7怎么当串口0使用? 以下是官方例程,我将引脚宏定义改成PB6和PB7: /* definition for COM, connected to USART0 */ #define EVAL_COM USART0 #define EVAL_COM_CLK RCU_USART0 #define EVAL_COM_TX_PIN GPIO_PIN_6 #define EVAL_COM_RX_PIN GPIO_PIN_7 #define EVAL_COM_GPIO_PORT GPIOB #define EVAL_COM_GPIO_CLK RCU_GPIOB #define EVAL_COM_AF GPIO_AF_1 /*! \brief configure COM port \param[in] com: COM on the board \arg EVAL_COM: COM on the board \param[out] none \retval none */ void gd_eval_com_init(uint32_t com) { uint32_t COM_ID; COM_ID = 0U; /* enable COM GPIO clock */ rcu_periph_clock_enable(EVAL_COM_GPIO_CLK); /* enable USART clock */ rcu_periph_clock_enable(COM_CLK[COM_ID]); /* connect port to USARTx_Tx */ gpio_af_set(EVAL_COM_GPIO_PORT, EVAL_COM_AF, COM_TX_PIN[COM_ID]); /* connect port to USARTx_Rx */ gpio_af_set(EVAL_COM_GPIO_PORT, EVAL_COM_AF, COM_RX_PIN[COM_ID]); /* configure USART Tx as alternate function push-pull */ gpio_mode_set(EVAL_COM_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, COM_TX_PIN[COM_ID]); gpio_output_options_set(EVAL_COM_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, COM_TX_PIN[COM_ID]); /* configure USART Rx as alternate function push-pull */ gpio_mode_set(EVAL_COM_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, COM_RX_PIN[COM_ID]); gpio_output_options_set(EVAL_COM_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, COM_RX_PIN[COM_ID]); /* USART configure */ usart_deinit(com); usart_baudrate_set(com, 115200U); usart_receive_config(com, USART_RECEIVE_ENABLE); usart_transmit_config(com, USART_TRANSMIT_ENABLE); usart_enable(com); } |