Skip to content

Commit 1254af4

Browse files
[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 <175728472+Copilot@users.noreply.github.com> * feat: optimize gd32 uart driver error messages --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 25b6953 commit 1254af4

File tree

3 files changed

+67
-25
lines changed

3 files changed

+67
-25
lines changed

bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,6 @@ menu "On-chip Peripheral Drivers"
5656
depends on BSP_USING_UART2
5757
select RT_SERIAL_USING_DMA
5858
default n
59-
60-
config BSP_USING_UART3
61-
bool "Enable UART3"
62-
default n
63-
64-
config BSP_UART3_RX_USING_DMA
65-
bool "Enable UART3 RX DMA"
66-
depends on BSP_USING_UART3
67-
select RT_SERIAL_USING_DMA
68-
default n
69-
70-
config BSP_USING_UART4
71-
bool "Enable UART4"
72-
default n
73-
74-
config BSP_UART4_RX_USING_DMA
75-
bool "Enable UART4 RX DMA"
76-
depends on BSP_USING_UART4
77-
select RT_SERIAL_USING_DMA
78-
default n
7959
endif
8060

8161
menuconfig BSP_USING_PWM

bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Date Author Notes
88
* 2021-08-20 BruceOu first implementation
99
* 2025-07-11 Wangshun adapt to GD32VV553H
10+
* 2026-01-22 HaitaoZhang adapt to GD32VW553H UART1/2
1011
*/
1112

1213
#include "drv_usart.h"
@@ -45,6 +46,7 @@ void USART0_IRQHandler(void)
4546
#if defined(BSP_USING_UART1)
4647
struct rt_serial_device serial1;
4748

49+
#if defined (SOC_SERIES_GD32VF103V)
4850
void USART1_IRQHandler(void)
4951
{
5052
/* enter interrupt */
@@ -55,12 +57,27 @@ void USART1_IRQHandler(void)
5557
/* leave interrupt */
5658
rt_interrupt_leave();
5759
}
60+
#elif defined (SOC_SERIES_GD32VW55x)
61+
void UART1_IRQHandler(void)
62+
{
63+
/* enter interrupt */
64+
rt_interrupt_enter();
65+
66+
GD32_UART_IRQHandler(&serial1);
67+
68+
/* leave interrupt */
69+
rt_interrupt_leave();
70+
}
71+
#else
72+
#error "Uart1 ISR name not compatible with current MCU series"
73+
#endif
5874

5975
#endif /* BSP_USING_UART1 */
6076

6177
#if defined(BSP_USING_UART2)
6278
struct rt_serial_device serial2;
6379

80+
#if defined (SOC_SERIES_GD32VF103V)
6481
void USART2_IRQHandler(void)
6582
{
6683
/* enter interrupt */
@@ -71,6 +88,20 @@ void USART2_IRQHandler(void)
7188
/* leave interrupt */
7289
rt_interrupt_leave();
7390
}
91+
#elif defined (SOC_SERIES_GD32VW55x)
92+
void UART2_IRQHandler(void)
93+
{
94+
/* enter interrupt */
95+
rt_interrupt_enter();
96+
97+
GD32_UART_IRQHandler(&serial2);
98+
99+
/* leave interrupt */
100+
rt_interrupt_leave();
101+
}
102+
#else
103+
#error "Uart2 ISR name not compatible with current MCU series"
104+
#endif
74105

75106
#endif /* BSP_USING_UART2 */
76107

@@ -161,30 +192,55 @@ static const struct gd32_uart uart_obj[] = {
161192
RCU_USART0, RCU_GPIOB, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */
162193
GPIOB, GPIO_PIN_15, /* tx port, tx pin */
163194
GPIOA, GPIO_PIN_8, /* rx port, rx pin */
195+
#if defined (SOC_SERIES_GD32VW55x)
196+
GPIO_AF_8, GPIO_AF_2,
197+
#endif
164198
&serial0,
165199
"uart0",
166200
},
167201
#endif
168202

169203
#ifdef BSP_USING_UART1
170204
{
205+
#if defined (SOC_SERIES_GD32VF103V)
171206
USART1, /* uart peripheral index */
172207
USART1_IRQn, /* uart iqrn */
173208
RCU_USART1, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */
174209
GPIOA, GPIO_PIN_2, /* tx port, tx pin */
175210
GPIOA, GPIO_PIN_3, /* rx port, rx pin */
211+
#elif defined (SOC_SERIES_GD32VW55x)
212+
UART1, /* uart peripheral index */
213+
UART1_IRQn, /* uart iqrn */
214+
RCU_UART1, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */
215+
GPIOA, GPIO_PIN_2, /* tx port, tx pin */
216+
GPIOA, GPIO_PIN_3, /* rx port, rx pin */
217+
GPIO_AF_7, GPIO_AF_7,
218+
#else
219+
#error "UART1 peripheral config incompatible with current MCU series"
220+
#endif
176221
&serial1,
177222
"uart1",
178223
},
179224
#endif
180225

181226
#ifdef BSP_USING_UART2
182227
{
228+
#if defined (SOC_SERIES_GD32VF103V)
183229
USART2, /* uart peripheral index */
184230
USART2_IRQn, /* uart iqrn */
185231
RCU_USART2, RCU_GPIOB, RCU_GPIOB, /* periph clock, tx gpio clock, rt gpio clock */
186232
GPIOB, GPIO_PIN_10, /* tx port, tx pin */
187233
GPIOB, GPIO_PIN_11, /* rx port, rx pin */
234+
#elif defined (SOC_SERIES_GD32VW55x)
235+
UART2, /* uart peripheral index */
236+
UART2_IRQn, /* uart iqrn */
237+
RCU_UART2, RCU_GPIOA, RCU_GPIOA, /* periph clock, tx gpio clock, rt gpio clock */
238+
GPIOA, GPIO_PIN_6, /* tx port, tx pin */
239+
GPIOA, GPIO_PIN_7, /* rx port, rx pin */
240+
GPIO_AF_10, GPIO_AF_8,
241+
#else
242+
#error "UART2 peripheral config incompatible with current MCU series"
243+
#endif
188244
&serial2,
189245
"uart2",
190246
},
@@ -233,17 +289,19 @@ void gd32_uart_gpio_init(struct gd32_uart *uart)
233289
rcu_periph_clock_enable(uart->per_clk);
234290

235291
/* connect port */
236-
#if defined SOC_SERIES_GD32VF103V
292+
#if defined (SOC_SERIES_GD32VF103V)
237293
gpio_init(uart->tx_port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, uart->tx_pin);
238294
gpio_init(uart->rx_port, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, uart->rx_pin);
239-
#else
240-
gpio_af_set(uart->tx_port, GPIO_AF_8, uart->tx_pin);
295+
#elif defined (SOC_SERIES_GD32VW55x)
296+
gpio_af_set(uart->tx_port, uart->tx_alt, uart->tx_pin);
241297
gpio_mode_set(uart->tx_port, GPIO_MODE_AF, GPIO_PUPD_PULLUP, uart->tx_pin);
242298
gpio_output_options_set(uart->tx_port, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, uart->tx_pin);
243299

244-
gpio_af_set(uart->rx_port, GPIO_AF_2, uart->rx_pin);
300+
gpio_af_set(uart->rx_port, uart->rx_alt, uart->rx_pin);
245301
gpio_mode_set(uart->rx_port, GPIO_MODE_AF, GPIO_PUPD_PULLUP, uart->rx_pin);
246302
gpio_output_options_set(uart->rx_port, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, uart->rx_pin);
303+
#else
304+
#error "Uart GPIO config incompatible with current MCU series"
247305
#endif
248306
}
249307

@@ -328,7 +386,7 @@ static rt_err_t gd32_uart_control(struct rt_serial_device *serial, int cmd, void
328386

329387
break;
330388
case RT_DEVICE_CTRL_SET_INT:
331-
#ifdef SOC_SERIES_GD32VF103V
389+
#if defined (SOC_SERIES_GD32VF103V)
332390
eclic_set_nlbits(ECLIC_GROUP_LEVEL3_PRIO1);
333391
#endif /* SOC_SERIES_GD32VF103V */
334392
/* enable rx irq */

bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ struct gd32_uart
3232
uint16_t tx_pin; /* Todo: 4bits */
3333
uint32_t rx_port; /* Todo: 4bits */
3434
uint16_t rx_pin; /* Todo: 4bits */
35+
#if defined (SOC_SERIES_GD32VW55x)
36+
uint32_t tx_alt; /* GPIO alternate function for TX */
37+
uint32_t rx_alt; /* GPIO alternate function for RX */
38+
#endif
3539
struct rt_serial_device * serial;
3640
char *device_name;
3741
};

0 commit comments

Comments
 (0)