|
|
@@ -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 */
|