Skip to content

Commit c2252f6

Browse files
authored
Merge pull request #4003 from mysterywolf/pr4
[bsp][stm32][bluepill] add USART2
2 parents 37ecf07 + 2b322ee commit c2252f6

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

bsp/stm32/stm32f103-blue-pill/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
222222
GPIO_InitTypeDef GPIO_InitStruct = {0};
223223
if(huart->Instance==USART1)
224224
{
225-
/* USER CODE BEGIN USART1_MspInit 0 */
226-
227-
/* USER CODE END USART1_MspInit 0 */
228225
/* Peripheral clock enable */
229226
__HAL_RCC_USART1_CLK_ENABLE();
230227

@@ -242,12 +239,28 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
242239
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
243240
GPIO_InitStruct.Pull = GPIO_NOPULL;
244241
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
245-
246-
/* USER CODE BEGIN USART1_MspInit 1 */
247-
248-
/* USER CODE END USART1_MspInit 1 */
249242
}
243+
244+
if(huart->Instance==USART2)
245+
{
246+
/* Peripheral clock enable */
247+
__HAL_RCC_USART2_CLK_ENABLE();
248+
249+
__HAL_RCC_GPIOA_CLK_ENABLE();
250+
/**USART1 GPIO Configuration
251+
PA2 ------> USART2_TX
252+
PA3 ------> USART2_RX
253+
*/
254+
GPIO_InitStruct.Pin = GPIO_PIN_2;
255+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
256+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
257+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
250258

259+
GPIO_InitStruct.Pin = GPIO_PIN_3;
260+
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
261+
GPIO_InitStruct.Pull = GPIO_NOPULL;
262+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
263+
}
251264
}
252265

253266
/**

bsp/stm32/stm32f103-blue-pill/board/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ menu "On-chip Peripheral Drivers"
3737
bool "Enable UART1 RX DMA"
3838
depends on BSP_USING_UART1 && RT_SERIAL_USING_DMA
3939
default n
40+
41+
config BSP_USING_UART2
42+
bool "Enable UART2"
43+
default n
44+
45+
config BSP_UART2_RX_USING_DMA
46+
bool "Enable UART2 RX DMA"
47+
depends on BSP_USING_UART2 && RT_SERIAL_USING_DMA
48+
default n
4049
endif
4150

4251
menuconfig BSP_USING_ONCHIP_RTC

0 commit comments

Comments
 (0)