From 2b322eecc498a979c1554c19e7988311ae96d345 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Fri, 30 Oct 2020 12:46:18 +0800 Subject: [PATCH] [bsp][stm32][bluepill] add USART2 --- .../CubeMX_Config/Src/stm32f1xx_hal_msp.c | 27 ++++++++++++++----- bsp/stm32/stm32f103-blue-pill/board/Kconfig | 9 +++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c b/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c index 663b3021fa..8e3f5be31e 100644 --- a/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c +++ b/bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c @@ -222,9 +222,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) GPIO_InitTypeDef GPIO_InitStruct = {0}; if(huart->Instance==USART1) { - /* USER CODE BEGIN USART1_MspInit 0 */ - - /* USER CODE END USART1_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_USART1_CLK_ENABLE(); @@ -242,12 +239,28 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN USART1_MspInit 1 */ - - /* USER CODE END USART1_MspInit 1 */ } + + if(huart->Instance==USART2) + { + /* Peripheral clock enable */ + __HAL_RCC_USART2_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USART1 GPIO Configuration + PA2 ------> USART2_TX + PA3 ------> USART2_RX + */ + GPIO_InitStruct.Pin = GPIO_PIN_2; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_3; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + } } /** diff --git a/bsp/stm32/stm32f103-blue-pill/board/Kconfig b/bsp/stm32/stm32f103-blue-pill/board/Kconfig index 11dd928381..7c223cbabd 100644 --- a/bsp/stm32/stm32f103-blue-pill/board/Kconfig +++ b/bsp/stm32/stm32f103-blue-pill/board/Kconfig @@ -37,6 +37,15 @@ menu "On-chip Peripheral Drivers" bool "Enable UART1 RX DMA" depends on BSP_USING_UART1 && RT_SERIAL_USING_DMA default n + + config BSP_USING_UART2 + bool "Enable UART2" + default n + + config BSP_UART2_RX_USING_DMA + bool "Enable UART2 RX DMA" + depends on BSP_USING_UART2 && RT_SERIAL_USING_DMA + default n endif menuconfig BSP_USING_ONCHIP_RTC