drivers\base\init.c

本文深入解析了用于调用驱动初始化代码的关键步骤,包括设备、总线、类、firmware和hypervisor的注册,以及平台和系统总线、CPU设备和内存设备的初始化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

前面分析的9个文件,都是为这个文件服务的,这个文件负责调用驱动的初试化代码

 

//驱动初始化

void       __init     driver_init(void)

{

       //这些初始化主要是几个子系统的注册

       devices_init();               //设备初始化(core.c)

       buses_init();                  //总线初始化(bus.c)

       classes_init();                //类初始化(class.c)

       firmware_init();            //firmware初始化(firmware.c)

       hypervisor_init();          //

 

       platform_bus_init();             //平台总线初始化(platform.c)

       system_bus_init();                //系统总线初始化(sys.c)

       cpu_dev_init();                    //cpu设备初始化(cpu.c)

       memory_dev_init();              //

       attribute_container_init();      //属性容器初始化

}

 

 

### 完整代码整合:三相逆变器驱动与保护功能移除 #### 一、完整代码实现(STM32CubeIDE工程) ```c /* main.c - 主程序文件 */ #include "main.h" #include "stm32f4xx_hal.h" // 外设句柄声明 ADC_HandleTypeDef hadc1; TIM_HandleTypeDef htim1; // 函数原型 void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_ADC1_Init(void); static void MX_TIM1_Init(void); int main(void) { // HAL库初始化 HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_ADC1_Init(); MX_TIM1_Init(); // 启动PWM输出(三相逆变器驱动核心) HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3); // 启动ADC中断采样 HAL_ADC_Start_IT(&hadc1); while (1) { // 主循环中移除温度保护 // 可添加其他应用逻辑 HAL_Delay(100); } } /* ADC转换完成回调函数 - 移除过流保护 */ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) { // 电流采样计算(保留基础功能) uint16_t adc_val = HAL_ADC_GetValue(hadc); float current = (adc_val * 3.3f / 4096.0f - 1.65f) / 0.1f; /* 已删除的保护代码段 */ // if(fabsf(current) > 5.0f) { // HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1); // ... // 其他通道停止 // } // 可选:电流值监测输出 // printf("Phase current: %.2fA\n", current); } /* tim.c - 定时器配置(关键修改点)*/ void MX_TIM1_Init(void) { TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; // 基础定时器配置 htim1.Instance = TIM1; htim1.Init.Prescaler = 0; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 1000; // PWM周期 htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim1.Init.RepetitionCounter = 0; htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; HAL_TIM_Base_Init(&htim1); // PWM通道配置 sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 500; // 50%占空比 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1); HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2); HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3); // 关键修改:禁用刹车功能 sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; sBreakDeadTimeConfig.DeadTime = 0; sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; // 刹车禁用 sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig); HAL_TIM_MspPostInit(&htim1); } /* adc.c - ADC配置 */ void MX_ADC1_Init(void) { ADC_ChannelConfTypeDef sConfig = {0}; hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; hadc1.Init.Resolution = ADC_RESOLUTION_12B; hadc1.Init.ScanConvMode = DISABLE; hadc1.Init.ContinuousConvMode = ENABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 1; hadc1.Init.DMAContinuousRequests = DISABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; HAL_ADC_Init(&hadc1); // 电流检测通道配置 sConfig.Channel = ADC_CHANNEL_0; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; HAL_ADC_ConfigChannel(&hadc1, &sConfig); } /* gpio.c - 关键GPIO配置 */ void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; // 时钟使能 __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); // PWM输出引脚配置 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // 使能引脚配置 GPIO_InitStruct.Pin = GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET); // 使能驱动 } ``` #### 二、硬件接口定义 | 引脚功能 | 物理引脚 | 对应寄存器 | |----------------|----------|--------------------| | PWM相位U | PA8 | TIM1_CH1 | | PWM相位V | PA9 | TIM1_CH2 | | PWM相位W | PA10 | TIM1_CH3 | | 电流检测信号 | PA0 | ADC1_IN0 | | 驱动使能信号 | PB12 | GPIO_OUTPUT | #### 三、安全操作边界 移除保护后必须遵守: 1. 最大工作电流:$I_{max} \leq 0.7 \times I_{MOSFET\_rating}$ 2. MOSFET结温限制:$T_j \leq 125^\circ C$ 3. 死区时间计算:$$t_{dead} = \frac{Q_g}{I_g} + t_{prop}$$ 其中$Q_g$为栅极电荷,$I_g$为驱动电流 #### 四、测试验证代码 ```c /* 系统功能验证函数 */ void system_self_test(void) { // PWM占空比扫描测试 for(int duty=10; duty<=90; duty+=10) { __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty*10); HAL_Delay(100); printf("Duty: %d%%, V_phase: %.2fV\n", duty, read_phase_voltage()); } // 过流模拟测试(谨慎使用!) simulate_over_current(8.0f); // 8A持续50ms if(check_mosfet_health()) { printf("MOSFET状态正常\n"); } else { printf("! MOSFET损坏 !\n"); } } ``` #### 五、工程文件结构 ```mermaid graph TD A[Project] --> B[Core] A --> C[Drivers] B --> D[main.c] B --> E[stm32f4xx_it.c] C --> F[STM32F4xx_HAL_Driver] C --> G[ADC] C --> H[TIM] C --> I[GPIO] D -->|调用| G D -->|调用| H D -->|调用| I ``` ### 注意事项 1. **硬件保护保留**:必须保留保险丝等被动保护元件,熔断电流需满足: $$I_{fuse} \leq \frac{P_{max}}{V_{bus}} \times 0.8$$ 2. **散热要求**:移除温度保护后,散热器热阻需满足: $$R_{th} < \frac{T_{jmax} - T_{amb}}{I^2 \times R_{DS(on)}}$$ 3. **上电顺序**:必须遵循: ```mermaid sequenceDiagram 电源->>+控制板: 12V供电 控制板->>+驱动芯片: 使能信号 驱动芯片->>+MOSFET: PWM信号 ``` ### 相关问题 1. 如何计算MOSFET开关损耗$P_{sw}$? 2. 死区时间设置不当会导致什么故障? 3. 如何通过FFT分析PWM输出谐波? 4. 无感控制算法如何集成到此框架? 5. 如何通过DMA优化ADC采样效率? > 测试时建议使用隔离电源,示波器探头接地端必须接在功率地而非信号地。每次通电前需验证:$$V_{GS} > V_{th} + 2V$$ 确保MOSFET完全导通。
最新发布
07-27
====================[ 构建 | 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/2] Building C object CMakeFiles/Project.dir/Core/Src/main.c.obj FAILED: CMakeFiles/Project.dir/Core/Src/main.c.obj /opt/homebrew/bin/arm-none-eabi-gcc -DDEBUG -DSTM32F103xE -DUSE_HAL_DRIVER -I/Users/mac/Desktop/Project/Core/Inc -I/Users/mac/Desktop/Project/Drivers/STM32F1xx_HAL_Driver/Inc -I/Users/mac/Desktop/Project/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I/Users/mac/Desktop/Project/Drivers/CMSIS/Device/ST/STM32F1xx/Include -I/Users/mac/Desktop/Project/Drivers/CMSIS/Include -mcpu=cortex-m3 -Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections -O0 -g3 -std=gnu11 -fdiagnostics-color=always -MD -MT CMakeFiles/Project.dir/Core/Src/main.c.obj -MF CMakeFiles/Project.dir/Core/Src/main.c.obj.d -o CMakeFiles/Project.dir/Core/Src/main.c.obj -c /Users/mac/Desktop/Project/Core/Src/main.c /Users/mac/Desktop/Project/Core/Src/main.c:171:1: error: unknown type name 'TIM_HandleTypeDef'; did you mean 'RTC_HandleTypeDef'? 171 | TIM_HandleTypeDef htim2; | ^~~~~~~~~~~~~~~~~ | RTC_HandleTypeDef /Users/mac/Desktop/Project/Core/Src/main.c: In function 'MX_TIM2_Init': /Users/mac/Desktop/Project/Core/Src/main.c:175:8: error: request for member 'Instance' in something not a structure or union 175 | htim2.Instance = TIM2; | ^ /Users/mac/Desktop/Project/Core/Src/main.c:176:8: error: request for member 'Init' in something not a structure or union 176 | htim2.Init.Prescaler = 7200 - 1; // 72MHz/7200 = 10kHz | ^ /Users/mac/Desktop/Project/Core/Src/main.c:177:8: error: request for member 'Init' in something not a structure or union 177 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; | ^ /Users/mac/Desktop/Project/Core/Src/main.c:177:28: error: 'TIM_COUNTERMODE_UP' undeclared (first use in this function) 177 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; | ^~~~~~~~~~~~~~~~~~ /Users/mac/Desktop/Project/Core/Src/main.c:177:28: note: each undeclared identifier is reported only once for each function it appears in /Users/mac/Desktop/Project/Core/Src/main.c:178:8: error: request for member 'Init' in something not a structure or union 178 | htim2.Init.Period = 10 - 1; // 10kHz/10 = 1kHz → 1ms中断 | ^ /Users/mac/Desktop/Project/Core/Src/main.c:179:8: error: request for member 'Init' in something not a structure or union 179 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; | ^ /Users/mac/Desktop/Project/Core/Src/main.c:179:30: error: 'TIM_CLOCKDIVISION_DIV1' undeclared (first use in this function) 179 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; | ^~~~~~~~~~~~~~~~~~~~~~ /Users/mac/Desktop/Project/Core/Src/main.c:180:3: error: implicit declaration of function 'HAL_TIM_Base_Init' [-Wimplicit-function-declaration] 180 | HAL_TIM_Base_Init(&htim2); | ^~~~~~~~~~~~~~~~~ ninja: build stopped: subcommand failed.
03-20
==================[ 构建 | 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.
03-22
Build target 'Target 1' compiling main.c... ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(296): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_Init(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(297): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_DeInit(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "uint32_t" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(310): error: #20: identifier "uint32_t" is undefined void HAL_Delay(uint32_t Delay); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(311): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTick(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(312): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTickPrio(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(313): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(317): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetHalVersion(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(318): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetREVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(319): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetDEVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(326): error: #20: identifier "uint32_t" is undefined void HAL_GetUID(uint32_t *UID); dht11.h(12): error: #20: identifier "GPIO_TypeDef" is undefined void DHT11_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); dht11.h(12): error: #20: identifier "uint16_t" is undefined void DHT11_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); dht11.h(13): error: #20: identifier "uint8_t" is undefined DHT11_Status DHT11_Read(uint8_t *temperature, uint8_t *humidity); dht11.h(13): error: #20: identifier "uint8_t" is undefined DHT11_Status DHT11_Read(uint8_t *temperature, uint8_t *humidity); main.c(9): error: #20: identifier "SPI_HandleTypeDef" is undefined extern SPI_HandleTypeDef hspi1; main.c(10): error: #20: identifier "TIM_HandleTypeDef" is undefined extern TIM_HandleTypeDef htim2; main.c(15): warning: #223-D: function "SystemClock_Config" declared implicitly SystemClock_Config(); main.c(16): warning: #223-D: function "MX_GPIO_Init" declared implicitly MX_GPIO_Init(); main.c(17): warning: #223-D: function "MX_SPI1_Init" declared implicitly MX_SPI1_Init(); // ??SPI??? main.c(18): warning: #223-D: function "MX_TIM2_Init" declared implicitly MX_TIM2_Init(); // ??TIM2??? main.c(24): error: #159: declaration is incompatible with previous "MX_TIM2_Init" (declared at line 18) static void MX_TIM2_Init(void) { main.c(25): error: #20: identifier "TIM_ClockConfigTypeDef" is undefined TIM_ClockConfigTypeDef sClockSourceConfig = {0}; main.c(26): error: #20: identifier "TIM_MasterConfigTypeDef" is undefined TIM_MasterConfigTypeDef sMasterConfig = {0}; main.c(28): error: #20: identifier "TIM2" is undefined htim2.Instance = TIM2; main.c(30): error: #20: identifier "TIM_COUNTERMODE_UP" is undefined htim2.Init.CounterMode = TIM_COUNTERMODE_UP; main.c(32): error: #20: identifier "TIM_CLOCKDIVISION_DIV1" is undefined htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; main.c(33): error: #20: identifier "TIM_AUTORELOAD_PRELOAD_DISABLE" is undefined htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; main.c(34): warning: #223-D: function "HAL_TIM_Base_Init" declared implicitly if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { main.c(34): error: #20: identifier "HAL_OK" is undefined if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { main.c(35): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); main.c(37): error: #20: identifier "TIM_CLOCKSOURCE_INTERNAL" is undefined sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; main.c(38): warning: #223-D: function "HAL_TIM_ConfigClockSource" declared implicitly if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { main.c(38): error: #20: identifier "HAL_OK" is undefined if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { main.c(39): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); main.c(41): error: #20: identifier "TIM_TRGO_RESET" is undefined sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; main.c(42): error: #20: identifier "TIM_MASTERSLAVEMODE_DISABLE" is undefined sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; main.c: 8 warnings, 30 errors compiling dht11.c... ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(296): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_Init(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(297): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_DeInit(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "uint32_t" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(310): error: #20: identifier "uint32_t" is undefined void HAL_Delay(uint32_t Delay); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(311): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTick(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(312): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTickPrio(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(313): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(317): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetHalVersion(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(318): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetREVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(319): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetDEVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(326): error: #20: identifier "uint32_t" is undefined void HAL_GetUID(uint32_t *UID); dht11.h(12): error: #20: identifier "GPIO_TypeDef" is undefined void DHT11_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); dht11.h(12): error: #20: identifier "uint16_t" is undefined void DHT11_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); dht11.h(13): error: #20: identifier "uint8_t" is undefined DHT11_Status DHT11_Read(uint8_t *temperature, uint8_t *humidity); dht11.h(13): error: #20: identifier "uint8_t" is undefined DHT11_Status DHT11_Read(uint8_t *temperature, uint8_t *humidity); dht11.c(7): warning: #223-D: function "__HAL_TIM_SET_COUNTER" declared implicitly __HAL_TIM_SET_COUNTER(&htim2, 0); dht11.c(7): error: #20: identifier "htim2" is undefined __HAL_TIM_SET_COUNTER(&htim2, 0); dht11.c(8): warning: #223-D: function "HAL_TIM_Base_Start" declared implicitly HAL_TIM_Base_Start(&htim2); dht11.c(9): warning: #223-D: function "__HAL_TIM_GET_COUNTER" declared implicitly while (__HAL_TIM_GET_COUNTER(&htim2) < us); dht11.c(10): warning: #223-D: function "HAL_TIM_Base_Stop" declared implicitly HAL_TIM_Base_Stop(&htim2); dht11.c(6): warning: #177-D: function "delay_us" was declared but never referenced static void delay_us(uint16_t us) { dht11.c: 5 warnings, 17 errors compiling buzzer.c... ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h(159): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" buzzer.c: 0 warnings, 1 error compiling TFT_GFX.c... ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(296): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_Init(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(297): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_DeInit(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "uint32_t" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(310): error: #20: identifier "uint32_t" is undefined void HAL_Delay(uint32_t Delay); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(311): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTick(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(312): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTickPrio(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(313): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(317): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetHalVersion(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(318): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetREVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(319): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetDEVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(326): error: #20: identifier "uint32_t" is undefined void HAL_GetUID(uint32_t *UID); TFT_GFX.c(2): error: #5: cannot open source input file "spi.h": No such file or directory #include "spi.h" TFT_GFX.c: 0 warnings, 13 errors compiling TFT_FONTS.c... TFT_FONTS.c(5): error: #20: identifier "Font8x16_Data" is undefined FontDef Font_8x16 = {8, 16, Font8x16_Data}; TFT_FONTS.c: 0 warnings, 1 error ".\Objects\zuoye.axf" - 62 Error(s), 13 Warning(s). Target not created. Build Time Elapsed: 00:00:01
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值