mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-03-26 17:00:00 +08:00
[gd32][uart] Add GD32VW553 series UART driver support (#11147)
Some checks failed
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
Weekly CI Scheduler / Trigger and Monitor CIs (push) Has been cancelled
Weekly CI Scheduler / Create Discussion Report (push) Has been cancelled
Some checks failed
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
Weekly CI Scheduler / Trigger and Monitor CIs (push) Has been cancelled
Weekly CI Scheduler / Create Discussion Report (push) Has been cancelled
* 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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user