summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorself-confident neko <[email protected]>2022-09-02 00:35:11 +0800
committerGitHub <[email protected]>2022-09-01 12:35:11 -0400
commit6da3b2b4b6e7af3c1c80682706d10bdcaa61155e (patch)
tree199ec843996a784e7e9b9711c180dfa64e7e6afc
parent44b815d8d58b55bd14088a1c8a62fa7ea7595c2f (diff)
完善CH32V307的串口BSP (#6359)
* Update drv_usart.h CH32V307的串口1外设是对接在APB2桥上,其他串口均对接在APB1桥上 已完全测试,并发现一个问题,已修正。
-rw-r--r--bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.c91
-rw-r--r--bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.h3
2 files changed, 82 insertions, 12 deletions
diff --git a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.c b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.c
index bca62de814..e409acc637 100644
--- a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.c
+++ b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.c
@@ -59,7 +59,7 @@ static struct ch32_uart_hw_config uart_hw_config[] =
#ifdef BSP_USING_UART1
{
/* clock configuration, please refer to ch32v30x_rcc.h */
- RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA,
+ RCC_APB2Periph_USART1, RCC_APB2Periph_GPIOA,
/* GPIO configuration : TX_Port,TX_Pin, RX_Port,RX_Pin */
GPIOA, GPIO_Pin_9, /* Tx */GPIOA, GPIO_Pin_10, /* Rx */
/* Whether to enable port remapping, you can refer to ch32v30x_gpio.h file,
@@ -68,25 +68,81 @@ static struct ch32_uart_hw_config uart_hw_config[] =
},
#endif
#ifdef BSP_USING_UART2
- {},
+ {
+ /* clock configuration, please refer to ch32v30x_rcc.h */
+ RCC_APB1Periph_USART2, RCC_APB2Periph_GPIOA,
+ /* GPIO configuration : TX_Port,TX_Pin, RX_Port,RX_Pin */
+ GPIOA, GPIO_Pin_2, /* Tx */GPIOA, GPIO_Pin_3, /* Rx */
+ /* Whether to enable port remapping, you can refer to ch32v30x_gpio.h file,
+ for example, USART1 needs to be turned on, you can use GPIO_Remap_USART1 */
+ GPIO_Remap_NONE,
+ },
#endif
#ifdef BSP_USING_UART3
- {},
+ {
+ /* clock configuration, please refer to ch32v30x_rcc.h */
+ RCC_APB1Periph_USART3, RCC_APB2Periph_GPIOB,
+ /* GPIO configuration : TX_Port,TX_Pin, RX_Port,RX_Pin */
+ GPIOB, GPIO_Pin_10, /* Tx */GPIOB, GPIO_Pin_11, /* Rx */
+ /* Whether to enable port remapping, you can refer to ch32v30x_gpio.h file,
+ for example, USART1 needs to be turned on, you can use GPIO_Remap_USART1 */
+ GPIO_Remap_NONE,
+ },
#endif
#ifdef BSP_USING_UART4
- {},
+ {
+ /* clock configuration, please refer to ch32v30x_rcc.h */
+ RCC_APB1Periph_UART4, RCC_APB2Periph_GPIOC,
+ /* GPIO configuration : TX_Port,TX_Pin, RX_Port,RX_Pin */
+ GPIOC, GPIO_Pin_10, /* Tx */GPIOC, GPIO_Pin_11, /* Rx */
+ /* Whether to enable port remapping, you can refer to ch32v30x_gpio.h file,
+ for example, USART1 needs to be turned on, you can use GPIO_Remap_USART1 */
+ GPIO_Remap_NONE,
+ },
#endif
#ifdef BSP_USING_UART5
- {},
+ {
+ /* clock configuration, please refer to ch32v30x_rcc.h */
+ RCC_APB1Periph_UART5, RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD,
+ /* GPIO configuration : TX_Port,TX_Pin, RX_Port,RX_Pin */
+ GPIOC, GPIO_Pin_12, /* Tx */GPIOD, GPIO_Pin_2, /* Rx */
+ /* Whether to enable port remapping, you can refer to ch32v30x_gpio.h file,
+ for example, USART1 needs to be turned on, you can use GPIO_Remap_USART1 */
+ GPIO_Remap_NONE,
+ },
#endif
#ifdef BSP_USING_UART6
- {},
+ {
+ /* clock configuration, please refer to ch32v30x_rcc.h */
+ RCC_APB1Periph_UART6, RCC_APB2Periph_GPIOC,
+ /* GPIO configuration : TX_Port,TX_Pin, RX_Port,RX_Pin */
+ GPIOC, GPIO_Pin_0, /* Tx */GPIOC, GPIO_Pin_1, /* Rx */
+ /* Whether to enable port remapping, you can refer to ch32v30x_gpio.h file,
+ for example, USART1 needs to be turned on, you can use GPIO_Remap_USART1 */
+ GPIO_Remap_NONE,
+ },
#endif
#ifdef BSP_USING_UART7
- {},
+ {
+ /* clock configuration, please refer to ch32v30x_rcc.h */
+ RCC_APB1Periph_UART7, RCC_APB2Periph_GPIOC,
+ /* GPIO configuration : TX_Port,TX_Pin, RX_Port,RX_Pin */
+ GPIOC, GPIO_Pin_2, /* Tx */GPIOC, GPIO_Pin_3, /* Rx */
+ /* Whether to enable port remapping, you can refer to ch32v30x_gpio.h file,
+ for example, USART1 needs to be turned on, you can use GPIO_Remap_USART1 */
+ GPIO_Remap_NONE,
+ },
#endif
#ifdef BSP_USING_UART8
- {},
+ {
+ /* clock configuration, please refer to ch32v30x_rcc.h */
+ RCC_APB1Periph_UART8, RCC_APB2Periph_GPIOC,
+ /* GPIO configuration : TX_Port,TX_Pin, RX_Port,RX_Pin */
+ GPIOC, GPIO_Pin_4, /* Tx */GPIOC, GPIO_Pin_5, /* Rx */
+ /* Whether to enable port remapping, you can refer to ch32v30x_gpio.h file,
+ for example, USART1 needs to be turned on, you can use GPIO_Remap_USART1 */
+ GPIO_Remap_NONE,
+ },
#endif
};
@@ -208,7 +264,15 @@ static rt_err_t ch32_configure(struct rt_serial_device *serial, struct serial_co
}
/* UART hardware configuration, including clock and GPIO, etc. */
- RCC_APB2PeriphClockCmd(uart->hw_config->periph_clock, ENABLE);
+ RCC_APB2PeriphClockCmd(uart->hw_config->gpio_periph_clock, ENABLE);
+ if(uart->config->Instance == USART1)
+ {
+ RCC_APB2PeriphClockCmd(uart->hw_config->uart_periph_clock, ENABLE);
+ }
+ else
+ {
+ RCC_APB1PeriphClockCmd(uart->hw_config->uart_periph_clock, ENABLE);
+ }
if(uart->hw_config->remap != GPIO_Remap_NONE)
{
@@ -415,9 +479,14 @@ int rt_hw_usart_init(void)
uart_obj[i].serial.config = config;
/* Hardware initialization is required, otherwise it
will not be registered into the device framework */
- if(uart_obj[i].hw_config->periph_clock == 0)
+ if(uart_obj[i].hw_config->gpio_periph_clock == 0)
+ {
+ LOG_E("You did not perform hardware initialization for %s", uart_obj[i].config->name);
+ continue;
+ }
+ if(uart_obj[i].hw_config->uart_periph_clock == 0)
{
- LOG_E("You did not perform hardware initialization for %s", uart->config->name);
+ LOG_E("You did not perform hardware initialization for %s", uart_obj[i].config->name);
continue;
}
/* register UART device */
diff --git a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.h b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.h
index 7c56771914..b002887a19 100644
--- a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.h
+++ b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_usart.h
@@ -20,7 +20,8 @@
/* ch32 hardware config class */
struct ch32_uart_hw_config
{
- rt_uint32_t periph_clock;
+ rt_uint32_t uart_periph_clock;
+ rt_uint32_t gpio_periph_clock;
GPIO_TypeDef *tx_gpio_port;
rt_uint16_t tx_gpio_pin;
GPIO_TypeDef *rx_gpio_port;