[gd32/arm][drivers]: general GD serial driver adapter

This commit is contained in:
kurisaw
2025-11-14 10:44:21 +08:00
committed by R b b666
parent d32ed6a4af
commit 98b9ecdba6
4 changed files with 273 additions and 316 deletions

View File

@@ -65,6 +65,7 @@ if GetDepend('BSP_USING_SDRAM'):
src += ['drv_sdram.c']
path = [cwd]
path += [cwd + "/config"]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path)

View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2025-10-09 WangShun optimize the serial driver
* 2025-11-13 kurisaw general GD driver adaptation
*/
#ifndef __UART_CONFIG_H__
#define __UART_CONFIG_H__
#include <rtthread.h>
#include <board.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(BSP_USING_UART0)
#ifndef UART0_CONFIG
#define UART0_CONFIG \
{ \
.uart_periph = USART0, \
.irqn = USART0_IRQn, \
.per_clk = RCU_USART0, \
.tx_pin_name = BSP_UART0_TX_PIN, \
.rx_pin_name = BSP_UART0_RX_PIN, \
.alternate = BSP_UART0_AFIO, \
.serial = &serial0, \
.device_name = "uart0", \
}
#endif /* UART0_CONFIG */
#endif /* BSP_USING_UART0 */
#if defined(BSP_USING_UART1)
#ifndef UART1_CONFIG
#define UART1_CONFIG \
{ \
.uart_periph = USART1, \
.irqn = USART1_IRQn, \
.per_clk = RCU_USART1, \
.tx_pin_name = BSP_UART1_TX_PIN, \
.rx_pin_name = BSP_UART1_RX_PIN, \
.alternate = BSP_UART1_AFIO, \
.serial = &serial1, \
.device_name = "uart1", \
}
#endif /* UART1_CONFIG */
#endif /* BSP_USING_UART1 */
#if defined(BSP_USING_UART2)
#ifndef UART2_CONFIG
#define UART2_CONFIG \
{ \
.uart_periph = USART2, \
.irqn = USART2_IRQn, \
.per_clk = RCU_USART2, \
.tx_pin_name = BSP_UART2_TX_PIN, \
.rx_pin_name = BSP_UART2_RX_PIN, \
.alternate = BSP_UART2_AFIO, \
.serial = &serial2, \
.device_name = "uart2", \
}
#endif /* UART2_CONFIG */
#endif /* BSP_USING_UART2 */
#if defined(BSP_USING_UART3)
#ifndef UART3_CONFIG
#define UART3_CONFIG \
{ \
.uart_periph = UART3, \
.irqn = UART3_IRQn, \
.per_clk = RCU_UART3, \
.tx_pin_name = BSP_UART3_TX_PIN, \
.rx_pin_name = BSP_UART3_RX_PIN, \
.alternate = BSP_UART3_AFIO, \
.serial = &serial3, \
.device_name = "uart3", \
}
#endif /* UART3_CONFIG */
#endif /* BSP_USING_UART3 */
#if defined(BSP_USING_UART4)
#ifndef UART4_CONFIG
#define UART4_CONFIG \
{ \
.uart_periph = UART4, \
.irqn = UART4_IRQn, \
.per_clk = RCU_UART4, \
.tx_pin_name = BSP_UART4_TX_PIN, \
.rx_pin_name = BSP_UART4_RX_PIN, \
.alternate = BSP_UART4_AFIO, \
.serial = &serial4, \
.device_name = "uart4", \
}
#endif /* UART4_CONFIG */
#endif /* BSP_USING_UART4 */
#if defined(BSP_USING_UART5)
#ifndef UART5_CONFIG
#define UART5_CONFIG \
{ \
.uart_periph = USART5, \
.irqn = USART5_IRQn, \
.per_clk = RCU_USART5, \
.tx_pin_name = BSP_UART5_TX_PIN, \
.rx_pin_name = BSP_UART5_RX_PIN, \
.alternate = BSP_UART5_AFIO, \
.serial = &serial5, \
.device_name = "uart5", \
}
#endif /* UART5_CONFIG */
#endif /* BSP_USING_UART5 */
#if defined(BSP_USING_UART6)
#ifndef UART6_CONFIG
#define UART6_CONFIG \
{ \
.uart_periph = UART6, \
.irqn = UART6_IRQn, \
.per_clk = RCU_UART6, \
.tx_pin_name = BSP_UART6_TX_PIN, \
.rx_pin_name = BSP_UART6_RX_PIN, \
.alternate = BSP_UART6_AFIO, \
.serial = &serial6, \
.device_name = "uart6", \
}
#endif /* UART6_CONFIG */
#endif /* BSP_USING_UART6 */
#if defined(BSP_USING_UART7)
#ifndef UART7_CONFIG
#define UART7_CONFIG \
{ \
.uart_periph = UART7, \
.irqn = UART7_IRQn, \
.per_clk = RCU_UART7, \
.tx_pin_name = BSP_UART7_TX_PIN, \
.rx_pin_name = BSP_UART7_RX_PIN, \
.alternate = BSP_UART7_AFIO, \
.serial = &serial7, \
.device_name = "uart7", \
}
#endif /* UART7_CONFIG */
#endif /* BSP_USING_UART7 */
#ifdef __cplusplus
}
#endif
#endif /* __UART_CONFIG_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,8 @@
* Change Logs:
* Date Author Notes
* 2021-08-20 BruceOu first implementation
* 2025-10-09 WangShun optimize the serial driver
* 2025-11-13 kurisaw general GD driver adaptation
*/
#ifndef __DRV_USART_H__
@@ -19,7 +21,7 @@
extern "C" {
#endif
#ifndef SOC_SERIES_GD32H7xx
#if !defined(SOC_SERIES_GD32H7xx) || !defined(SOC_SERIES_GD32H75E)
#undef RT_SERIAL_USING_DMA
#endif
#define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n))
@@ -33,7 +35,7 @@ typedef struct
uint32_t dma_periph;
/* dma channel */
dma_channel_enum dma_ch;
#ifdef SOC_SERIES_GD32H7xx
#if defined(SOC_SERIES_GD32H7xx) || defined(SOC_SERIES_GD32H75E)
/* rx dma request */
uint32_t dma_mux_req_rx;
#endif
@@ -49,31 +51,16 @@ typedef struct
#endif
/* GD32 uart driver */
/* Todo: compress uart info */
struct gd32_uart
{
uint32_t uart_periph; /* Todo: 3bits */
IRQn_Type irqn; /* Todo: 7bits */
rcu_periph_enum per_clk; /* Todo: 5bits */
rcu_periph_enum tx_gpio_clk; /* Todo: 5bits */
rcu_periph_enum rx_gpio_clk; /* Todo: 5bits */
uint32_t tx_port; /* Todo: 4bits */
#if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx || defined SOC_SERIES_GD32F5xx || defined SOC_SERIES_GD32E23x
uint16_t tx_af; /* Todo: 4bits */
#elif defined SOC_SERIES_GD32E50x
uint32_t tx_af; /* alternate1 cfg */
#endif
uint16_t tx_pin; /* Todo: 4bits */
uint32_t rx_port; /* Todo: 4bits */
#if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx || defined SOC_SERIES_GD32F5xx || defined SOC_SERIES_GD32E23x
uint16_t rx_af; /* Todo: 4bits */
#elif defined SOC_SERIES_GD32E50x
uint32_t rx_af; /* alternate1 cfg */
#endif
uint16_t rx_pin; /* Todo: 4bits */
#if defined SOC_SERIES_GD32E50x
uint32_t uart_remap; /* remap */
#endif
uint32_t uart_periph; /* Instance */
IRQn_Type irqn; /* irqn */
rcu_periph_enum per_clk; /* uart_clk */
const char *tx_pin_name; /* tx pin name */
const char *rx_pin_name; /* rx pin name */
const char *alternate; /* pin alternate */
#ifdef RT_SERIAL_USING_DMA
gd32_uart_dma *uart_dma;
@@ -82,7 +69,7 @@ struct gd32_uart
#endif
#endif
struct rt_serial_device * serial;
struct rt_serial_device * serial; /* serial device */
char *device_name;
};