diff options
| author | haitaoZhang <[email protected]> | 2026-02-05 22:14:48 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-05 22:14:48 +0800 |
| commit | 1254af44f253a11e2fe7351bb0242a6dbd219544 (patch) | |
| tree | 1a5409a20d854db265d2fcc3b63a265d80c38adf | |
| parent | 25b6953501e7ec8eeb7e8c72d2b11e8e49dbecf7 (diff) | |
[gd32][uart] Add GD32VW553 series UART driver support (#11147)
* 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
* Update drv_usart.c
* Update drv_usart.h follow AI Review.
* Update bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c
Co-authored-by: Copilot <[email protected]>
* feat: optimize gd32 uart driver error messages
---------
Co-authored-by: Copilot <[email protected]>
| -rw-r--r-- | bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig | 20 | ||||
| -rw-r--r-- | bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c | 68 | ||||
| -rw-r--r-- | bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.h | 4 |
3 files changed, 67 insertions, 25 deletions
diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig b/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig index 8d0f34949a..433c305712 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 menuconfig BSP_USING_PWM 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 2b3f8881d1..feba6f0004 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 "Uart1 ISR name not compatible with current MCU series" +#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 "Uart2 ISR name not compatible with current MCU series" +#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 */ 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 "UART1 peripheral config incompatible with current MCU series" +#endif &serial1, "uart1", }, @@ -180,11 +225,22 @@ static const struct gd32_uart uart_obj[] = { #ifdef BSP_USING_UART2 { +#if defined (SOC_SERIES_GD32VF103V) 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 */ + 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 "UART2 peripheral config incompatible with current MCU series" +#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 "Uart GPIO config incompatible with current MCU series" #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 6a6f75697e..bff4604876 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; /* GPIO alternate function for TX */ + uint32_t rx_alt; /* GPIO alternate function for RX */ +#endif struct rt_serial_device * serial; char *device_name; }; |
