From e5f3bf900ae41dcc9b4d72bcafd0e168b0e56161 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Mon, 20 Jan 2025 16:32:12 +0800 Subject: [PATCH] for debug --- inc/board_config.h | 21 ++++++++++++++++++--- src/usart.c | 6 ++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/inc/board_config.h b/inc/board_config.h index d6af13d..f37cde6 100644 --- a/inc/board_config.h +++ b/inc/board_config.h @@ -12,6 +12,21 @@ // #define POWER_SUPPLY_12V #define POWER_SUPPLY_24V +// #define GD32E230F4 +// #define GD32E230F8 + +/******************************************************************************/ + +#ifdef GD32E230F8 +#define USART_RCU RCU_USART1 +#define USART_PHY USART1 +#define USART_PHY_IRQ USART1_IRQn +#else +#define USART_RCU RCU_USART0 +#define USART_PHY USART0 +#define USART_PHY_IRQ USART0_IRQn +#endif + /******************************************************************************/ #ifdef POWER_SUPPLY_12V @@ -26,7 +41,6 @@ #error "Please define either POWER_SUPPLY_12V or POWER_SUPPLY_24V" #endif - /******************************************************************************/ #define I2C_GPIO_RCU RCU_GPIOF @@ -41,13 +55,14 @@ /******************************************************************************/ #define USART_GPIO_RCU RCU_GPIOA -#define USART_RCU RCU_USART0 +// #define USART_RCU RCU_USART0 #define USART_GPIO_PORT GPIOA #define USART_GPIO_AF GPIO_AF_1 #define USART_TX_PIN GPIO_PIN_2 #define USART_RX_PIN GPIO_PIN_3 -#define USART_PHY USART0 +// #define USART_PHY USART0 #define USART_PHY_BAUDRATE 115200U +// #define USART_PHY_IRQ USART0_IRQn #define RS485_EN_PORT GPIOA #define RS485_EN_PIN GPIO_PIN_4 diff --git a/src/usart.c b/src/usart.c index 4416f9e..433ad14 100644 --- a/src/usart.c +++ b/src/usart.c @@ -26,12 +26,10 @@ void usart_config(void) usart_baudrate_set(USART_PHY, USART_PHY_BAUDRATE); usart_receive_config(USART_PHY, USART_RECEIVE_ENABLE); usart_transmit_config(USART_PHY, USART_TRANSMIT_ENABLE); - - usart_enable(USART_PHY); - - nvic_irq_enable(USART0_IRQn, 0); + nvic_irq_enable(USART_PHY_IRQ, 0); usart_interrupt_enable(USART_PHY, USART_INT_RBNE); usart_interrupt_enable(USART_PHY, USART_INT_IDLE); + usart_enable(USART_PHY); } /**