From 570e051d8353efd1c15bebfc64a8d3babcc5ba27 Mon Sep 17 00:00:00 2001 From: zhang-haitao-repo <2649825643@qq.com> Date: Thu, 22 Jan 2026 02:14:13 +0800 Subject: [PATCH 1/2] feat(gd32): add GD32VW55x series USART driver support - Add support for GD32VW55x series UART/USART peripherals - Implement proper GPIO alternate function configuration for GD32VW55x - Add conditional compilation for different GD32 series (GD32VF103V vs GD32VW55x) - Remove unused UART3/UART4 configurations from Kconfig --- bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig | 20 ----- .../risc-v/libraries/gd32_drivers/drv_usart.c | 80 ++++++++++++++++--- .../risc-v/libraries/gd32_drivers/drv_usart.h | 4 + 3 files changed, 73 insertions(+), 31 deletions(-) diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig b/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig index 6bb5df41373..1e902d4e3e1 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig @@ -56,26 +56,6 @@ menu "On-chip Peripheral Drivers" depends on BSP_USING_UART2 select RT_SERIAL_USING_DMA default n - - config BSP_USING_UART3 - bool "Enable UART3" - default n - - config BSP_UART3_RX_USING_DMA - bool "Enable UART3 RX DMA" - depends on BSP_USING_UART3 - select RT_SERIAL_USING_DMA - default n - - config BSP_USING_UART4 - bool "Enable UART4" - default n - - config BSP_UART4_RX_USING_DMA - bool "Enable UART4 RX DMA" - depends on BSP_USING_UART4 - select RT_SERIAL_USING_DMA - default n endif source "$(BSP_DIR)/../libraries/gd32_drivers/Kconfig" diff --git a/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c b/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c index 2b3f8881d15..1ee8244b3be 100644 --- a/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c +++ b/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c @@ -7,6 +7,7 @@ * Date Author Notes * 2021-08-20 BruceOu first implementation * 2025-07-11 Wangshun adapt to GD32VV553H + * 2026-01-22 HaitaoZhang adapt to GD32VW553H UART1/2 */ #include "drv_usart.h" @@ -45,6 +46,7 @@ void USART0_IRQHandler(void) #if defined(BSP_USING_UART1) struct rt_serial_device serial1; +#if defined (SOC_SERIES_GD32VF103V) void USART1_IRQHandler(void) { /* enter interrupt */ @@ -55,12 +57,27 @@ void USART1_IRQHandler(void) /* leave interrupt */ rt_interrupt_leave(); } +#elif defined (SOC_SERIES_GD32VW55x) +void UART1_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + GD32_UART_IRQHandler(&serial1); + + /* leave interrupt */ + rt_interrupt_leave(); +} +#else +#error "not support soc" +#endif #endif /* BSP_USING_UART1 */ #if defined(BSP_USING_UART2) struct rt_serial_device serial2; +#if defined (SOC_SERIES_GD32VF103V) void USART2_IRQHandler(void) { /* enter interrupt */ @@ -71,6 +88,20 @@ void USART2_IRQHandler(void) /* leave interrupt */ rt_interrupt_leave(); } +#elif defined (SOC_SERIES_GD32VW55x) +void UART2_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + GD32_UART_IRQHandler(&serial2); + + /* leave interrupt */ + rt_interrupt_leave(); +} +#else +#error "not support soc" +#endif #endif /* BSP_USING_UART2 */ @@ -161,6 +192,9 @@ static const struct gd32_uart uart_obj[] = { RCU_USART0, RCU_GPIOB, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */ GPIOB, GPIO_PIN_15, /* tx port, tx pin */ GPIOA, GPIO_PIN_8, /* rx port, rx pin */ +#if defined (SOC_SERIES_GD32VW55x) + GPIO_AF_8, GPIO_AF_2, +#endif &serial0, "uart0", }, @@ -168,11 +202,22 @@ static const struct gd32_uart uart_obj[] = { #ifdef BSP_USING_UART1 { +#if defined (SOC_SERIES_GD32VF103V) USART1, /* uart peripheral index */ USART1_IRQn, /* uart iqrn */ - RCU_USART1, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */ + RCU_UART1, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */ GPIOA, GPIO_PIN_2, /* tx port, tx pin */ GPIOA, GPIO_PIN_3, /* rx port, rx pin */ +#elif defined (SOC_SERIES_GD32VW55x) + UART1, /* uart peripheral index */ + UART1_IRQn, /* uart iqrn */ + RCU_UART1, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */ + GPIOA, GPIO_PIN_2, /* tx port, tx pin */ + GPIOA, GPIO_PIN_3, /* rx port, rx pin */ + GPIO_AF_7, GPIO_AF_7, +#else +#error "not support soc" +#endif &serial1, "uart1", }, @@ -180,11 +225,22 @@ static const struct gd32_uart uart_obj[] = { #ifdef BSP_USING_UART2 { - USART2, /* uart peripheral index */ - USART2_IRQn, /* uart iqrn */ - RCU_USART2, RCU_GPIOB, RCU_GPIOB, /* periph clock, tx gpio clock, rt gpio clock */ - GPIOB, GPIO_PIN_10, /* tx port, tx pin */ - GPIOB, GPIO_PIN_11, /* rx port, rx pin */ +#if defined (SOC_SERIES_GD32VF103V) + UART2, /* uart peripheral index */ + UART2_IRQn, /* uart iqrn */ + RCU_UART2, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */ + GPIOA, GPIO_PIN_6, /* tx port, tx pin */ + GPIOA, GPIO_PIN_7, /* rx port, rx pin */ +#elif defined (SOC_SERIES_GD32VW55x) + UART2, /* uart peripheral index */ + UART2_IRQn, /* uart iqrn */ + RCU_UART2, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */ + GPIOA, GPIO_PIN_6, /* tx port, tx pin */ + GPIOA, GPIO_PIN_7, /* rx port, rx pin */ + GPIO_AF_10, GPIO_AF_8, +#else +#error "not support soc" +#endif &serial2, "uart2", }, @@ -233,17 +289,19 @@ void gd32_uart_gpio_init(struct gd32_uart *uart) rcu_periph_clock_enable(uart->per_clk); /* connect port */ -#if defined SOC_SERIES_GD32VF103V +#if defined (SOC_SERIES_GD32VF103V) gpio_init(uart->tx_port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, uart->tx_pin); gpio_init(uart->rx_port, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, uart->rx_pin); -#else - gpio_af_set(uart->tx_port, GPIO_AF_8, uart->tx_pin); +#elif defined (SOC_SERIES_GD32VW55x) + gpio_af_set(uart->tx_port, uart->tx_alt, uart->tx_pin); gpio_mode_set(uart->tx_port, GPIO_MODE_AF, GPIO_PUPD_PULLUP, uart->tx_pin); gpio_output_options_set(uart->tx_port, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, uart->tx_pin); - gpio_af_set(uart->rx_port, GPIO_AF_2, uart->rx_pin); + gpio_af_set(uart->rx_port, uart->rx_alt, uart->rx_pin); gpio_mode_set(uart->rx_port, GPIO_MODE_AF, GPIO_PUPD_PULLUP, uart->rx_pin); gpio_output_options_set(uart->rx_port, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, uart->rx_pin); +#else +#error "not support soc" #endif } @@ -328,7 +386,7 @@ static rt_err_t gd32_uart_control(struct rt_serial_device *serial, int cmd, void break; case RT_DEVICE_CTRL_SET_INT: -#ifdef SOC_SERIES_GD32VF103V +#if defined (SOC_SERIES_GD32VF103V) eclic_set_nlbits(ECLIC_GROUP_LEVEL3_PRIO1); #endif /* SOC_SERIES_GD32VF103V */ /* enable rx irq */ diff --git a/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.h b/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.h index 6a6f75697e6..14ec8786efe 100644 --- a/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.h +++ b/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.h @@ -32,6 +32,10 @@ struct gd32_uart uint16_t tx_pin; /* Todo: 4bits */ uint32_t rx_port; /* Todo: 4bits */ uint16_t rx_pin; /* Todo: 4bits */ +#if defined (SOC_SERIES_GD32VW55x) + uint32_t tx_alt; + uint32_t rx_alt; +#endif struct rt_serial_device * serial; char *device_name; }; From 25d730a9757e5e82b765fadc1d948f0aa6f80561 Mon Sep 17 00:00:00 2001 From: haitaoZhang <49626779+zhang-haitao-repo@users.noreply.github.com> Date: Thu, 22 Jan 2026 14:11:17 +0800 Subject: [PATCH 2/2] Update drv_usart.c --- bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c b/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c index 1ee8244b3be..f9e8105a264 100644 --- a/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c +++ b/bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c @@ -205,7 +205,7 @@ static const struct gd32_uart uart_obj[] = { #if defined (SOC_SERIES_GD32VF103V) USART1, /* uart peripheral index */ USART1_IRQn, /* uart iqrn */ - RCU_UART1, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */ + RCU_USART1, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */ GPIOA, GPIO_PIN_2, /* tx port, tx pin */ GPIOA, GPIO_PIN_3, /* rx port, rx pin */ #elif defined (SOC_SERIES_GD32VW55x) @@ -226,11 +226,11 @@ static const struct gd32_uart uart_obj[] = { #ifdef BSP_USING_UART2 { #if defined (SOC_SERIES_GD32VF103V) - UART2, /* uart peripheral index */ - UART2_IRQn, /* uart iqrn */ - RCU_UART2, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */ - GPIOA, GPIO_PIN_6, /* tx port, tx pin */ - GPIOA, GPIO_PIN_7, /* rx port, rx pin */ + USART2, /* uart peripheral index */ + USART2_IRQn, /* uart iqrn */ + RCU_USART2, RCU_GPIOB, RCU_GPIOB, /* periph clock, tx gpio clock, rt gpio clock */ + GPIOB, GPIO_PIN_10, /* tx port, tx pin */ + GPIOB, GPIO_PIN_11, /* rx port, rx pin */ #elif defined (SOC_SERIES_GD32VW55x) UART2, /* uart peripheral index */ UART2_IRQn, /* uart iqrn */