Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
68 changes: 63 additions & 5 deletions bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */

Expand Down Expand Up @@ -161,30 +192,55 @@ 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",
},
#endif

#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 "not support soc"
#endif
&serial1,
"uart1",
},
#endif

#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 "not support soc"
#endif
&serial2,
"uart2",
},
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 */
Expand Down
4 changes: 4 additions & 0 deletions bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down