From 291597de217f6232f9d065f30542ba31f12b9e03 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Tue, 2 Apr 2019 19:36:13 +0800 Subject: [PATCH] [bsp][stm32][f411-nucleo] add uart6 support. --- bsp/stm32/stm32f411-st-nucleo/.config | 23 +++++++--- .../board/CubeMX_Config/CubeMX_Config.ioc | 40 +++++++++------- .../board/CubeMX_Config/Inc/main.h | 2 - .../board/CubeMX_Config/Src/main.c | 46 +++++++++++++++---- .../CubeMX_Config/Src/stm32f4xx_hal_msp.c | 42 +++++++++++++++++ bsp/stm32/stm32f411-st-nucleo/board/Kconfig | 14 +++++- bsp/stm32/stm32f411-st-nucleo/rtconfig.h | 3 -- 7 files changed, 130 insertions(+), 40 deletions(-) diff --git a/bsp/stm32/stm32f411-st-nucleo/.config b/bsp/stm32/stm32f411-st-nucleo/.config index 6df7485ea9..e8df7c72f9 100644 --- a/bsp/stm32/stm32f411-st-nucleo/.config +++ b/bsp/stm32/stm32f411-st-nucleo/.config @@ -7,6 +7,7 @@ # RT-Thread Kernel # CONFIG_RT_NAME_MAX=8 +# CONFIG_RT_USING_ARCH_DATA_TYPE is not set # CONFIG_RT_USING_SMP is not set CONFIG_RT_ALIGN_SIZE=4 # CONFIG_RT_THREAD_PRIORITY_8 is not set @@ -111,6 +112,7 @@ CONFIG_FINSH_ARG_MAX=10 # CONFIG_RT_USING_DEVICE_IPC=y CONFIG_RT_PIPE_BUFSZ=512 +# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set CONFIG_RT_USING_SERIAL=y # CONFIG_RT_SERIAL_USING_DMA is not set CONFIG_RT_SERIAL_RB_BUFSZ=64 @@ -185,12 +187,6 @@ CONFIG_RT_USING_PIN=y # CONFIG_RT_USING_RYM is not set # CONFIG_RT_USING_ULOG is not set # CONFIG_RT_USING_UTEST is not set - -# -# ARM CMSIS -# -# CONFIG_RT_USING_CMSIS_OS is not set -# CONFIG_RT_USING_RTT_CMSIS is not set # CONFIG_RT_USING_LWP is not set # @@ -207,6 +203,7 @@ CONFIG_RT_USING_PIN=y # CONFIG_PKG_USING_WEBTERMINAL is not set # CONFIG_PKG_USING_CJSON is not set # CONFIG_PKG_USING_JSMN is not set +# CONFIG_PKG_USING_LIBMODBUS is not set # CONFIG_PKG_USING_LJSON is not set # CONFIG_PKG_USING_EZXML is not set # CONFIG_PKG_USING_NANOPB is not set @@ -224,6 +221,7 @@ CONFIG_RT_USING_PIN=y # Wiced WiFi # # CONFIG_PKG_USING_WLAN_WICED is not set +# CONFIG_PKG_USING_RW007 is not set # CONFIG_PKG_USING_COAP is not set # CONFIG_PKG_USING_NOPOLL is not set # CONFIG_PKG_USING_NETUTILS is not set @@ -238,6 +236,8 @@ CONFIG_RT_USING_PIN=y # CONFIG_PKG_USING_ALI_IOTKIT is not set # CONFIG_PKG_USING_AZURE is not set # CONFIG_PKG_USING_TENCENT_IOTKIT is not set +# CONFIG_PKG_USING_NIMBLE is not set +# CONFIG_PKG_USING_OTA_DOWNLOADER is not set # # security packages @@ -258,6 +258,7 @@ CONFIG_RT_USING_PIN=y # # CONFIG_PKG_USING_OPENMV is not set # CONFIG_PKG_USING_MUPDF is not set +# CONFIG_PKG_USING_STEMWIN is not set # # tools packages @@ -269,6 +270,7 @@ CONFIG_RT_USING_PIN=y # CONFIG_PKG_USING_RDB is not set # CONFIG_PKG_USING_QRCODE is not set # CONFIG_PKG_USING_ULOG_EASYFLASH is not set +# CONFIG_PKG_USING_ADBD is not set # # system packages @@ -286,10 +288,12 @@ CONFIG_RT_USING_PIN=y # CONFIG_PKG_USING_CMSIS is not set # CONFIG_PKG_USING_DFS_YAFFS is not set # CONFIG_PKG_USING_LITTLEFS is not set +# CONFIG_PKG_USING_THREAD_POOL is not set # # peripheral libraries and drivers # +# CONFIG_PKG_USING_SENSORS_DRIVERS is not set # CONFIG_PKG_USING_REALTEK_AMEBA is not set # CONFIG_PKG_USING_SHT2X is not set # CONFIG_PKG_USING_AHT10 is not set @@ -300,7 +304,11 @@ CONFIG_RT_USING_PIN=y # CONFIG_PKG_USING_BUTTON is not set # CONFIG_PKG_USING_MPU6XXX is not set # CONFIG_PKG_USING_PCF8574 is not set +# CONFIG_PKG_USING_SX12XX is not set +# CONFIG_PKG_USING_SIGNAL_LED is not set +# CONFIG_PKG_USING_WM_LIBRARIES is not set # CONFIG_PKG_USING_KENDRYTE_SDK is not set +# CONFIG_PKG_USING_INFRARED is not set # # miscellaneous packages @@ -326,6 +334,8 @@ CONFIG_RT_USING_PIN=y # CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set # CONFIG_PKG_USING_HELLO is not set # CONFIG_PKG_USING_VI is not set +# CONFIG_PKG_USING_NNOM is not set + CONFIG_SOC_FAMILY_STM32=y CONFIG_SOC_SERIES_STM32F4=y @@ -344,6 +354,7 @@ CONFIG_SOC_STM32F411RE=y CONFIG_BSP_USING_GPIO=y CONFIG_BSP_USING_UART=y CONFIG_BSP_USING_UART2=y +# CONFIG_BSP_USING_UART6 is not set # CONFIG_BSP_USING_I2C1 is not set # CONFIG_BSP_USING_PWM is not set # CONFIG_BSP_USING_ON_CHIP_FLASH is not set diff --git a/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/CubeMX_Config.ioc b/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/CubeMX_Config.ioc index 81e4b8cf64..f86fed8a1f 100644 --- a/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/CubeMX_Config.ioc +++ b/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/CubeMX_Config.ioc @@ -7,27 +7,29 @@ Mcu.IP1=RCC Mcu.IP2=SYS Mcu.IP3=TIM3 Mcu.IP4=USART2 -Mcu.IPNb=5 +Mcu.IP5=USART6 +Mcu.IPNb=6 Mcu.Name=STM32F411R(C-E)Tx Mcu.Package=LQFP64 Mcu.Pin0=PC13-ANTI_TAMP Mcu.Pin1=PC14-OSC32_IN -Mcu.Pin10=PB0 -Mcu.Pin11=PB1 -Mcu.Pin12=PA13 -Mcu.Pin13=PA14 -Mcu.Pin14=PB3 -Mcu.Pin15=VP_SYS_VS_Systick -Mcu.Pin16=VP_TIM3_VS_ClockSourceINT +Mcu.Pin10=PB1 +Mcu.Pin11=PA11 +Mcu.Pin12=PA12 +Mcu.Pin13=PA13 +Mcu.Pin14=PA14 +Mcu.Pin15=PB3 +Mcu.Pin16=VP_SYS_VS_Systick +Mcu.Pin17=VP_TIM3_VS_ClockSourceINT Mcu.Pin2=PC15-OSC32_OUT Mcu.Pin3=PH0 - OSC_IN Mcu.Pin4=PH1 - OSC_OUT Mcu.Pin5=PA2 Mcu.Pin6=PA3 -Mcu.Pin7=PA5 -Mcu.Pin8=PA6 -Mcu.Pin9=PA7 -Mcu.PinsNb=17 +Mcu.Pin7=PA6 +Mcu.Pin8=PA7 +Mcu.Pin9=PB0 +Mcu.PinsNb=18 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F411RETx @@ -43,6 +45,12 @@ NVIC.PriorityGroup=NVIC_PRIORITYGROUP_0 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false NVIC.SysTick_IRQn=true\:0\:0\:true\:false\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true +PA11.Locked=true +PA11.Mode=Asynchronous +PA11.Signal=USART6_TX +PA12.Locked=true +PA12.Mode=Asynchronous +PA12.Signal=USART6_RX PA13.GPIOParameters=GPIO_Label PA13.GPIO_Label=TMS PA13.Locked=true @@ -57,10 +65,6 @@ PA2.Mode=Asynchronous PA2.Signal=USART2_TX PA3.Mode=Asynchronous PA3.Signal=USART2_RX -PA5.GPIOParameters=GPIO_Label -PA5.GPIO_Label=LD2 [Green Led] -PA5.Locked=true -PA5.Signal=GPIO_Output PA6.Signal=S_TIM3_CH1 PA7.Signal=S_TIM3_CH2 PB0.Signal=S_TIM3_CH3 @@ -121,7 +125,7 @@ ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=MDK-ARM V5 ProjectManager.ToolChainLocation= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_TIM3_Init-TIM3-false-HAL-true +ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_TIM3_Init-TIM3-false-HAL-true,5-MX_USART6_UART_Init-USART6-false-HAL-true RCC.48MHZClocksFreq_Value=42000000 RCC.AHBFreq_Value=84000000 RCC.APB1CLKDivider=RCC_HCLK_DIV2 @@ -172,6 +176,8 @@ TIM3.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4 TIM3.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4 USART2.IPParameters=VirtualMode USART2.VirtualMode=VM_ASYNC +USART6.IPParameters=VirtualMode +USART6.VirtualMode=VM_ASYNC VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick VP_TIM3_VS_ClockSourceINT.Mode=Internal diff --git a/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Inc/main.h b/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Inc/main.h index 3651f0788e..7dd412343c 100644 --- a/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Inc/main.h +++ b/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Inc/main.h @@ -82,8 +82,6 @@ void Error_Handler(void); /* Private defines -----------------------------------------------------------*/ #define B1_Pin GPIO_PIN_13 #define B1_GPIO_Port GPIOC -#define LD2_Pin GPIO_PIN_5 -#define LD2_GPIO_Port GPIOA #define TMS_Pin GPIO_PIN_13 #define TMS_GPIO_Port GPIOA #define TCK_Pin GPIO_PIN_14 diff --git a/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Src/main.c b/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Src/main.c index cb90fe22eb..261a100abd 100644 --- a/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Src/main.c +++ b/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Src/main.c @@ -65,6 +65,7 @@ TIM_HandleTypeDef htim3; UART_HandleTypeDef huart2; +UART_HandleTypeDef huart6; /* USER CODE BEGIN PV */ @@ -75,6 +76,7 @@ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); static void MX_TIM3_Init(void); +static void MX_USART6_UART_Init(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ @@ -114,6 +116,7 @@ int main(void) MX_GPIO_Init(); MX_USART2_UART_Init(); MX_TIM3_Init(); + MX_USART6_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ @@ -274,6 +277,39 @@ static void MX_USART2_UART_Init(void) } +/** + * @brief USART6 Initialization Function + * @param None + * @retval None + */ +static void MX_USART6_UART_Init(void) +{ + + /* USER CODE BEGIN USART6_Init 0 */ + + /* USER CODE END USART6_Init 0 */ + + /* USER CODE BEGIN USART6_Init 1 */ + + /* USER CODE END USART6_Init 1 */ + huart6.Instance = USART6; + huart6.Init.BaudRate = 115200; + huart6.Init.WordLength = UART_WORDLENGTH_8B; + huart6.Init.StopBits = UART_STOPBITS_1; + huart6.Init.Parity = UART_PARITY_NONE; + huart6.Init.Mode = UART_MODE_TX_RX; + huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart6.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart6) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN USART6_Init 2 */ + + /* USER CODE END USART6_Init 2 */ + +} + /** * @brief GPIO Initialization Function * @param None @@ -289,22 +325,12 @@ static void MX_GPIO_Init(void) __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin : B1_Pin */ GPIO_InitStruct.Pin = B1_Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pin : LD2_Pin */ - GPIO_InitStruct.Pin = LD2_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct); - } /* USER CODE BEGIN 4 */ diff --git a/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Src/stm32f4xx_hal_msp.c b/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Src/stm32f4xx_hal_msp.c index 0cc7029333..0c869664cb 100644 --- a/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Src/stm32f4xx_hal_msp.c +++ b/bsp/stm32/stm32f411-st-nucleo/board/CubeMX_Config/Src/stm32f4xx_hal_msp.c @@ -220,6 +220,30 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) /* USER CODE END USART2_MspInit 1 */ } + else if(huart->Instance==USART6) + { + /* USER CODE BEGIN USART6_MspInit 0 */ + + /* USER CODE END USART6_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_USART6_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USART6 GPIO Configuration + PA11 ------> USART6_TX + PA12 ------> USART6_RX + */ + GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF8_USART6; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN USART6_MspInit 1 */ + + /* USER CODE END USART6_MspInit 1 */ + } } @@ -251,6 +275,24 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) /* USER CODE END USART2_MspDeInit 1 */ } + else if(huart->Instance==USART6) + { + /* USER CODE BEGIN USART6_MspDeInit 0 */ + + /* USER CODE END USART6_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART6_CLK_DISABLE(); + + /**USART6 GPIO Configuration + PA11 ------> USART6_TX + PA12 ------> USART6_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); + + /* USER CODE BEGIN USART6_MspDeInit 1 */ + + /* USER CODE END USART6_MspDeInit 1 */ + } } diff --git a/bsp/stm32/stm32f411-st-nucleo/board/Kconfig b/bsp/stm32/stm32f411-st-nucleo/board/Kconfig index 92402d950d..737f4511ac 100644 --- a/bsp/stm32/stm32f411-st-nucleo/board/Kconfig +++ b/bsp/stm32/stm32f411-st-nucleo/board/Kconfig @@ -29,6 +29,15 @@ menu "On-chip Peripheral Drivers" bool "Enable UART2 RX DMA" depends on BSP_USING_UART2 && RT_SERIAL_USING_DMA default n + + config BSP_USING_UART6 + bool "Enable UART6" + default y + + config BSP_UART6_RX_USING_DMA + bool "Enable UART6 RX DMA" + depends on BSP_USING_UART6 && RT_SERIAL_USING_DMA + default n endif menuconfig BSP_USING_I2C1 @@ -38,14 +47,15 @@ menu "On-chip Peripheral Drivers" select RT_USING_I2C_BITOPS select RT_USING_PIN if BSP_USING_I2C1 + comment "Notice: PB8 --> 24; PB9 --> 25" config BSP_I2C1_SCL_PIN int "i2c1 scl pin number" range 0 80 - default 30 + default 24 config BSP_I2C1_SDA_PIN int "I2C1 sda pin number" range 0 80 - default 31 + default 25 endif menuconfig BSP_USING_PWM diff --git a/bsp/stm32/stm32f411-st-nucleo/rtconfig.h b/bsp/stm32/stm32f411-st-nucleo/rtconfig.h index 1d7b6ca3f0..3f842a28cb 100644 --- a/bsp/stm32/stm32f411-st-nucleo/rtconfig.h +++ b/bsp/stm32/stm32f411-st-nucleo/rtconfig.h @@ -110,9 +110,6 @@ /* Utilities */ -/* ARM CMSIS */ - - /* RT-Thread online packages */ /* IoT - internet of things */