uart: add support for gd32h7xx

This commit is contained in:
wirano 2024-07-24 22:55:24 +08:00 committed by Rbb666
parent ab2e98aacf
commit 229b2bffec
3 changed files with 58 additions and 26 deletions

View File

@ -67,6 +67,10 @@ void rt_hw_board_init()
SystemClock_Config(); SystemClock_Config();
#ifdef RT_USING_SERIAL
rt_hw_usart_init();
#endif
#ifdef RT_USING_COMPONENTS_INIT #ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init(); rt_components_board_init();
#endif #endif

View File

@ -156,11 +156,18 @@ static const struct gd32_uart uart_obj[] = {
{ {
USART0, // uart peripheral index USART0, // uart peripheral index
USART0_IRQn, // uart iqrn USART0_IRQn, // uart iqrn
RCU_USART0, RCU_GPIOA, RCU_GPIOA, // periph clock, tx gpio clock, rt gpio clock RCU_USART0, // uart periph clock
#if defined SOC_SERIES_GD32F4xx #if defined SOC_SERIES_GD32F4xx
RCU_GPIOA, RCU_GPIOA, // tx gpio clock, rx gpio clock
GPIOA, GPIO_AF_7, GPIO_PIN_9, // tx port, tx alternate, tx pin GPIOA, GPIO_AF_7, GPIO_PIN_9, // tx port, tx alternate, tx pin
GPIOA, GPIO_AF_7, GPIO_PIN_10, // rx port, rx alternate, rx pin GPIOA, GPIO_AF_7, GPIO_PIN_10, // rx port, rx alternate, rx pin
#elif defined SOC_SERIES_GD32H7xx
RCU_GPIOF, // periph clock, tx gpio clock
RCU_GPIOF, // periph clock, rx gpio clock
GPIOF, GPIO_AF_4, GPIO_PIN_4, // tx port, tx alternate, tx pin
GPIOF, GPIO_AF_4, GPIO_PIN_5, // rx port, rx alternate, rx pin
#else #else
RCU_GPIOA, RCU_GPIOA, // tx gpio clock, rx gpio clock
GPIOA, GPIO_PIN_9, // tx port, tx pin GPIOA, GPIO_PIN_9, // tx port, tx pin
GPIOA, GPIO_PIN_10, // rx port, rx pin GPIOA, GPIO_PIN_10, // rx port, rx pin
#endif #endif
@ -173,11 +180,13 @@ static const struct gd32_uart uart_obj[] = {
{ {
USART1, // uart peripheral index USART1, // uart peripheral index
USART1_IRQn, // uart iqrn USART1_IRQn, // uart iqrn
RCU_USART1, RCU_GPIOA, RCU_GPIOA, // periph clock, tx gpio clock, rt gpio clock RCU_USART1, // uart periph clock
#if defined SOC_SERIES_GD32F4xx #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx
RCU_GPIOA, RCU_GPIOA, // tx gpio clock, rx gpio clock
GPIOA, GPIO_AF_7, GPIO_PIN_2, // tx port, tx alternate, tx pin GPIOA, GPIO_AF_7, GPIO_PIN_2, // tx port, tx alternate, tx pin
GPIOA, GPIO_AF_7, GPIO_PIN_3, // rx port, rx alternate, rx pin GPIOA, GPIO_AF_7, GPIO_PIN_3, // rx port, rx alternate, rx pin
#else #else
RCU_GPIOA, RCU_GPIOA, // periph clock, tx gpio clock, rt gpio clock
GPIOA, GPIO_PIN_2, // tx port, tx pin GPIOA, GPIO_PIN_2, // tx port, tx pin
GPIOA, GPIO_PIN_3, // rx port, rx pin GPIOA, GPIO_PIN_3, // rx port, rx pin
#endif #endif
@ -190,11 +199,13 @@ static const struct gd32_uart uart_obj[] = {
{ {
USART2, // uart peripheral index USART2, // uart peripheral index
USART2_IRQn, // uart iqrn USART2_IRQn, // uart iqrn
RCU_USART2, RCU_GPIOB, RCU_GPIOB, // periph clock, tx gpio clock, rt gpio clock RCU_USART2, // uart periph clock
#if defined SOC_SERIES_GD32F4xx #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx
RCU_GPIOB, RCU_GPIOB, // tx gpio clock, rt gpio clock
GPIOB, GPIO_AF_7, GPIO_PIN_10, // tx port, tx alternate, tx pin GPIOB, GPIO_AF_7, GPIO_PIN_10, // tx port, tx alternate, tx pin
GPIOB, GPIO_AF_7, GPIO_PIN_11, // rx port, rx alternate, rx pin GPIOB, GPIO_AF_7, GPIO_PIN_11, // rx port, rx alternate, rx pin
#else #else
RCU_GPIOB, RCU_GPIOB, // tx gpio clock, rt gpio clock
GPIOB, GPIO_PIN_10, // tx port, tx pin GPIOB, GPIO_PIN_10, // tx port, tx pin
GPIOB, GPIO_PIN_11, // rx port, rx pin GPIOB, GPIO_PIN_11, // rx port, rx pin
#endif #endif
@ -207,11 +218,13 @@ static const struct gd32_uart uart_obj[] = {
{ {
UART3, // uart peripheral index UART3, // uart peripheral index
UART3_IRQn, // uart iqrn UART3_IRQn, // uart iqrn
RCU_UART3, RCU_GPIOC, RCU_GPIOC, // periph clock, tx gpio clock, rt gpio clock RCU_USART3, // uart periph clock
#if defined SOC_SERIES_GD32F4xx #if defined SOC_SERIES_GD32F4xx
RCU_GPIOC, RCU_GPIOC, // tx gpio clock, rt gpio clock
GPIOC, GPIO_AF_8, GPIO_PIN_10, // tx port, tx alternate, tx pin GPIOC, GPIO_AF_8, GPIO_PIN_10, // tx port, tx alternate, tx pin
GPIOC, GPIO_AF_8, GPIO_PIN_11, // rx port, rx alternate, rx pin GPIOC, GPIO_AF_8, GPIO_PIN_11, // rx port, rx alternate, rx pin
#else #else
RCU_GPIOC, RCU_GPIOC, // periph clock, tx gpio clock, rt gpio clock
GPIOC, GPIO_PIN_10, // tx port, tx pin GPIOC, GPIO_PIN_10, // tx port, tx pin
GPIOC, GPIO_PIN_11, // rx port, rx pin GPIOC, GPIO_PIN_11, // rx port, rx pin
#endif #endif
@ -321,6 +334,21 @@ void gd32_uart_gpio_init(struct gd32_uart *uart)
gpio_mode_set(uart->rx_port, GPIO_MODE_AF, GPIO_PUPD_PULLUP, 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_50MHZ, uart->rx_pin); gpio_output_options_set(uart->rx_port, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, uart->rx_pin);
#elif defined SOC_SERIES_GD32H7xx
/* connect port to USARTx_Tx */
gpio_af_set(uart->tx_port, uart->tx_af, uart->tx_pin);
/* connect port to USARTx_Rx */
gpio_af_set(uart->rx_port, uart->rx_af, uart->rx_pin);
/* configure USART Tx as alternate function push-pull */
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_60MHZ, uart->tx_pin);
/* configure USART Rx as alternate function push-pull */
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_60MHZ, uart->rx_pin);
#else #else
/* connect port to USARTx_Tx */ /* connect port to USARTx_Tx */
gpio_init(uart->tx_port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, uart->tx_pin); gpio_init(uart->tx_port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, uart->tx_pin);

View File

@ -33,12 +33,12 @@ struct gd32_uart
rcu_periph_enum tx_gpio_clk; //Todo: 5bits rcu_periph_enum tx_gpio_clk; //Todo: 5bits
rcu_periph_enum rx_gpio_clk; //Todo: 5bits rcu_periph_enum rx_gpio_clk; //Todo: 5bits
uint32_t tx_port; //Todo: 4bits uint32_t tx_port; //Todo: 4bits
#if defined SOC_SERIES_GD32F4xx #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx
uint16_t tx_af; //Todo: 4bits uint16_t tx_af; //Todo: 4bits
#endif #endif
uint16_t tx_pin; //Todo: 4bits uint16_t tx_pin; //Todo: 4bits
uint32_t rx_port; //Todo: 4bits uint32_t rx_port; //Todo: 4bits
#if defined SOC_SERIES_GD32F4xx #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx
uint16_t rx_af; //Todo: 4bits uint16_t rx_af; //Todo: 4bits
#endif #endif
uint16_t rx_pin; //Todo: 4bits uint16_t rx_pin; //Todo: 4bits