From 18eed95c7e091eae79a29567f7f3bab3d8b7fa93 Mon Sep 17 00:00:00 2001 From: JasonChen <2805998671@qq.com> Date: Sat, 13 Jul 2024 16:34:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=84=20refactor:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9B=9E=E4=B8=B2=E5=8F=A32=20DMA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .mxproject | 5 ++ CAR.ioc | 12 +-- Core/Inc/stm32f1xx_it.h | 1 - Core/Inc/usart.h | 2 +- Core/Src/main.c | 161 +++++++++++++++++++++------------------- Core/Src/stm32f1xx_it.c | 15 ---- Core/Src/tim.c | 2 +- Core/Src/usart.c | 103 ++++++++++++------------- Makefile | 7 +- 9 files changed, 152 insertions(+), 156 deletions(-) diff --git a/.mxproject b/.mxproject index c36ebc1..d4a8207 100644 --- a/.mxproject +++ b/.mxproject @@ -6,6 +6,11 @@ SourceFiles=..\Core\Src\main.c;..\Core\Src\gpio.c;..\Core\Src\dma.c;..\Core\Src\ HeaderPath=..\Drivers\STM32F1xx_HAL_Driver\Inc;..\Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;..\Drivers\CMSIS\Device\ST\STM32F1xx\Include;..\Core\Inc; CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER; +[PreviousUsedMakefileFiles] +SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\dma.c;Core\Src\i2c.c;Core\Src\tim.c;Core\Src\usart.c;Core\Src\stm32f1xx_it.c;Core\Src\stm32f1xx_hal_msp.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_i2c.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_i2c.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_uart.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;;; +HeaderPath=Drivers\STM32F1xx_HAL_Driver\Inc;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;Drivers\CMSIS\Device\ST\STM32F1xx\Include;Drivers\CMSIS\Include;Core\Inc; +CDefines=USE_HAL_DRIVER;STM32F103xB;USE_HAL_DRIVER;USE_HAL_DRIVER; + [PreviousGenFiles] AdvancedFolderStructure=true HeaderFileListSize=8 diff --git a/CAR.ioc b/CAR.ioc index aeb2d55..6e324ba 100644 --- a/CAR.ioc +++ b/CAR.ioc @@ -77,7 +77,6 @@ NVIC.PriorityGroup=NVIC_PRIORITYGROUP_2 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.SysTick_IRQn=true\:3\:0\:true\:false\:true\:false\:true\:false NVIC.TIM2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true -NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA0-WKUP.GPIOParameters=PinState,GPIO_Label @@ -90,6 +89,8 @@ PA1.GPIO_Label=FAN_GS PA1.Locked=true PA1.PinState=GPIO_PIN_SET PA1.Signal=GPIO_Output +PA10.Mode=Asynchronous +PA10.Signal=USART1_RX PA12.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI PA12.GPIO_Label=Echo PA12.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING @@ -113,6 +114,8 @@ PA7.GPIOParameters=GPIO_Label PA7.GPIO_Label=LED_B_TIM3CH2 PA7.Locked=true PA7.Signal=S_TIM3_CH2 +PA9.Mode=Asynchronous +PA9.Signal=USART1_TX PB0.GPIOParameters=GPIO_Label PB0.GPIO_Label=LED_G_TIM3CH3 PB0.Locked=true @@ -189,7 +192,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_I2C2_Init-I2C2-false-HAL-true,5-MX_TIM2_Init-TIM2-false-HAL-true,6-MX_TIM3_Init-TIM3-false-HAL-true,7-MX_TIM4_Init-TIM4-false-HAL-true,8-MX_USART1_UART_Init-USART1-false-HAL-true,9-MX_USART2_UART_Init-USART2-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_I2C2_Init-I2C2-false-HAL-true,5-MX_TIM2_Init-TIM2-false-HAL-true,6-MX_TIM3_Init-TIM3-false-HAL-true,7-MX_TIM4_Init-TIM4-false-HAL-true,8-MX_USART2_UART_Init-USART2-false-HAL-true,9-MX_USART1_UART_Init-USART1-false-HAL-true RCC.ADCFreqValue=36000000 RCC.AHBFreq_Value=72000000 RCC.APB1CLKDivider=RCC_HCLK_DIV2 @@ -249,11 +252,8 @@ USART1.IPParameters=VirtualMode,BaudRate,Parity,WordLength USART1.Parity=PARITY_NONE USART1.VirtualMode=VM_ASYNC USART1.WordLength=WORDLENGTH_8B -USART2.BaudRate=9600 -USART2.IPParameters=VirtualMode,BaudRate,Parity,WordLength -USART2.Parity=PARITY_NONE +USART2.IPParameters=VirtualMode USART2.VirtualMode=VM_ASYNC -USART2.WordLength=WORDLENGTH_8B VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick VP_TIM2_VS_ClockSourceINT.Mode=Internal diff --git a/Core/Inc/stm32f1xx_it.h b/Core/Inc/stm32f1xx_it.h index 63af3ef..5e2b5bf 100644 --- a/Core/Inc/stm32f1xx_it.h +++ b/Core/Inc/stm32f1xx_it.h @@ -57,7 +57,6 @@ void PendSV_Handler(void); void SysTick_Handler(void); void DMA1_Channel6_IRQHandler(void); void TIM2_IRQHandler(void); -void USART1_IRQHandler(void); void USART2_IRQHandler(void); void EXTI15_10_IRQHandler(void); /* USER CODE BEGIN EFP */ diff --git a/Core/Inc/usart.h b/Core/Inc/usart.h index 37e914b..c54411d 100644 --- a/Core/Inc/usart.h +++ b/Core/Inc/usart.h @@ -32,7 +32,7 @@ extern "C" { /* USER CODE END Includes */ -extern UART_HandleTypeDef huart2; +extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart2; diff --git a/Core/Src/main.c b/Core/Src/main.c index 750cce2..f78c47e 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -18,11 +18,11 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - -#include "gpio.h" +#include "dma.h" #include "i2c.h" #include "tim.h" #include "usart.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -68,38 +68,42 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ -int main(void) { - /* USER CODE BEGIN 1 */ + * @brief The application entry point. + * @retval int + */ +int main(void) +{ - /* USER CODE END 1 */ + /* USER CODE BEGIN 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* USER CODE END 1 */ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* MCU Configuration--------------------------------------------------------*/ - /* USER CODE BEGIN Init */ + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE END Init */ + /* USER CODE BEGIN Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* USER CODE END Init */ - /* USER CODE BEGIN SysInit */ + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE END SysInit */ + /* USER CODE BEGIN SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_I2C2_Init(); - MX_TIM3_Init(); - MX_TIM4_Init(); - MX_TIM2_Init(); - MX_USART2_UART_Init(); - /* USER CODE BEGIN 2 */ + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_DMA_Init(); + MX_I2C2_Init(); + MX_TIM2_Init(); + MX_TIM3_Init(); + MX_TIM4_Init(); + MX_USART2_UART_Init(); + MX_USART1_UART_Init(); + /* USER CODE BEGIN 2 */ HC_SR04_Init(); /* Initialize all configured peripherals */ @@ -108,14 +112,13 @@ int main(void) { MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); - MX_USART1_UART_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { printf("test\n"); @@ -125,46 +128,50 @@ int main(void) { HAL_Delay(300); // 延时300毫秒 - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) { - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { - Error_Handler(); - } + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { - Error_Handler(); - } + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -172,30 +179,32 @@ void SystemClock_Config(void) { /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ +void Error_Handler(void) +{ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t *file, uint32_t line) +{ + /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/Core/Src/stm32f1xx_it.c b/Core/Src/stm32f1xx_it.c index cd1dc7d..b92439a 100644 --- a/Core/Src/stm32f1xx_it.c +++ b/Core/Src/stm32f1xx_it.c @@ -57,7 +57,6 @@ /* External variables --------------------------------------------------------*/ extern TIM_HandleTypeDef htim2; extern DMA_HandleTypeDef hdma_usart2_rx; -extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart2; /* USER CODE BEGIN EV */ @@ -229,20 +228,6 @@ void TIM2_IRQHandler(void) /* USER CODE END TIM2_IRQn 1 */ } -/** - * @brief This function handles USART1 global interrupt. - */ -void USART1_IRQHandler(void) -{ - /* USER CODE BEGIN USART1_IRQn 0 */ - - /* USER CODE END USART1_IRQn 0 */ - HAL_UART_IRQHandler(&huart1); - /* USER CODE BEGIN USART1_IRQn 1 */ - - /* USER CODE END USART1_IRQn 1 */ -} - /** * @brief This function handles USART2 global interrupt. */ diff --git a/Core/Src/tim.c b/Core/Src/tim.c index f908f29..ec3e6eb 100644 --- a/Core/Src/tim.c +++ b/Core/Src/tim.c @@ -47,7 +47,7 @@ void MX_TIM2_Init(void) htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 72 - 1; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; + htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { Error_Handler(); diff --git a/Core/Src/usart.c b/Core/Src/usart.c index 4c4c945..d31b386 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -28,6 +28,35 @@ UART_HandleTypeDef huart1; UART_HandleTypeDef huart2; DMA_HandleTypeDef hdma_usart2_rx; +/* USART1 init function */ + +void MX_USART1_UART_Init(void) +{ + + /* USER CODE BEGIN USART1_Init 0 */ + + /* USER CODE END USART1_Init 0 */ + + /* USER CODE BEGIN USART1_Init 1 */ + + /* USER CODE END USART1_Init 1 */ + huart1.Instance = USART1; + huart1.Init.BaudRate = 115200; + huart1.Init.WordLength = UART_WORDLENGTH_8B; + huart1.Init.StopBits = UART_STOPBITS_1; + huart1.Init.Parity = UART_PARITY_NONE; + huart1.Init.Mode = UART_MODE_TX_RX; + huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart1.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN USART1_Init 2 */ + + /* USER CODE END USART1_Init 2 */ + +} /* USART2 init function */ void MX_USART2_UART_Init(void) @@ -56,70 +85,38 @@ void MX_USART2_UART_Init(void) /* USER CODE END USART2_Init 2 */ -} -/* USART2 init function */ - -void MX_USART2_UART_Init(void) -{ - - /* USER CODE BEGIN USART2_Init 0 */ - - /* USER CODE END USART2_Init 0 */ - - /* USER CODE BEGIN USART2_Init 1 */ - - /* USER CODE END USART2_Init 1 */ - huart2.Instance = USART2; - huart2.Init.BaudRate = 9600; - huart2.Init.WordLength = UART_WORDLENGTH_8B; - huart2.Init.StopBits = UART_STOPBITS_1; - huart2.Init.Parity = UART_PARITY_NONE; - huart2.Init.Mode = UART_MODE_TX_RX; - huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart2.Init.OverSampling = UART_OVERSAMPLING_16; - if (HAL_UART_Init(&huart2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USART2_Init 2 */ - - /* USER CODE END USART2_Init 2 */ - } void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==USART2) + if(uartHandle->Instance==USART1) { - /* USER CODE BEGIN USART2_MspInit 0 */ + /* USER CODE BEGIN USART1_MspInit 0 */ - /* USER CODE END USART2_MspInit 0 */ - /* USART2 clock enable */ - __HAL_RCC_USART2_CLK_ENABLE(); + /* USER CODE END USART1_MspInit 0 */ + /* USART1 clock enable */ + __HAL_RCC_USART1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USART2 GPIO Configuration - PA2 ------> USART2_TX - PA3 ------> USART2_RX + /**USART1 GPIO Configuration + PA9 ------> USART1_TX + PA10 ------> USART1_RX */ - GPIO_InitStruct.Pin = GPIO_PIN_2; + GPIO_InitStruct.Pin = GPIO_PIN_9; 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.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /* USART1 interrupt Init */ - HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspInit 1 */ - /* USER CODE END USART2_MspInit 1 */ + /* USER CODE END USART1_MspInit 1 */ } else if(uartHandle->Instance==USART2) { @@ -173,25 +170,23 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if(uartHandle->Instance==USART2) + if(uartHandle->Instance==USART1) { - /* USER CODE BEGIN USART2_MspDeInit 0 */ + /* USER CODE BEGIN USART1_MspDeInit 0 */ - /* USER CODE END USART2_MspDeInit 0 */ + /* USER CODE END USART1_MspDeInit 0 */ /* Peripheral clock disable */ - __HAL_RCC_USART2_CLK_DISABLE(); + __HAL_RCC_USART1_CLK_DISABLE(); - /**USART2 GPIO Configuration - PA2 ------> USART2_TX - PA3 ------> USART2_RX + /**USART1 GPIO Configuration + PA9 ------> USART1_TX + PA10 ------> USART1_RX */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); - /* USART1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(USART1_IRQn); /* USER CODE BEGIN USART1_MspDeInit 1 */ - /* USER CODE END USART2_MspDeInit 1 */ + /* USER CODE END USART1_MspDeInit 1 */ } else if(uartHandle->Instance==USART2) { diff --git a/Makefile b/Makefile index 7a96bf0..efa4cc4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [4.4.0-B60] date: [Sat Jul 13 14:09:19 CST 2024] +# File automatically-generated by tool: [projectgenerator] version: [4.4.0-B60] date: [Sat Jul 13 16:33:46 CST 2024] ########################################################################################################################## # ------------------------------------------------ @@ -40,6 +40,7 @@ Core/Src/main.c \ Core/Src/gpio.c \ Core/Src/i2c.c \ Core/Src/tim.c \ +Core/Src/dma.c \ Core/Src/usart.c \ Core/Src/stm32f1xx_it.c \ Core/Src/stm32f1xx_hal_msp.c \ @@ -63,7 +64,9 @@ Core/Src/sysmem.c \ Core/Src/hcsr04.c \ Core/Src/motor.c \ Core/Src/led.c \ -Core/Src/syscalls.c +Core/Src/syscalls.c \ +Core/Src/bluetooth.c \ +Core/Src/control.c # ASM sources ASM_SOURCES = \