…/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_rcc_ex.h(1271): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_rcc.h(3357): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_RCC_DeInit(void); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_rcc.h(3358): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_rcc.h(3359): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_gpio.h(301): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef GPIOx, uint16_t GPIO_Pin); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma.h(119): error: #20: identifier “HAL_LockTypeDef” is undefined HAL_LockTypeDef Lock; /!< DMA locking object */ …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma_ex.h(197): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator(DMA_HandleTypeDef *hdma, …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma_ex.h(199): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator(DMA_HandleTypeDef *hdma); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma_ex.h(200): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator(DMA_HandleTypeDef *hdma); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma_ex.h(204): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma.h(759): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma.h(760): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma.h(769): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma.h(770): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, …/Drivers/STM32G4xx_HAL_Driver/Inc/stm32g4xx_hal_dma.h(772): error: #20: identifier “HAL_StatusTypeDef” is undefined HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma);

时间: 2025-07-13 11:43:12 浏览: 9
<think>嗯,用户遇到了多个编译错误,都是关于HAL_StatusTypeDef和HAL_LockTypeDef未定义的。我需要先分析可能的原因。首先,这些类型通常在HAL的头文件中定义,比如stm32g4xx_hal_def.h。可能用户没有正确包含这个头文件,或者包含顺序有问题。 接下来,检查错误出现的文件,比如stm32g4xx_hal_rcc_ex.h和stm32g4xx_hal_rcc.h,这些文件应该会包含stm32g4xx_hal_def.h,但可能因为条件编译或者配置宏的问题导致没有正确引入。用户可能需要检查他们的项目配置,确保所有的HAL头文件路径正确,并且必要的宏定义如USE_HAL_DRIVER已经设置。 另外,用户可能在包含头文件时顺序不对,导致某些依赖没有被正确解析。例如,如果主头文件比如stm32g4xx_hal.h没有被包含,或者被包含在依赖它的文件之后,就会导致类型未定义的问题。 也有可能用户的HAL库版本不匹配,或者存在文件损坏。这时候需要重新下载或更新HAL库,确保文件完整性。 最后,用户需要检查代码中的包含语句是否正确,有没有拼写错误,或者路径是否正确。确保每个使用HAL_StatusTypeDef的地方都正确包含了相关的头文件。 总结起来,可能的解决步骤包括检查头文件包含顺序,确认宏定义是否正确,验证库文件完整性,以及检查项目配置。用户需要一步步排查这些可能性,找到具体原因并解决。</think>你在编译STM32G4系列HAL库时遇到的`HAL_StatusTypeDef`和`HAL_LockTypeDef`未定义错误,通常由以下原因导致。以下是分步排查指南: --- ### **1. 检查头文件包含顺序** #### 问题本质: - `HAL_StatusTypeDef`在`stm32g4xx_hal_def.h`中定义 - 错误提示中的`.h`文件(如`hal_rcc.h`)未正确包含基础定义文件 #### 修复步骤: 1. **确保主HAL头文件优先包含** 在`main.c`或工程入口文件中,头文件包含顺序应为: ```c #include "stm32g4xx_hal.h" // 必须最先包含 #include "stm32g4xx_hal_rcc.h" // 其他HAL模块头文件 #include "stm32g4xx_hal_gpio.h" ``` *因为`stm32g4xx_hal.h`会自动包含`stm32g4xx_hal_def.h`* 2. **验证头文件依赖** 检查报错的头文件(如`stm32g4xx_hal_rcc.h`)是否直接或间接包含`stm32g4xx_hal_def.h` --- ### **2. 检查预编译宏定义** #### 关键配置: - **必须定义宏`USE_HAL_DRIVER`** 此宏用于启用HAL库的完整定义,通常在工程配置中设置(如Keil的`Options for Target -> C/C++ -> Define`) #### 验证步骤: 1. 检查IDE/编译器的预定义宏列表 2. 确认包含路径已添加HAL库目录(如`Drivers/STM32G4xx_HAL_Driver/Inc`) --- ### **3. 排查库文件完整性** #### 可能问题: - HAL库文件损坏或版本不匹配(如使用了G4系列的库,但工程配置为其他系列) #### 解决方法: 1. 重新下载官方STM32CubeG4库 2. 使用CubeMX重新生成工程文件(推荐) 3. 检查`stm32g4xx_hal_def.h`文件是否存在且内容完整 --- ### **4. 检查硬件抽象层初始化** #### 代码示例: 在`main()`函数中确保HAL初始化已调用: ```c HAL_Init(); // 初始化HAL库基础组件 SystemClock_Config(); // 配置系统时钟(内部会调用RCC相关函数) ``` --- ### **5. 其他可能性** - **头文件重复包含**:使用`#pragma once`或`#ifndef HEADER_H`保护 - **C/C++混编问题**:如果使用C++编译器,需在包含HAL头文件时添加`extern "C"`包裹 ```cpp extern "C" { #include "stm32g4xx_hal.h" } ``` --- ### **错误示例分析** 以错误行`stm32g4xx_hal_rcc.h(3357)`为例: ```c HAL_StatusTypeDef HAL_RCC_DeInit(void); // 若未包含hal_def.h,HAL_StatusTypeDef无法解析 ``` *依赖链:`hal_rcc.h` → `hal_rcc_ex.h` → `hal_def.h`* --- ### **总结解决方案** 1. 确保`USE_HAL_DRIVER`宏已定义 2. 优先包含`stm32g4xx_hal.h` 3. 验证HAL库文件完整性 4. 通过CubeMX重新生成工程(可选) 完成上述步骤后,重新编译应能解决未定义类型错误。如果问题持续,请提供工程配置截图或编译环境详细信息。
阅读全文

相关推荐

==================[ 构建 | Project | Debug ]==================================== /Users/mac/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/bin/cmake --build /Users/mac/Desktop/Project/cmake-build-debug --target Project -j 6 [1/1] Linking C executable Project.elf FAILED: Project.elf : && /opt/homebrew/bin/arm-none-eabi-gcc -mcpu=cortex-m3 -Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections -O0 -g3 -mcpu=cortex-m3 -T "/Users/mac/Desktop/Project/STM32F103XX_FLASH.ld" --specs=nano.specs -Wl,-Map=Project.map -Wl,--gc-sections -Wl,--start-group -lc -lm -Wl,--end-group -Wl,--print-memory-usage cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Core/Src/system_stm32f1xx.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc_ex.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c.obj cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c.obj CMakeFiles/Project.dir/Core/Src/main.c.obj CMakeFiles/Project.dir/Core/Src/gpio.c.obj CMakeFiles/Project.dir/Core/Src/rtc.c.obj CMakeFiles/Project.dir/Core/Src/stm32f1xx_it.c.obj CMakeFiles/Project.dir/Core/Src/stm32f1xx_hal_msp.c.obj CMakeFiles/Project.dir/Core/Src/sysmem.c.obj CMakeFiles/Project.dir/Core/Src/syscalls.c.obj CMakeFiles/Project.dir/startup_stm32f103xe.s.obj -o Project.elf && : /Applications/ArmGNUToolchain/14.2.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/14.2.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/Project.dir/Core/Src/gpio.c.obj: in function MX_GPIO_Init': /Users/mac/Desktop/Project/Core/Src/gpio.c:45: multiple definition of MX_GPIO_Init'; CMakeFiles/Project.dir/Core/Src/main.c.obj:/Users/mac/Desktop/Project/Core/Src/main.c:185: first defined here /Applications/ArmGNUToolchain/14.2.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/14.2.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/Project.dir/Core/Src/main.c.obj: in function MX_TIM2_Init': /Users/mac/Desktop/Project/Core/Src/main.c:181:(.text.MX_TIM2_Init+0x28): undefined reference to HAL_TIM_Base_Init' Memory region Used Size Region Size %age Used RAM: 1672 B 64 KB 2.55% FLASH: 6556 B 512 KB 1.25% collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed.

[1/1] Linking C executable XSSS.elf FAILED: XSSS.elf : && /opt/homebrew/bin/arm-none-eabi-gcc -g -Wl,-gc-sections,--print-memory-usage,-Map=/Users/mac/Desktop/NewFolder/XSSS/cmake-build-debug/XSSS.map -mcpu=cortex-m3 -mthumb -mthumb-interwork -T /Users/mac/Desktop/NewFolder/XSSS/STM32F103VETX_FLASH.ld CMakeFiles/XSSS.elf.dir/Core/Src/gpio.c.obj CMakeFiles/XSSS.elf.dir/Core/Src/lcd1602.c.obj CMakeFiles/XSSS.elf.dir/Core/Src/main.c.obj CMakeFiles/XSSS.elf.dir/Core/Src/stm32f1xx_hal_msp.c.obj CMakeFiles/XSSS.elf.dir/Core/Src/stm32f1xx_it.c.obj CMakeFiles/XSSS.elf.dir/Core/Src/syscalls.c.obj CMakeFiles/XSSS.elf.dir/Core/Src/sysmem.c.obj CMakeFiles/XSSS.elf.dir/Core/Src/system_stm32f1xx.c.obj CMakeFiles/XSSS.elf.dir/Core/Startup/startup_stm32f103vetx.s.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c.obj CMakeFiles/XSSS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c.obj -o XSSS.elf && cd /Users/mac/Desktop/NewFolder/XSSS/cmake-build-debug && arm-none-eabi-objcopy -Oihex /Users/mac/Desktop/NewFolder/XSSS/cmake-build-debug/XSSS.elf /Users/mac/Desktop/NewFolder/XSSS/cmake-build-debug/XSSS.hex && arm-none-eabi-objcopy -Obinary /Users/mac/Desktop/NewFolder/XSSS/cmake-build-debug/XSSS.elf /Users/mac/Desktop/NewFolder/XSSS/cmake-build-debug/XSSS.bin /Applications/ArmGNUToolchain/14.2.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/14.2.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/XSSS.elf.dir/Core/Src/main.c.obj: in function main': /Users/mac/Desktop/NewFolder/XSSS/Core/Src/main.c:92:(.text.main+0x1c): undefined reference to LCD_SetCursor'

====================[ 构建 | XXS.elf | Debug ]==================================== /Users/mac/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/bin/cmake --build /Users/mac/Desktop/NewFolder/XXS_副本/cmake-build-debug --target XXS.elf -- -j 6 [ 14%] Building C object CMakeFiles/XXS.elf.dir/Core/Src/syscalls.c.obj [ 14%] Building C object CMakeFiles/XXS.elf.dir/Core/Src/main.c.obj [ 14%] Building C object CMakeFiles/XXS.elf.dir/Core/Src/LCD1602.c.obj [ 19%] Building C object CMakeFiles/XXS.elf.dir/Core/Src/stm32f1xx_hal_msp.c.obj [ 23%] Building C object CMakeFiles/XXS.elf.dir/Core/Src/gpio.c.obj [ 28%] Building C object CMakeFiles/XXS.elf.dir/Core/Src/stm32f1xx_it.c.obj [ 33%] Building C object CMakeFiles/XXS.elf.dir/Core/Src/sysmem.c.obj [ 38%] Building ASM object CMakeFiles/XXS.elf.dir/Core/Startup/startup_stm32f103vetx.s.obj [ 47%] Building C object CMakeFiles/XXS.elf.dir/Core/Src/system_stm32f1xx.c.obj [ 47%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c.obj [ 52%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj [ 57%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c.obj [ 61%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c.obj [ 66%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c.obj [ 71%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c.obj [ 76%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c.obj [ 80%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c.obj [ 85%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj [ 90%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c.obj [ 95%] Building C object CMakeFiles/XXS.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c.obj [100%] Linking C executable XXS.elf /Applications/ArmGNUToolchain/14.2.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/14.2.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/XXS.elf.dir/Core/Src/main.c.obj: in function main': /Users/mac/Desktop/NewFolder/XXS_副本/Core/Src/main.c:94:(.text.main+0x1c): undefined reference to LCD_Clear' /Applications/ArmGNUToolchain/14.2.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/14.2.1/../../../../arm-none-eabi/bin/ld: /Users/mac/Desktop/NewFolder/XXS_副本/Core/Src/main.c:99:(.text.main+0x2e): undefined reference to LCD_WriteString' /Applications/ArmGNUToolchain/14.2.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/14.2.1/../../../../arm-none-eabi/bin/ld: /Users/mac/Desktop/NewFolder/XXS_副本/Core/Src/main.c:102:(.text.main+0x42): undefined reference to LCD_WriteString' Memory region Used Size Region Size %age Used RAM: 1992 B 64 KB 3.04% FLASH: 4508 B 512 KB 0.86% collect2: error: ld returned 1 exit status make[3]: *** [XXS.elf] Error 1 make[2]: *** [CMakeFiles/XXS.elf.dir/all] Error 2 make[1]: *** [CMakeFiles/XXS.elf.dir/rule] Error 2 make: *** [XXS.elf] Error 2

/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ RGBColor ledStrip[4][LED_PER_CHAIN]; /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 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}; /** 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; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* 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 */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #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 */ /* 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 */ } #endif /* USE_FULL_ASSERT */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.h * @brief : Header for main.c file. * This file contains the common defines of the application. ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_hal.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ /* USER CODE BEGIN ET */ /* USER CODE END ET */ /* Exported constants --------------------------------------------------------*/ /* USER CODE BEGIN EC */ /* USER CODE END EC */ /* Exported macro ------------------------------------------------------------*/ /* USER CODE BEGIN EM */ /* USER CODE END EM */ /* Exported functions prototypes ---------------------------------------------*/ void Error_Handler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ #ifdef __cplusplus } #endif #endif /* __MAIN_H */ #ifndef WS2812_H#include "ws2812.h" #include "math.h" // 亮度调整参数 static uint8_t global_brightness = 100; // 亮度因子 static float brightness_factor = 1.0f; // 占空比定义 (72MHz时钟@ARR=71) #define PWM_HIGH 50 // 0.7µs高电平 #define PWM_LOW 25 // 0.35µs高电平 #define PWM_RESET 0 // 复位电平 // PWM数据缓冲区(按通道分组) static uint16_t pwmData[4][PWM_BUFFER_SIZE]; // Timer和DMA句柄 static TIM_HandleTypeDef* htim; static DMA_HandleTypeDef* hdma; static volatile uint8_t dma_busy = 0; // 通道配置 const WS2812_Channel channels[4] = { {NULL, TIM_CHANNEL_1, GPIO_PIN_0, GPIOA}, // PA0 {NULL, TIM_CHANNEL_2, GPIO_PIN_1, GPIOA}, // PA1 {NULL, TIM_CHANNEL_3, GPIO_PIN_2, GPIOA}, // PA2 {NULL, TIM_CHANNEL_4, GPIO_PIN_3, GPIOA} // PA3 }; // 初始化WS2812控制器 void WS2812_Init(TIM_HandleTypeDef* htim, DMA_HandleTypeDef* hdma) { htim = htim; hdma = hdma; // 设置所有通道初始状态 for (int i = 0; i < 4; i++) { HAL_GPIO_WritePin(channels[i].port, channels[i].pin, GPIO_PIN_RESET); } // 清除DMA状态 dma_busy = 0; } // 设置LED颜色(带亮度调整) void WS2812_SetColor(uint8_t ch, uint16_t index, RGBColor color) { if (ch >= 4 || index >= LED_PER_CHAIN) return; // 应用全局亮度 RGBColor adjColor = { .r = (uint8_t)(color.r * brightness_factor), .g = (uint8_t)(color.g * brightness_factor), .b = (uint8_t)(color.b * brightness_factor) }; // 转换为GRB格式 uint32_t grb = ((adjColor.g << 16) | (adjColor.r << 8) | adjColor.b); uint16_t* buf = pwmData[ch] + index * BIT_PER_LED; // 生成波形数据(高位先出) for(int i = 0; i < BIT_PER_LED; i++) { buf[i] = (grb & 0x800000) ? PWM_HIGH : PWM_LOW; grb <<= 1; } } // 设置全局亮度 (0-100) void WS2812_SetBrightness(uint8_t brightness) { if (brightness > 100) brightness = 100; global_brightness = brightness; // 亮度调整公式: // $$ \text{brightness_factor} = \sqrt{\frac{\text{brightness}}{100}} $$ brightness_factor = sqrtf((float)brightness / 100.0f); } // 启动DMA传输 void WS2812_StartDMATransfer(void) { // 配置DMA传输(TIM2_CCR寄存器连续地址) HAL_DMA_Start_IT( hdma, (uint32_t)&pwmData[0][0], (uint32_t)&htim->Instance->CCR1, DMA_TRANSFER_SIZE ); // 启用DMA请求 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1 | TIM_DMA_CC2 | TIM_DMA_CC3 | TIM_DMA_CC4); __HAL_TIM_ENABLE(htim); dma_busy = 1; } // 更新LED显示 void WS2812_Update(void) { if (dma_busy) return; WS2812_StartDMATransfer(); } // 检查是否忙状态 uint8_t WS2812_IsBusy(void) { return dma_busy; } // DMA传输完成回调 void WS2812_DMACompleteCallback(void) { // 关闭定时器和DMA __HAL_TIM_DISABLE(htim); __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1 | TIM_DMA_CC2 | TIM_DMA_CC3 | TIM_DMA_CC4); // 所有引脚置低电平(产生复位信号) for (int i = 0; i < 4; i++) { HAL_GPIO_WritePin(channels[i].port, channels[i].pin, GPIO_PIN_RESET); } dma_busy = 0; } 22:42:50 **** 项目dengguang配置Debug的增量构建 **** make -j16 all arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.o" arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.o" arm-none-eabi-gcc "../Core/Src/gpio.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/gpio.d" -MT"Core/Src/gpio.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/gpio.o" arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/main.o" arm-none-eabi-gcc "../Core/Src/stm32f1xx_hal_msp.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/stm32f1xx_hal_msp.d" -MT"Core/Src/stm32f1xx_hal_msp.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/stm32f1xx_hal_msp.o" arm-none-eabi-gcc "../Core/Src/stm32f1xx_it.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/stm32f1xx_it.d" -MT"Core/Src/stm32f1xx_it.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/stm32f1xx_it.o" arm-none-eabi-gcc "../Core/Src/syscalls.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/syscalls.d" -MT"Core/Src/syscalls.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/syscalls.o" ../Core/Src/main.c:25:1: error: unknown type name 'RGBColor' 25 | RGBColor ledStrip[4][LED_PER_CHAIN]; | ^~~~~~~~ ../Core/Src/main.c:25:22: error: 'LED_PER_CHAIN' undeclared here (not in a function) 25 | RGBColor ledStrip[4][LED_PER_CHAIN]; | ^~~~~~~~~~~~~ make: *** [Core/Src/subdir.mk:40: Core/Src/main.o] Error 1 make: *** Waiting for unfinished jobs.... "make -j16 all"以退出代码2结尾。构建可能不完整。 22:42:51 构建失败。 4 错误,0 警告。 (使用1s.155ms) #define WS2812_H #include "stm32f1xx_hal.h" // 每路LED数量(根据内存调整) #define LED_PER_CHAIN 30 // 每LED数据位数 (24位GRB) #define BIT_PER_LED 24 // PWM缓冲大小 #define PWM_BUFFER_SIZE (LED_PER_CHAIN * BIT_PER_LED) // 单个通道数据总数 #define DMA_TRANSFER_SIZE (PWM_BUFFER_SIZE * 4) // 4通道共享同一DMA请求 // LED颜色结构 typedef struct { uint8_t r; uint8_t g; uint8_t b; } RGBColor; // 通道配置结构 typedef struct { TIM_HandleTypeDef* timer; uint32_t channel; uint16_t pin; GPIO_TypeDef* port; } WS2812_Channel; // 初始化函数 void WS2812_Init(TIM_HandleTypeDef* htim, DMA_HandleTypeDef* hdma); // 设置LED颜色 void WS2812_SetColor(uint8_t ch, uint16_t index, RGBColor color); // 设置全局亮度 (0-100) void WS2812_SetBrightness(uint8_t brightness); // 更新LED显示 void WS2812_Update(void); // 复位完成标志 uint8_t WS2812_IsBusy(void); // DMA传输完成回调 void WS2812_DMACompleteCallback(void); #endif

Build started: Project: atk_f407 *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'E:\ARM\ARMCC\Bin' Build target 'OLEO' assembling startup_stm32f407xx.s... compiling sys.c... compiling stm32f4xx_hal_usart.c... compiling delay.c... compiling stm32f4xx_hal_adc.c... "no source": Error: #5: cannot open source input file "H:\xxx\4锛岀▼搴忔簮鐮乗2锛屾爣鍑嗕緥绋?HAL搴撶増鏈琝2锛屾爣鍑嗕緥绋?HAL搴撶増鏈琝瀹為獙12 OLED鏄剧ず瀹為獙\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc.c": No such file or directory H:\xxx\4,程序源码\2,标准例程-HAL库版本\2,标准例程-HAL库版本\实验12 OLED显示实验\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc.c: 0 warnings, 1 error compiling stm32f4xx_hal_tim.c... "no source": Error: #5: cannot open source input file "H:\xxx\4锛岀▼搴忔簮鐮乗2锛屾爣鍑嗕緥绋?HAL搴撶増鏈琝2锛屾爣鍑嗕緥绋?HAL搴撶増鏈琝瀹為獙12 OLED鏄剧ず瀹為獙\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c": No such file or directory H:\xxx\4,程序源码\2,标准例程-HAL库版本\2,标准例程-HAL库版本\实验12 OLED显示实验\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c: 0 warnings, 1 error compiling stm32f4xx_hal_tim_ex.c... "no source": Error: #5: cannot open source input file "H:\xxx\4锛岀▼搴忔簮鐮乗2锛屾爣鍑嗕緥绋?HAL搴撶増鏈琝2锛屾爣鍑嗕緥绋?HAL搴撶増鏈琝瀹為獙12 OLED鏄剧ず瀹為獙\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c": No such file or directory H:\xxx\4,程序源码\2,标准例程-HAL库版本\2,标准例程-HAL库版本\实验12 OLED显示实验\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c: 0 warnings, 1 error compiling stm32f4xx_hal_adc_ex.c... "no source": Error: #5: cannot open source input file "H:\xxx\4锛岀▼搴忔簮鐮乗2锛屾爣鍑嗕緥绋?HAL搴撶増鏈琝2锛屾爣鍑嗕緥绋?HAL搴撶増鏈琝瀹為獙12 OLED鏄剧ず瀹為獙\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc_ex.c": No such file or directory H:\xxx\4,程序源码\2,标准例程-HAL库版本\2,标准例程-HAL库版本\实验12 OLED显示实验\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc_ex.c: 0 warnings, 1 error compiling usart.c... compiling stm32f4xx_hal_rcc.c... compiling main.c... ..\..\User\main.c(31): warning: #177-D: variable "t" was declared but never referenced uint8_t t = 0; ..\..\User\main.c(35): warning: #177-D: variable "temp" was declared but never referenc

====================[ 构建 | DEMO.elf | Debug ]=================================== /Users/mac/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/bin/cmake --build /Users/mac/Desktop/NewFolder/DEMO/cmake-build-debug --target DEMO.elf -- -j 6 [ 8%] Building C object CMakeFiles/DEMO.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj [ 13%] Building C object CMakeFiles/DEMO.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c.obj [ 8%] Building C object CMakeFiles/DEMO.elf.dir/Core/Src/main.c.obj [ 21%] Building C object CMakeFiles/DEMO.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c.obj [ 21%] Building C object CMakeFiles/DEMO.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c.obj [ 26%] Building C object CMakeFiles/DEMO.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c.obj /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:99:3: error: redeclaration of enumerator 'IDLE' 99 | IDLE, | ^~~~ In file included from /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:20: /Users/mac/Desktop/NewFolder/DEMO/Core/Inc/main.h:35:5: note: previous definition of 'IDLE' with type 'enum <anonymous>' 35 | IDLE, | ^~~~ /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:100:3: error: redeclaration of enumerator 'DELAY_3S' 100 | DELAY_3S, | ^~~~~~~~ /Users/mac/Desktop/NewFolder/DEMO/Core/Inc/main.h:36:5: note: previous definition of 'DELAY_3S' with type 'enum <anonymous>' 36 | DELAY_3S, | ^~~~~~~~ /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:101:3: error: redeclaration of enumerator 'DELAY_20MS' 101 | DELAY_20MS, | ^~~~~~~~~~ /Users/mac/Desktop/NewFolder/DEMO/Core/Inc/main.h:37:5: note: previous definition of 'DELAY_20MS' with type 'enum <anonymous>' 37 | DELAY_20MS, | ^~~~~~~~~~ /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:103:3: error: conflicting types for 'KeyState'; have 'enum <anonymous>' 103 | } KeyState; | ^~~~~~~~ /Users/mac/Desktop/NewFolder/DEMO/Core/Inc/main.h:39:5: note: previous declaration of 'KeyState' with type 'KeyState' 39 | } KeyState; | ^~~~~~~~ /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c: In function 'ProcessKeyState': /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:167:25: error: 'DELAY_DH' undeclared (first use in this function); did you mean 'DELAY_3S'? 167 | keyCtrl.state = DELAY_DH; | ^~~~~~~~ | DELAY_3S /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:167:25: note: each undeclared identifier is reported only once for each function it appears in /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:175:25: error: 'TURN_OFF' undeclared (first use in this function) 175 | keyCtrl.state = TURN_OFF; | ^~~~~~~~ /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:187:10: error: 'MEASURE_IN1' undeclared (first use in this function) 187 | case MEASURE_IN1: | ^~~~~~~~~~~ [ 30%] Building C object CMakeFiles/DEMO.elf.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c.obj /Users/mac/Desktop/NewFolder/DEMO/Core/Src/main.c:190:25: error: 'MEASURE_IN2' undeclared (first use in this function) 190 | keyCtrl.state = MEASURE_IN2; | ^~~~~~~~~~~ make[3]: *** [CMakeFiles/DEMO.elf.dir/Core/Src/main.c.obj] Error 1 make[3]: *** Waiting for unfinished jobs.... make[2]: *** [CMakeFiles/DEMO.elf.dir/all] Error 2 make[1]: *** [CMakeFiles/DEMO.elf.dir/rule] Error 2 make: *** [DEMO.elf] Error 2

10:45:52 **** Incremental Build of configuration Debug for project test1 **** make -j12 all arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/main.o" arm-none-eabi-gcc "../Core/Src/n3310.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F103xB -c -I../Core/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/n3310.d" -MT"Core/Src/n3310.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/n3310.o" ../Core/Src/n3310.c: In function 'LcdInit': ../Core/Src/n3310.c:25:27: error: 'GPIO_InitTypeDef' has no member named 'GPIO_Pin' 25 | GPIO_InitStructure.GPIO_Pin = (LCD_DC_PIN | LCD_CE_PIN | LCD_RST_PIN | LCD_SDIN_PIN | LCD_SCLK_PIN); | ^ ../Core/Src/n3310.c:26:27: error: 'GPIO_InitTypeDef' has no member named 'GPIO_Mode' 26 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | ^ ../Core/Src/main.c: In function 'main': ../Core/Src/main.c:106:9: warning: implicit declaration of function 'GPIO_PinRemapConfig' [-Wimplicit-function-declaration] 106 | GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); | ^~~~~~~~~~~~~~~~~~~ ../Core/Src/n3310.c:26:40: error: 'GPIO_Mode_Out_PP' undeclared (first use in this function); did you mean 'GPIO_MODE_AF_PP'? 26 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "dev_Encoder.h" #include "hal_InterruptCF.h" #include "OLED.h" #include "dev_Motor.h" #include "srv_PID.h" #include "app_Synthetical.h" #include "dev_LimitSwitch.h" #include "dev_LMP_Gray.h" #include "dev_Serial.h" #include "srv_LMP_FA.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_TIM5_Init(); MX_TIM6_Init(); MX_TIM8_Init(); MX_USART1_UART_Init(); MX_UART4_Init(); MX_TIM9_Init(); MX_TIM10_Init(); MX_TIM12_Init(); /* USER CODE BEGIN 2 */ Encoder_Init(); InterruptCF_Init(); OLED_Init(); Motor_Init(); PID_System_Init(); // 系统初始化 Serial_Periph_Init(); LMP_FA_Gray_Init(); OLED_Init(); HAL_Delay(2000);//延迟2s启动 /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { int8_t i; i = 2; HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_15);//程序指示灯 // OLED_Printf(64,1,OLED_6X8,"TIP:%d",TIP); //显示任务标识 // LMP_Display(2); //显示巡线滤波数据 OLED_Update(); OLED_Clear(); /*************************测试区************************** */ if (i == 1) { HAL_Delay(10); // EMC_X1_StraightLine(500); // LMP_Display(2); // LMP_Display(4); // EMC_X1_StraightLine(500); // MyPID_Tick(500.0f, 500.0f, 500.0f, 500.0f); // PID_Debug_Display(39); EMC_X1_StraightLine(500); } /*************************流程区************************** */ if (i == 2) { if (TIP == 1) // 任务1开始 { Synthetical_Task_1(); } else if (TIP == 2) // 任务2开始 { Synthetical_Task_2(); } else if (TIP == 3) // 任务3开始 { Synthetical_Task_3(); } else if (TIP == 4) // 任务4开始 { Synthetical_Task_4(); } else if (TIP == 5) // 任务5开始 { Synthetical_Task_5(); } else if (TIP == 6) // 任务6开始 { Synthetical_Task_6(); } } /* USER CODE END WHILE */ /* USER CODE BEGIN 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}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 168; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; 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_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* 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 */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #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 */ /* 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 */ } #endif /* USE_FULL_ASSERT */

/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2023 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stdio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ UART_HandleTypeDef huart1; TIM_HandleTypeDef htim6; /* USER CODE BEGIN PV */ volatile uint8_t received_data = 0; volatile uint8_t data_ready = 0; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART1_UART_Init(void); static void MX_TIM6_Init(void); /* USER CODE BEGIN PFP */ void process_received_data(uint8_t data) { // ����LED��ʾ���� HAL_GPIO_WritePin(GPIOF, GPIO_PIN_0, (data & 0x01) ? GPIO_PIN_SET : GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, (data & 0x02) ? GPIO_PIN_SET : GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_2, (data & 0x04) ? GPIO_PIN_SET : GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_3, (data & 0x08) ? GPIO_PIN_SET : GPIO_PIN_RESET); printf("[Receiver] �յ�����: %d (0x%X)\r\n", data, data); } /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /*to redirect printf to uart with semihosting.*/ int _write(int fd, char* ptr, int len) { HAL_UART_Transmit(&huart1, (uint8_t *) ptr, len, HAL_MAX_DELAY); return len; } /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); MX_TIM6_Init(); /* USER CODE BEGIN 2 */ printf("ReceiveReady\r\n"); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { if(data_ready) { process_received_data(received_data); data_ready = 0; } HAL_Delay(10); // ����CPUռ���� } /* USER CODE END WHILE */ /* USER CODE BEGIN 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}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** 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.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; 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_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { Error_Handler(); } } /** * @brief TIM6 Initialization Function * @param None * @retval None */ static void MX_TIM6_Init(void) { /* USER CODE BEGIN TIM6_Init 0 */ /* USER CODE END TIM6_Init 0 */ TIM_MasterConfigTypeDef sMasterConfig = {0}; /* USER CODE BEGIN TIM6_Init 1 */ /* USER CODE END TIM6_Init 1 */ htim6.Instance = TIM6; htim6.Init.Prescaler = 16 * 168 * 2 - 1; htim6.Init.CounterMode = TIM_COUNTERMODE_UP; htim6.Init.Period = 65535; htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim6) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM6_Init 2 */ /* USER CODE END TIM6_Init 2 */ } /** * @brief USART1 Initialization Function * @param None * @retval None */ static 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 */ } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_Initure; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); /*Configure GPIO pins output : PF0123 8 12(�ж�) 11(������)*/ GPIO_Initure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP; GPIO_Initure.Pull = GPIO_NOPULL; GPIO_Initure.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOF, &GPIO_Initure); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_8, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET); /*Configure GPIO pins : PC01234567 8 all sw */ GPIO_Initure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; /* all sw */ GPIO_Initure.Mode = GPIO_MODE_INPUT; GPIO_Initure.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_Initure); /*Configure GPIO pin : PC11����ͨ������ */ GPIO_Initure.Pin = GPIO_PIN_8 | GPIO_PIN_11; /* key1_n && key2_n*/ GPIO_Initure.Mode = GPIO_MODE_IT_RISING; GPIO_Initure.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_Initure); HAL_NVIC_SetPriority(EXTI9_5_IRQn, 4, 0); HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0); HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); } /* USER CODE BEGIN 4 */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == GPIO_PIN_12) { // �ж����� // ��PC0-PC3��ȡ���� received_data = 0; received_data |= HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_0) ? 0x01 : 0x00; received_data |= HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_1) ? 0x02 : 0x00; received_data |= HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_2) ? 0x04 : 0x00; received_data |= HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_3) ? 0x08 : 0x00; data_ready = 1; } } /* 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 */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #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 */ /* 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 */ } #endif /* USE_FULL_ASSERT */ 编译失败

/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2022 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** ****************************************************************************** * 作者:好家伙VCC * 联系方式:[email protected] * 软件版本:V3.3.0 * 使用硬件版本:V3.3.0 * ****************************************************************************** * 更新日志: * * * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "adc.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "oled.h" #include "stdio.h" #include "motor.h" #include "niming.h" #include "pid.h" #include "cJSON.h" #include <string.h> #include "HC_SR04.h" #include "mpu6050.h" #include "inv_mpu.h" #include "inv_mpu_dmp_motion_driver.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ extern float Motor1Speed ;//声明电机1速度 extern float Motor2Speed ;//声明电机2速度 extern tPid pidMotor1Speed;//声明电机1PID速度控制结构体类型变量 extern tPid pidMotor2Speed; extern tPid pidFollow; //定距离跟随PID extern tPid pidMPU6050YawMovement; //利用6050偏航角 进行姿态控制的PID extern uint8_t Usart1_ReadBuf[255]; //串口1 缓冲数组 float p,i,d,a,b;//使用JSON时候使用的变量 uint8_t OledString[50];//OLED显示使用的字符串数组 extern float Mileage;//里程数 extern tPid pidHW_Tracking;//红外循迹的PID uint8_t g_ucaHW_Read[4] = {0};//保存红外对管电平的数组 int8_t g_cThisState = 0;//这次状态 int8_t g_cLastState = 0; //上次状态 float g_fHW_PID_Out;//红外对管PID计算输出速度 float g_fHW_PID_Out1;//电机1的最后循迹PID控制速度 float g_fHW_PID_Out2;//电机2的最后循迹PID控制速度 uint8_t g_ucUsart3ReceiveData; //保存串口三接收的数据 uint8_t Usart3String[50];//串口三输出字符串使用的字符串数组 float g_fHC_SR04_Read;//超声波传感器读取障碍物数据 float g_fFollow_PID_Out;//定距离跟随PID计算输出速度 float pitch,roll,yaw; //俯仰角 横滚角 航向角 float g_fMPU6050YawMovePidOut = 0.00f; //姿态PID运算输出 float g_fMPU6050YawMovePidOut1 = 0.00f; //第一个电机控制输出 float g_fMPU6050YawMovePidOut2 = 0.00f; //第一个电机控制输出 uint8_t g_ucMode = 0; //小车运动模式标志位 0:显示功能、1:PID循迹模式、2:手机遥控普通运动模式、3.超声波避障模式、4:PID跟随模式、5:遥控角度闭环 /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM4_Init(); MX_ADC2_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ OLED_Init(); //初始化OLED OLED_Clear() ; HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);//开启定时器1 通道1 PWM输出 HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_4);//开启定时器1 通道4 PWM输出 HAL_TIM_Encoder_Start(&htim2,TIM_CHANNEL_ALL);//开启定时器2 HAL_TIM_Encoder_Start(&htim4,TIM_CHANNEL_ALL);//开启定时器4 HAL_TIM_Base_Start_IT(&htim2); //开启定时器2 中断 HAL_TIM_Base_Start_IT(&htim4); //开启定时器4 中断 HAL_TIM_Base_Start_IT(&htim1); //开启定时器1 中断 __HAL_UART_ENABLE_IT(&huart1,UART_IT_RXNE); //开启串口1接收中断 PID_init();//PID参数初始化 HAL_UART_Receive_IT(&huart3,&g_ucUsart3ReceiveData,1); //串口三接收数据 HAL_Delay(500);//延时0.5秒 6050上电稳定后初始化 MPU_Init(); //初始化MPU6050 while(MPU_Init()!=0);//初始化MPU6050模块的MPU 注意初始化阶段不要移动小车 while(mpu_dmp_init()!=0);//mpu6050,dmp初始化 // cJSON *cJsonData ,*cJsonVlaue; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ sprintf((char *)OledString," g_ucMode:%d",g_ucMode);//显示g_ucMode 当前模式 OLED_ShowString(0,6,OledString,12); //显示在OLED上 sprintf((char *)Usart3String," g_ucMode:%d",g_ucMode);//蓝牙APP显示 HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 if(g_ucMode == 0) { //0LED显示功能 sprintf((char*)OledString, "V1:%.2fV2:%.2f", Motor1Speed,Motor2Speed);//显示速度 OLED_ShowString(0,0,OledString,12);//这个是oled驱动里面的,是显示位置的一个函数, sprintf((char*)OledString, "Mileage:%.2f", Mileage);//显示里程 OLED_ShowString(0,1,OledString,12);//这个是oled驱动里面的,是显示位置的一个函数, sprintf((char*)OledString, "U:%.2fV", adcGetBatteryVoltage());//显示电池电压 OLED_ShowString(0,2,OledString,12);//这个是oled驱动里面的,是显示位置的一个函数, sprintf((char *)OledString,"HC_SR04:%.2fcm\r\n",HC_SR04_Read());//显示超声波数据 OLED_ShowString(0,3,OledString,12);//这个是oled驱动里面的,是显示位置的一个函数, sprintf((char *)OledString,"p:%.2f r:%.2f \r\n",pitch,roll);//显示6050数据 俯仰角 横滚角 OLED_ShowString(0,4,OledString,12);//这个是oled驱动里面的,是显示位置的一个函数, sprintf((char *)OledString,"y:%.2f \r\n",yaw);//显示6050数据 航向角 OLED_ShowString(0,5,OledString,12);//这个是oled驱动里面的,是显示位置的一个函数, //蓝牙APP显示 sprintf((char*)Usart3String, "V1:%.2fV2:%.2f", Motor1Speed,Motor2Speed);//显示速度 HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 //阻塞方式发送可以保证数据发送完毕,中断发送不一定可以保证数据已经发送完毕才启动下一次发送 sprintf((char*)Usart3String, "Mileage:%.2f", Mileage);//显示里程 HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 sprintf((char*)Usart3String, "U:%.2fV", adcGetBatteryVoltage());//显示电池电压 HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 sprintf((char *)Usart3String,"HC_SR04:%.2fcm\r\n",HC_SR04_Read());//显示超声波数据 HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 sprintf((char *)Usart3String,"p:%.2f r:%.2f \r\n",pitch,roll);//显示6050数据 俯仰角 横滚角 HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 sprintf((char *)Usart3String,"y:%.2f \r\n",yaw);//显示6050数据 航向角 HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 //获得6050数据 while(mpu_dmp_get_data(&pitch,&roll,&yaw)!=0){} //这个可以解决经常读不出数据的问题 //在显示模式电机停转 设置小车速度为0 motorPidSetSpeed(0,0); } if(g_ucMode == 1) { ///**** 红外PID循迹功能******************/ g_ucaHW_Read[0] = READ_HW_OUT_1;//读取红外对管状态、这样相比于写在if里面更高效 g_ucaHW_Read[1] = READ_HW_OUT_2; g_ucaHW_Read[2] = READ_HW_OUT_3; g_ucaHW_Read[3] = READ_HW_OUT_4; if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 0 ) { // printf("应该前进\r\n");//注释掉更加高效,减少无必要程序执行 g_cThisState = 0;//前进 } else if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 1&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 0 )//使用else if更加合理高效 { // printf("应该右转\r\n"); g_cThisState = -1;//应该右转 } else if(g_ucaHW_Read[0] == 1&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 0 ) { // printf("快速右转\r\n"); g_cThisState = -2;//快速右转 } else if(g_ucaHW_Read[0] == 1&&g_ucaHW_Read[1] == 1&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 0) { // printf("快速右转\r\n"); g_cThisState = -3;//快速右转 } else if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 1&&g_ucaHW_Read[3] == 0 ) { // printf("应该左转\r\n"); g_cThisState = 1;//应该左转 } else if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 1 ) { // printf("快速左转\r\n"); g_cThisState = 2;//快速左转 } else if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 1&&g_ucaHW_Read[3] == 1) { // printf("快速左转\r\n"); g_cThisState = 3;//快速左转 } g_fHW_PID_Out = PID_realize(&pidHW_Tracking,g_cThisState);//PID计算输出目标速度 这个速度,会和基础速度加减 g_fHW_PID_Out1 = 3 + g_fHW_PID_Out;//电机1速度=基础速度+循迹PID输出速度 g_fHW_PID_Out2 = 3 - g_fHW_PID_Out;//电机1速度=基础速度-循迹PID输出速度 if(g_fHW_PID_Out1 >5) g_fHW_PID_Out1 =5;//进行限幅 限幅速度在0-5之间 if(g_fHW_PID_Out1 <0) g_fHW_PID_Out1 =0; if(g_fHW_PID_Out2 >5) g_fHW_PID_Out2 =5;//进行限幅 限幅速度在0-5之间 if(g_fHW_PID_Out2 <0) g_fHW_PID_Out2 =0; if(g_cThisState != g_cLastState)//如何这次状态不等于上次状态、就进行改变目标速度和控制电机、在定时器中依旧定时控制电机 { motorPidSetSpeed(g_fHW_PID_Out1,g_fHW_PID_Out2);//通过计算的速度控制电机 } g_cLastState = g_cThisState;//保存上次红外对管状态 } if(g_ucMode == 2) { //***************遥控模式***********************// //遥控模式的控制在串口三的中断里面 } if(g_ucMode == 3) { //******超声波避障模式*********************// ////避障逻辑 if(HC_SR04_Read() > 25)//前方无障碍物 { motorPidSetSpeed(1,1);//前运动 HAL_Delay(100); } else{ //前方有障碍物 motorPidSetSpeed(-1,1);//右边运动 原地 HAL_Delay(500); if(HC_SR04_Read() > 25)//右边无障碍物 { motorPidSetSpeed(1,1);//前运动 HAL_Delay(100); } else{//右边有障碍物 motorPidSetSpeed(1,-1);//左边运动 原地 HAL_Delay(1000); if(HC_SR04_Read() >25)//左边无障碍物 { motorPidSetSpeed(1,1);//前运动 HAL_Delay(100); } else{ motorPidSetSpeed(-1,-1);//后运动 HAL_Delay(1000); motorPidSetSpeed(-1,1);//右边运动 HAL_Delay(50); } } } } if(g_ucMode == 4) { //**********PID跟随功能***********// g_fHC_SR04_Read=HC_SR04_Read();//读取前方障碍物距离 if(g_fHC_SR04_Read < 60){ //如果前60cm 有东西就启动跟随 g_fFollow_PID_Out = PID_realize(&pidFollow,g_fHC_SR04_Read);//PID计算输出目标速度 这个速度,会和基础速度加减 if(g_fFollow_PID_Out > 6) g_fFollow_PID_Out = 6;//对输出速度限幅 if(g_fFollow_PID_Out < -6) g_fFollow_PID_Out = -6; motorPidSetSpeed(g_fFollow_PID_Out,g_fFollow_PID_Out);//速度作用与电机上 } else motorPidSetSpeed(0,0);//如果前面60cm 没有东西就停止 HAL_Delay(10);//读取超声波传感器不能过快 } if(g_ucMode == 5) { //*************MPU6050航向角 PID转向控制*****************// sprintf((char *)Usart3String,"pitch:%.2f roll:%.2f yaw:%.2f\r\n",pitch,roll,yaw);//显示6050数据 俯仰角 横滚角 航向角 HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),0xFFFF);//通过串口三输出字符 strlen:计算字符串大小 //mpu_dmp_get_data(&pitch,&roll,&yaw);//返回值:0,DMP成功解出欧拉角 while(mpu_dmp_get_data(&pitch,&roll,&yaw)!=0){} //这个可以解决经常读不出数据的问题 g_fMPU6050YawMovePidOut = PID_realize(&pidMPU6050YawMovement,yaw);//PID计算输出目标速度 这个速度,会和基础速度加减 g_fMPU6050YawMovePidOut1 = 1.5 + g_fMPU6050YawMovePidOut;//基础速度加减PID输出速度 g_fMPU6050YawMovePidOut2 = 1.5 - g_fMPU6050YawMovePidOut; if(g_fMPU6050YawMovePidOut1 >3.5) g_fMPU6050YawMovePidOut1 =3.5;//进行限幅 if(g_fMPU6050YawMovePidOut1 <0) g_fMPU6050YawMovePidOut1 =0; if(g_fMPU6050YawMovePidOut2 >3.5) g_fMPU6050YawMovePidOut2 =3.5;//进行限幅 if(g_fMPU6050YawMovePidOut2 <0) g_fMPU6050YawMovePidOut2 =0; motorPidSetSpeed(g_fMPU6050YawMovePidOut1,g_fMPU6050YawMovePidOut2);//将最后计算的目标速度 通过motorPidSetSpeed控制电机 } ///**** 红外PID循迹功能******************/ // g_ucaHW_Read[0] = READ_HW_OUT_1;//读取红外对管状态、这样相比于写在if里面更高效 // g_ucaHW_Read[1] = READ_HW_OUT_2; // g_ucaHW_Read[2] = READ_HW_OUT_3; // g_ucaHW_Read[3] = READ_HW_OUT_4; // if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 0 ) // { //// printf("应该前进\r\n");//注释掉更加高效,减少无必要程序执行 // g_cThisState = 0;//前进 // } // else if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 1&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 0 )//使用else if更加合理高效 // { //// printf("应该右转\r\n"); // g_cThisState = -1;//应该右转 // } // else if(g_ucaHW_Read[0] == 1&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 0 ) // { //// printf("快速右转\r\n"); // g_cThisState = -2;//快速右转 // } // else if(g_ucaHW_Read[0] == 1&&g_ucaHW_Read[1] == 1&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 0) // { //// printf("快速右转\r\n"); // g_cThisState = -3;//快速右转 // } // else if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 1&&g_ucaHW_Read[3] == 0 ) // { //// printf("应该左转\r\n"); // g_cThisState = 1;//应该左转 // } // else if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 0&&g_ucaHW_Read[3] == 1 ) // { //// printf("快速左转\r\n"); // g_cThisState = 2;//快速左转 // } // else if(g_ucaHW_Read[0] == 0&&g_ucaHW_Read[1] == 0&&g_ucaHW_Read[2] == 1&&g_ucaHW_Read[3] == 1) // { //// printf("快速左转\r\n"); // g_cThisState = 3;//快速左转 // } // g_fHW_PID_Out = PID_realize(&pidHW_Tracking,g_cThisState);//PID计算输出目标速度 这个速度,会和基础速度加减 // g_fHW_PID_Out1 = 3 + g_fHW_PID_Out;//电机1速度=基础速度+循迹PID输出速度 // g_fHW_PID_Out2 = 3 - g_fHW_PID_Out;//电机1速度=基础速度-循迹PID输出速度 // if(g_fHW_PID_Out1 >5) g_fHW_PID_Out1 =5;//进行限幅 限幅速度在0-5之间 // if(g_fHW_PID_Out1 <0) g_fHW_PID_Out1 =0; // if(g_fHW_PID_Out2 >5) g_fHW_PID_Out2 =5; // if(g_fHW_PID_Out2 <0) g_fHW_PID_Out2 =0; // if(g_cThisState != g_cLastState)//如何这次状态不等于上次状态、就进行改变目标速度和控制电机、在定时器中依旧定时控制电机 // { // motorPidSetSpeed(g_fHW_PID_Out1,g_fHW_PID_Out2);//通过计算的速度控制电机 // } // // g_cLastState = g_cThisState;//保存上次红外对管状态 ////通过串口三(蓝牙)输出信息 ////***************串口三输出****************************// // sprintf((char *)Usart3String,"V1:%.2fV2:%.2f\r\n",Motor1Speed,Motor2Speed);//显示两个电机转速 单位:转/秒 // HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 // // sprintf((char *)Usart3String,"Mileage%.2f\r\n",Mileage);//计算小车里程 单位cm // HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 // // sprintf((char *)Usart3String,"U:%.2fV\r\n",adcGetBatteryVoltage());//显示电池电压 // HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),50);//阻塞式发送通过串口三输出字符 strlen:计算字符串大小 // // sprintf((char *)Usart3String,"HC_SR04:%.2fcm\r\n",HC_SR04_Read());//显示超声波数据 // HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),0xFFFF);//通过串口三输出字符 strlen:计算字符串大小 // // sprintf((char *)Usart3String,"pitch:%.2f roll:%.2f yaw:%.2f\r\n",pitch,roll,yaw);//显示6050数据 俯仰角 横滚角 航向角 // HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),0xFFFF);//通过串口三输出字符 strlen:计算字符串大小 // // //mpu_dmp_get_data(&pitch,&roll,&yaw);//返回值:0,DMP成功解出欧拉角 // while(mpu_dmp_get_data(&pitch,&roll,&yaw)!=0){} //这个可以解决经常读不出数据的问题 // // // HAL_Delay(5);//注意调用不可以过于频繁HC_SR04_Read() ////*************MPU6050航向角 PID转向控制*****************// // sprintf((char *)Usart3String,"pitch:%.2f roll:%.2f yaw:%.2f\r\n",pitch,roll,yaw);//显示6050数据 俯仰角 横滚角 航向角 // HAL_UART_Transmit(&huart3,( uint8_t *)Usart3String,strlen(( const char *)Usart3String),0xFFFF);//通过串口三输出字符 strlen:计算字符串大小 // // //mpu_dmp_get_data(&pitch,&roll,&yaw);//返回值:0,DMP成功解出欧拉角 // while(mpu_dmp_get_data(&pitch,&roll,&yaw)!=0){} //这个可以解决经常读不出数据的问题 // // // g_fMPU6050YawMovePidOut = PID_realize(&pidMPU6050YawMovement,yaw);//PID计算输出目标速度 这个速度,会和基础速度加减 // g_fMPU6050YawMovePidOut1 = 1.5 + g_fMPU6050YawMovePidOut;//基础速度加减PID输出速度 // g_fMPU6050YawMovePidOut2 = 1.5 - g_fMPU6050YawMovePidOut; // if(g_fMPU6050YawMovePidOut1 >3.5) g_fMPU6050YawMovePidOut1 =3.5;//进行限幅 // if(g_fMPU6050YawMovePidOut1 <0) g_fMPU6050YawMovePidOut1 =0; // if(g_fMPU6050YawMovePidOut2 >3.5) g_fMPU6050YawMovePidOut2 =3.5; // if(g_fMPU6050YawMovePidOut2 <0) g_fMPU6050YawMovePidOut2 =0; // motorPidSetSpeed(g_fMPU6050YawMovePidOut1,g_fMPU6050YawMovePidOut2); ////**************避障功能********************// ////避障逻辑 // if(HC_SR04_Read() > 25)//前方无障碍物 // { // motorPidSetSpeed(1,1);//前运动 // HAL_Delay(100); // } // else{ //前方有障碍物 // motorPidSetSpeed(-1,1);//右边运动 原地 // HAL_Delay(500); // if(HC_SR04_Read() > 25)//右边无障碍物 // { // motorPidSetSpeed(1,1);//前运动 // HAL_Delay(100); // } // else{//右边有障碍物 // motorPidSetSpeed(1,-1);//左边运动 原地 // HAL_Delay(1000); // if(HC_SR04_Read() >25)//左边无障碍物 // { // motorPidSetSpeed(1,1);//前运动 // HAL_Delay(100); // } // else{ // motorPidSetSpeed(-1,-1);//后运动 // HAL_Delay(1000); // motorPidSetSpeed(-1,1);//右边运动 // HAL_Delay(50); // } // } // } ////*************无PID跟随功能************// // if(HC_SR04_Read() > 25) // { // motorPidSetSpeed(1,1);//前运动 // HAL_Delay(100); // } // if(HC_SR04_Read() < 20) // { // motorPidSetSpeed(-1,-1);//后运动 // HAL_Delay(100); // } ////**********PID跟随功能***********// // g_fHC_SR04_Read=HC_SR04_Read();//读取前方障碍物距离 // if(g_fHC_SR04_Read < 60){ //如果前60cm 有东西就启动跟随 // g_fFollow_PID_Out = PID_realize(&pidFollow,g_fHC_SR04_Read);//PID计算输出目标速度 这个速度,会和基础速度加减 // if(g_fFollow_PID_Out > 6) g_fFollow_PID_Out = 6;//对输出速度限幅 // if(g_fFollow_PID_Out < -6) g_fFollow_PID_Out = -6; // motorPidSetSpeed(g_fFollow_PID_Out,g_fFollow_PID_Out);//速度作用与电机上 // } // else motorPidSetSpeed(0,0);//如果前面60cm 没有东西就停止 // HAL_Delay(10);//读取超声波传感器不能过快 // ANO_DT_Send_F2(Motor1Speed*100, 3.0*100,Motor2Speed*100,3.0*100);//向匿名上位机通过F2帧发送4个int16类型的数据 曲线显示 // if(Usart_WaitReasFinish() == 0)//是否接收完毕 // { // cJsonData = cJSON_Parse((const char *)Usart1_ReadBuf); // if(cJSON_GetObjectItem(cJsonData,"p") !=NULL) // { // cJsonVlaue = cJSON_GetObjectItem(cJsonData,"p"); // p = cJsonVlaue->valuedouble; // pidMotor1Speed.Kp = p; // } // if(cJSON_GetObjectItem(cJsonData,"i") !=NULL) // { // cJsonVlaue = cJSON_GetObjectItem(cJsonData,"i"); // i = cJsonVlaue->valuedouble; // pidMotor1Speed.Ki = i; // } // if(cJSON_GetObjectItem(cJsonData,"d") !=NULL) // { // cJsonVlaue = cJSON_GetObjectItem(cJsonData,"d"); // d = cJsonVlaue->valuedouble; // pidMotor1Speed.Kd = d; // } // if(cJSON_GetObjectItem(cJsonData,"a") !=NULL) // { // // cJsonVlaue = cJSON_GetObjectItem(cJsonData,"a"); // a = cJsonVlaue->valuedouble; // pidMotor1Speed.target_val =a; // } // if(cJSON_GetObjectItem(cJsonData,"b") !=NULL) // { // // cJsonVlaue = cJSON_GetObjectItem(cJsonData,"b"); // b = cJsonVlaue->valuedouble; // pidMotor2Speed.target_val =b; // } // if(cJsonData != NULL){ // cJSON_Delete(cJsonData);//释放空间、但是不能删除cJsonVlaue不然会 出现异常错误 // } // memset(Usart1_ReadBuf,0,255);//清空接收buf,注意这里不能使用strlen // } // printf("P:%.3f I:%.3f D:%.3f A:%.3f\r\n",p,i,d,a); // __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 10); // __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_4, 10); // HAL_GPIO_WritePin(BIN1_GPIO_Port,BIN1_Pin,GPIO_PIN_SET); // HAL_GPIO_WritePin(AIN1_GPIO_Port,AIN1_Pin,GPIO_PIN_SET); // uint8_t c_Data[] = "串口输出测试:好家伙VCC\r\n"; // HAL_UART_Transmit(&huart1,c_Data,sizeof(c_Data),0xFFFF); // HAL_Delay(1000); // printf("printf:好家伙VCC测试\r\n"); // HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin); // HAL_Delay(500); } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {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 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(); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* 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 */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #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 */ /* 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 */ } #endif /* USE_FULL_ASSERT */ #include "motor.h" #include "tim.h" #include "pid.h" #define MAX_SPEED_UP 3 extern float Motor1Speed ; extern float Motor2Speed ; extern tPid pidMotor1Speed; extern tPid pidMotor2Speed; float motorSpeedUpCut = 0.5;//加减速速度变量 void Motor_Set(int Motor1,int Motor2) { //取反更适合控制习惯,大于0小车向前运动 Motor1 =-Motor1; Motor2 =-Motor2; //1.先根据正负设置方向GPIO 高低电平 if(Motor1 <0) BIN1_SET; else BIN1_RESET; if(Motor2 <0) AIN1_SET; else AIN1_RESET; //2.然后设置占空比 if(Motor1 <0) { if(Motor1 <-99) Motor1 =-99; __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, (100+Motor1)); } else { if(Motor1 >99) Motor1 = 99; __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1,Motor1); } if(Motor2<0) { if(Motor2 <-99) Motor2=-99; __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_4, (100+Motor2)); } else { if(Motor2 >99) Motor2 =99; __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_4, Motor2); } } /******************* * @brief 通过赋值PID目标速度控制小车运动 * @param Motor1SetSpeed:电机1目标速度 Motor2SetSpeed:电机2目标速度 * @return 无 * motorPidSetSpeed(1,2);//右边运动 motorPidSetSpeed(2,1);//左边运动 motorPidSetSpeed(1,1);//前运动 motorPidSetSpeed(-1,-1);//后运动 motorPidSetSpeed(-1,1); //向右原地旋转 motorPidSetSpeed(1,-1); //向左原地旋转 *******************/ void motorPidSetSpeed(float Motor1SetSpeed,float Motor2SetSpeed) { //设置Pid目标转速 pidMotor1Speed.target_val=Motor1SetSpeed; pidMotor2Speed.target_val=Motor2SetSpeed; //PID计算控制电机 Motor_Set(PID_realize(&pidMotor1Speed,Motor1Speed),PID_realize(&pidMotor2Speed,Motor2Speed)); } //向前加速函数 void motorPidSpeedUp(void) { if(motorSpeedUpCut <= MAX_SPEED_UP) motorSpeedUpCut +=0.5;//如果没有超过最大值就增加0.5 motorPidSetSpeed(motorSpeedUpCut,motorSpeedUpCut);//设置到电机 } //向前减速函数 void motorPidSpeedCut(void) { if(motorSpeedUpCut >=0.5)motorSpeedUpCut-=0.5;//判断是否速度太小 motorPidSetSpeed(motorSpeedUpCut,motorSpeedUpCut);//设置到电机 } #include "pid.h" //定义一个结构体类型变量 tPid pidMotor1Speed;//电机1速度PID闭环参数 tPid pidMotor2Speed;//电机2速度PID闭环参数 tPid pidHW_Tracking;//红外循迹的PID结构体类型变量 tPid pidFollow; //定距离跟随PID结构体类型变量 tPid pidMPU6050YawMovement; //利用6050偏航角 进行姿态控制的PID //给结构体类型变量赋初值 void PID_init() { pidMotor1Speed.actual_val=0.0; pidMotor1Speed.target_val=0.00; pidMotor1Speed.err=0.0; pidMotor1Speed.err_last=0.0; pidMotor1Speed.err_sum=0.0; pidMotor1Speed.Kp=15; pidMotor1Speed.Ki=5; pidMotor1Speed.Kd=0; pidMotor2Speed.actual_val=0.0; pidMotor2Speed.target_val=0.00; pidMotor2Speed.err=0.0; pidMotor2Speed.err_last=0.0; pidMotor2Speed.err_sum=0.0; pidMotor2Speed.Kp=15; pidMotor2Speed.Ki=5; pidMotor2Speed.Kd=0; pidHW_Tracking.actual_val=0.0; pidHW_Tracking.target_val=0.00;//红外循迹PID 的目标值为0 pidHW_Tracking.err=0.0; pidHW_Tracking.err_last=0.0; pidHW_Tracking.err_sum=0.0; pidHW_Tracking.Kp=-1.50; pidHW_Tracking.Ki=0; pidHW_Tracking.Kd=0.80; pidFollow.actual_val=0.0; pidFollow.target_val=22.50;//定距离跟随 目标距离22.5cm pidFollow.err=0.0; pidFollow.err_last=0.0; pidFollow.err_sum=0.0; pidFollow.Kp=-0.5;//定距离跟随的Kp大小通过估算PID输入输出数据,确定大概大小,然后在调试 pidFollow.Ki=-0.001;//Ki小一些 pidFollow.Kd=0; pidMPU6050YawMovement.actual_val=0.0; pidMPU6050YawMovement.target_val=0.00;//设定姿态目标值 pidMPU6050YawMovement.err=0.0; pidMPU6050YawMovement.err_last=0.0; pidMPU6050YawMovement.err_sum=0.0; pidMPU6050YawMovement.Kp=0.02;//6050航向角PID运动控制 pidMPU6050YawMovement.Ki=0; pidMPU6050YawMovement.Kd=0.1; } //比例p调节控制函数 float P_realize(tPid * pid,float actual_val) { pid->actual_val = actual_val;//传递真实值 pid->err = pid->target_val - pid->actual_val;//当前误差=目标值-真实值 //比例控制调节 输出=Kp*当前误差 pid->actual_val = pid->Kp*pid->err; return pid->actual_val; } //比例P 积分I 控制函数 float PI_realize(tPid * pid,float actual_val) { pid->actual_val = actual_val;//传递真实值 pid->err = pid->target_val - pid->actual_val;//当前误差=目标值-真实值 pid->err_sum += pid->err;//误差累计值 = 当前误差累计和 //使用PI控制 输出=Kp*当前误差+Ki*误差累计值 pid->actual_val = pid->Kp*pid->err + pid->Ki*pid->err_sum; return pid->actual_val; } // PID控制函数 float PID_realize(tPid * pid,float actual_val) { pid->actual_val = actual_val;//传递真实值 pid->err = pid->target_val - pid->actual_val;////当前误差=目标值-真实值 pid->err_sum += pid->err;//误差累计值 = 当前误差累计和 //使用PID控制 输出 = Kp*当前误差 + Ki*误差累计值 + Kd*(当前误差-上次误差) pid->actual_val = pid->Kp*pid->err + pid->Ki*pid->err_sum + pid->Kd*(pid->err - pid->err_last); //保存上次误差: 这次误差赋值给上次误差 pid->err_last = pid->err; return pid->actual_val; } 提取所有有关于红外循迹的代码部分,并将代码分别分装在pid,sensor,motor(c文件和h文件)

/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "adc.h" #include "dac.h" #include "i2c.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "user.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC1_Init(); MX_TIM2_Init(); MX_USART1_UART_Init(); MX_I2C1_Init(); MX_DAC_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ setup(); while (1) { loop(); /* USER CODE END WHILE */ /* USER CODE BEGIN 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}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** 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.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 4; RCC_OscInitStruct.PLL.PLLN = 168; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; 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_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* 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 */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #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 */ /* 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 */ } #endif /* USE_FULL_ASSERT */

“*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Build target 'Can_Serial' linking... Can_Serial\Can_Serial.axf: Error: L6218E: Undefined symbol MX_USB_OTG_FS_PCD_Init (referred from main.o). Can_Serial\Can_Serial.axf: Error: L6218E: Undefined symbol chassis_control_loop (referred from chassis_task.o). Not enough information to list image symbols. Not enough information to list load addresses in the image map. Finished: 2 information, 0 warning and 2 error messages. "Can_Serial\Can_Serial.axf" - 2 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:00”“/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "cmsis_os.h" #include "can.h" #include "dma.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void MX_FREERTOS_Init(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_CAN1_Init(); MX_USART1_UART_Init(); MX_USART3_UART_Init(); MX_USART6_UART_Init(); MX_USB_OTG_FS_PCD_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Call init function for freertos objects (in cmsis_os2.c) */ MX_FREERTOS_Init(); /* Start scheduler */ osKernelStart(); /* We should never get here as control is now taken by the scheduler */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 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}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** 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.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 7; 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_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* 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 */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #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 */ /* 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 */ } #endif /* USE_FULL_ASSERT */ ”现在怎么办,我将mai.c里面的关于usb的头文件删除之后又出现两个错误,这可怎么办

大家在看

recommend-type

C语言流程图生成工具

AutoFlowChart 自动生成流程图 AutoFlowchart 是一个极佳的根据源码生成流程图的工具 它生成的流程图支持展开 合拢 并且可以预定义流程图块的大小和间隔 移动和缩放流程图也很方便 你还可以把它导出到WORD文档或BMP文件 它可以帮助程序员更好地理解程序 制作文档和可视化代码 支持C C++ VC++ Visual C++ NET Delphi Object Pascal 主要功能 根据源程序生成流程图 导出流程图到WORD文档中 展开 合拢流程图 自动生成一个 TreeView显示所有函数 过程 同步显示对应块的源程序和流程图 自定义流程图的配色方案 自定义流程图的大小和间距 根据格式自动排列程序 自由缩小 放大 移动流程图 显示程序行号 支持清除当前流程图 导出流程图到 bmp文件 发展前瞻 ① 支持各种语言 已经完成Pascal C 待完成:Java FoxPro Basic Fortan等; ② 支持反向操作 可以动态修改流程图 并可根据流程图生成相应的语言代码; ③ 结合Delphi专家 嵌入IDE直接运行 已经完成详见主页 操作说明 ① 打开一个或多个文件; ② 双击一个If For While Case Repeat Try begin的起始行 你就可以看到流程图; ③ 双击流程图中相应的框 可以同步显示程序块位置;">AutoFlowChart 自动生成流程图 AutoFlowchart 是一个极佳的根据源码生成流程图的工具 它生成的流程图支持展开 合拢 并且可以预定义流程图块的大小和间隔 移动和缩放流程图也很方便 你还可以把它导出到WORD文档或BMP文件 [更多]
recommend-type

GPRS网络信令实例详解

抓取了GPRS各个接口信令,很详细的各类问题抓包,值得喜欢分析的人下载做为原材料
recommend-type

The GNU Toolchain for ARM targets HOWTO.pdf

英文原版的介绍怎样制作交叉编译工具的资料
recommend-type

高频双调谐谐振放大电路设计3MHz+电压200倍放大.zip

高频双调谐谐振放大电路设计3MHz+电压200倍放大.zip
recommend-type

中国地级市地图shp

中国地级市地图shp文件,希望对大家科研有帮助。

最新推荐

recommend-type

netty-all-4.1.23.Final.jar中文文档.zip

1、压缩文件中包含: 中文文档、jar包下载地址、Maven依赖、Gradle依赖、源代码下载地址。 2、使用方法: 解压最外层zip,再解压其中的zip包,双击 【index.html】 文件,即可用浏览器打开、进行查看。 3、特殊说明: (1)本文档为人性化翻译,精心制作,请放心使用; (2)只翻译了该翻译的内容,如:注释、说明、描述、用法讲解 等; (3)不该翻译的内容保持原样,如:类名、方法名、包名、类型、关键字、代码 等。 4、温馨提示: (1)为了防止解压后路径太长导致浏览器无法打开,推荐在解压时选择“解压到当前文件夹”(放心,自带文件夹,文件不会散落一地); (2)有时,一套Java组件会有多个jar,所以在下载前,请仔细阅读本篇描述,以确保这就是你需要的文件。 5、本文件关键字: jar中文文档.zip,java,jar包,Maven,第三方jar包,组件,开源组件,第三方组件,Gradle,中文API文档,手册,开发手册,使用手册,参考手册。
recommend-type

OKT507_修改默认界面显示_Linux_应用笔记_V1.0_20220627.pdf

OKT507_修改默认界面显示_Linux_应用笔记_V1.0_20220627
recommend-type

Linux_G2D_开发指南.pdf

Linux_G2D_开发指南
recommend-type

实现Struts2+IBatis+Spring集成的快速教程

### 知识点概览 #### 标题解析 - **Struts2**: Apache Struts2 是一个用于创建企业级Java Web应用的开源框架。它基于MVC(Model-View-Controller)设计模式,允许开发者将应用的业务逻辑、数据模型和用户界面视图进行分离。 - **iBatis**: iBatis 是一个基于 Java 的持久层框架,它提供了对象关系映射(ORM)的功能,简化了 Java 应用程序与数据库之间的交互。 - **Spring**: Spring 是一个开源的轻量级Java应用框架,提供了全面的编程和配置模型,用于现代基于Java的企业的开发。它提供了控制反转(IoC)和面向切面编程(AOP)的特性,用于简化企业应用开发。 #### 描述解析 描述中提到的“struts2+ibatis+spring集成的简单例子”,指的是将这三个流行的Java框架整合起来,形成一个统一的开发环境。开发者可以利用Struts2处理Web层的MVC设计模式,使用iBatis来简化数据库的CRUD(创建、读取、更新、删除)操作,同时通过Spring框架提供的依赖注入和事务管理等功能,将整个系统整合在一起。 #### 标签解析 - **Struts2**: 作为标签,意味着文档中会重点讲解关于Struts2框架的内容。 - **iBatis**: 作为标签,说明文档同样会包含关于iBatis框架的内容。 #### 文件名称列表解析 - **SSI**: 这个缩写可能代表“Server Side Include”,一种在Web服务器上运行的服务器端脚本语言。但鉴于描述中提到导入包太大,且没有具体文件列表,无法确切地解析SSI在此的具体含义。如果此处SSI代表实际的文件或者压缩包名称,则可能是一个缩写或别名,需要具体的上下文来确定。 ### 知识点详细说明 #### Struts2框架 Struts2的核心是一个Filter过滤器,称为`StrutsPrepareAndExecuteFilter`,它负责拦截用户请求并根据配置将请求分发到相应的Action类。Struts2框架的主要组件有: - **Action**: 在Struts2中,Action类是MVC模式中的C(控制器),负责接收用户的输入,执行业务逻辑,并将结果返回给用户界面。 - **Interceptor(拦截器)**: Struts2中的拦截器可以在Action执行前后添加额外的功能,比如表单验证、日志记录等。 - **ValueStack(值栈)**: Struts2使用值栈来存储Action和页面间传递的数据。 - **Result**: 结果是Action执行完成后返回的响应,可以是JSP页面、HTML片段、JSON数据等。 #### iBatis框架 iBatis允许开发者将SQL语句和Java类的映射关系存储在XML配置文件中,从而避免了复杂的SQL代码直接嵌入到Java代码中,使得代码的可读性和可维护性提高。iBatis的主要组件有: - **SQLMap配置文件**: 定义了数据库表与Java类之间的映射关系,以及具体的SQL语句。 - **SqlSessionFactory**: 负责创建和管理SqlSession对象。 - **SqlSession**: 在执行数据库操作时,SqlSession是一个与数据库交互的会话。它提供了操作数据库的方法,例如执行SQL语句、处理事务等。 #### Spring框架 Spring的核心理念是IoC(控制反转)和AOP(面向切面编程),它通过依赖注入(DI)来管理对象的生命周期和对象间的依赖关系。Spring框架的主要组件有: - **IoC容器**: 也称为依赖注入(DI),管理对象的创建和它们之间的依赖关系。 - **AOP**: 允许将横切关注点(如日志、安全等)与业务逻辑分离。 - **事务管理**: 提供了一致的事务管理接口,可以在多个事务管理器之间切换,支持声明式事务和编程式事务。 - **Spring MVC**: 是Spring提供的基于MVC设计模式的Web框架,与Struts2类似,但更灵活,且与Spring的其他组件集成得更紧密。 #### 集成Struts2, iBatis和Spring 集成这三种框架的目的是利用它们各自的优势,在同一个项目中形成互补,提高开发效率和系统的可维护性。这种集成通常涉及以下步骤: 1. **配置整合**:在`web.xml`中配置Struts2的`StrutsPrepareAndExecuteFilter`,以及Spring的`DispatcherServlet`。 2. **依赖注入配置**:在Spring的配置文件中声明Struts2和iBatis的组件,以及需要的其他bean,并通过依赖注入将它们整合。 3. **Action和SQL映射**:在Struts2中创建Action类,并在iBatis的SQLMap配置文件中定义对应的SQL语句,将Struts2的Action与iBatis的映射关联起来。 4. **事务管理**:利用Spring的事务管理功能来管理数据库操作的事务。 5. **安全和服务层**:通过Spring的AOP和IoC功能来实现业务逻辑的解耦合和事务的管理。 ### 结语 通过上述的整合,开发者可以有效地利用Struts2处理Web层的展示和用户交互,使用iBatis简化数据库操作,同时借助Spring强大的依赖注入和事务管理功能,创建一个结构良好、可维护性强的应用。这种集成方式在许多企业级Java Web应用中非常常见,是Java开发人员必须掌握的知识点。
recommend-type

【数据融合技术】:甘肃土壤类型空间分析中的专业性应用

# 摘要 数据融合技术作为一种集成多源数据信息的方法,在土壤类型空间分析中发挥着关键作用。本文介绍了数据融合技术的基本概念及其理论基础,阐述了数据预处理、同步整合及冲突解决等关键技术,并详细描述了甘肃土壤类型数据准备的流程,包括数据采集、质量评估、空间化处理及融合实践准备。通过具体案例分析,展示了数据融合在土壤类型空间分布分析、土壤质量评估及土壤保护规划中的应用。同时,文
recommend-type

Waymo使用稀疏图卷积处理LiDAR点云,目标检测精度提升15%

<think>好的,用户让我介绍一下Waymo使用稀疏图卷积处理LiDAR点云,目标检测精度提升15%的具体情况。我需要先回忆之前提供的回答中提到的相关案例,然后深入展开。 首先,用户可能已经知道稀疏图卷积的基本概念,但需要更详细的应用案例。他们可能对Waymo如何具体应用该技术感兴趣,比如技术细节、实现方式、提升的具体指标等。需要确保回答结构清晰,分点说明,同时保持技术准确性。 要考虑到用户可能的背景,可能是研究或工程领域的,需要技术细节,但避免过于复杂的数学公式,除非必要。之前回答中提到了应用案例,现在需要扩展这个部分。需要解释为什么稀疏图卷积在这里有效,比如处理LiDAR点云的稀疏性
recommend-type

Dwr实现无刷新分页功能的代码与数据库实例

### DWR简介 DWR(Direct Web Remoting)是一个用于允许Web页面中的JavaScript直接调用服务器端Java方法的开源库。它简化了Ajax应用的开发,并使得异步通信成为可能。DWR在幕后处理了所有的细节,包括将JavaScript函数调用转换为HTTP请求,以及将HTTP响应转换回JavaScript函数调用的参数。 ### 无刷新分页 无刷新分页是网页设计中的一种技术,它允许用户在不重新加载整个页面的情况下,通过Ajax与服务器进行交互,从而获取新的数据并显示。这通常用来优化用户体验,因为它加快了响应时间并减少了服务器负载。 ### 使用DWR实现无刷新分页的关键知识点 1. **Ajax通信机制:**Ajax(Asynchronous JavaScript and XML)是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。通过XMLHttpRequest对象,可以与服务器交换数据,并使用JavaScript来更新页面的局部内容。DWR利用Ajax技术来实现页面的无刷新分页。 2. **JSON数据格式:**DWR在进行Ajax调用时,通常会使用JSON(JavaScript Object Notation)作为数据交换格式。JSON是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成。 3. **Java后端实现:**Java代码需要编写相应的后端逻辑来处理分页请求。这通常包括查询数据库、计算分页结果以及返回分页数据。DWR允许Java方法被暴露给前端JavaScript,从而实现前后端的交互。 4. **数据库操作:**在Java后端逻辑中,处理分页的关键之一是数据库查询。这通常涉及到编写SQL查询语句,并利用数据库管理系统(如MySQL、Oracle等)提供的分页功能。例如,使用LIMIT和OFFSET语句可以实现数据库查询的分页。 5. **前端页面设计:**前端页面需要设计成能够响应用户分页操作的界面。例如,提供“下一页”、“上一页”按钮,或是分页条。这些元素在用户点击时会触发JavaScript函数,从而通过DWR调用Java后端方法,获取新的分页数据,并动态更新页面内容。 ### 数据库操作的关键知识点 1. **SQL查询语句:**在数据库操作中,需要编写能够支持分页的SQL查询语句。这通常涉及到对特定字段进行排序,并通过LIMIT和OFFSET来控制返回数据的范围。 2. **分页算法:**分页算法需要考虑当前页码、每页显示的记录数以及数据库中记录的总数。SQL语句中的OFFSET计算方式通常为(当前页码 - 1)* 每页记录数。 3. **数据库优化:**在分页查询时,尤其是当数据量较大时,需要考虑到查询效率问题。可以通过建立索引、优化SQL语句或使用存储过程等方式来提高数据库操作的性能。 ### DWR无刷新分页实现的代码要点 1. **DWR配置:**在实现DWR无刷新分页时,首先需要配置DWR,以暴露Java方法给前端JavaScript调用。 2. **JavaScript调用:**编写JavaScript代码,使用DWR提供的API发起Ajax调用。这些调用将触发后端Java方法,并接收返回的分页数据。 3. **数据展示:**在获取到新的分页数据后,需要将这些数据显示在前端页面的相应位置。这通常需要操作DOM元素,将新数据插入到页面中。 ### 结论 通过结合上述知识点,可以使用DWR技术实现一个无刷新分页的动态Web应用。DWR简化了Ajax通信过程,让开发者可以专注于业务逻辑的实现。通过熟练掌握Java后端处理、数据库查询和前端页面设计的相关技术,便能高效地完成无刷新分页的开发任务。
recommend-type

【空间分布规律】:甘肃土壤类型与农业生产的关联性研究

# 摘要 本文对甘肃土壤类型及其在农业生产中的作用进行了系统性研究。首先概述了甘肃土壤类型的基础理论,并探讨了土壤类型与农业生产的理论联系。通过GIS技术分析,本文详细阐述了甘肃土壤的空间分布规律,并对其特征和影响因素进行了深入分析。此外,本文还研究了甘肃土壤类型对农业生产实际影响,包括不同区域土壤改良和作物种植案例,以及土壤养分、水分管理对作物生长周期和产量的具体影响。最后,提出了促进甘肃土壤与农业可持续发展的策略,包括土壤保护、退化防治对策以及土壤类型优化与农业创新的结合。本文旨在为
recommend-type

缓存延迟双删的实际解决方案通常怎么实现

<think>嗯,用户问的是关于缓存延迟双删的最佳实践和实际解决方案。首先,我需要回忆一下延迟双删的基本概念。根据引用[1]和[2],延迟双删主要是为了解决数据库和缓存之间的数据不一致问题,尤其是在分布式系统中。核心步骤应该是先删除缓存,再更新数据库,然后延迟一段时间再次删除缓存。但具体怎么操作呢? 用户可能已经知道延迟双删的基本思想,但需要更详细的步骤和注意事项。比如,为什么要延迟?延迟多久合适?这些都需要解释清楚。引用[3]提到先更新数据库再删除缓存是推荐的方法,但延迟双删可能是在某些特定场景下的优化。 接下来,我得考虑实现延迟双删的具体步骤。首先,第一次删除缓存是为了避免旧数据被后续
recommend-type

企业内部文档管理平台使用Asp.net技术构建

标题和描述中提到的知识点相当丰富,涉及到多个层面的IT技术和管理机制,具体如下: 1. Asp.net技术框架:Asp.net是微软公司开发的一个用于构建动态网站和网络应用程序的服务器端技术。它基于.NET平台,支持使用C#、VB.NET等多种编程语言开发应用程序。Asp.net企业信息文档管理系统使用Asp.net框架,意味着它将利用这一技术平台的特性,比如丰富的类库、集成开发环境(IDE)支持和面向对象的开发模型。 2.TreeView控件:TreeView是一种常用的Web控件,用于在网页上显示具有层次结构的数据,如目录、文件系统或组织结构。该控件通常用于提供给用户清晰的导航路径。在Asp.net企业信息文档管理系统中,TreeView控件被用于实现树状结构的文档管理功能,便于用户通过树状目录快速定位和管理文档。 3.系统模块设计:Asp.net企业信息文档管理系统被划分为多个模块,包括类别管理、文档管理、添加文档、浏览文档、附件管理、角色管理和用户管理等。这些模块化的设计能够让用户根据不同的功能需求进行操作,从而提高系统的可用性和灵活性。 4.角色管理:角色管理是企业信息管理系统中非常重要的一个部分,用于定义不同级别的用户权限和职责。在这个系统中,角色可以进行添加、编辑(修改角色名称)、删除以及上下移动(改变排列顺序)。这些操作满足了对用户权限细分和动态调整的需求。 5.操作逻辑:描述中详细说明了角色管理的操作步骤,如通过按钮选择进行角色的移动、修改和删除,提供了明确的用户交互流程,体现了系统设计的直观性。 6.系统安全性:系统提供了默认的管理帐号和密码(均为51aspx),这通常是一种简便的部署时临时设置。但在实际部署过程中,出于安全考虑,这些默认信息需要立即更改,并定期更新密码以避免潜在的安全风险。 7.文件结构:文件名称列表揭示了系统的文件结构和主要组成部分,比如Global.asax负责应用程序级别的事件处理,Default.aspx和Default.aspx.cs分别对应于系统的默认页面和后台代码文件,Web.Config用于存储和配置应用程序的设置,DocumentManager.sln和DocumentManager.suo分别指出了解决方案文件和解决方案用户选项文件,表明这是一个完整的Visual Studio解决方案。 通过上述知识点的梳理,我们可以看出Asp.net企业信息文档管理系统是一个集成了多个模块,具有良好用户体验设计、清晰操作逻辑和基本安全措施的IT解决方案。它不仅可以提高企业文档管理的效率,还能通过角色的权限管理确保信息的安全性和访问控制的合理性。同时,该系统还遵循了一定的软件工程实践,如模块化设计和配置文件的使用,以保障系统的可维护性和可扩展性。