KEIL报错:fatal error in include chain(stm32f4xx_conf.h): stm32f4xx_dma.h not found 解决办法(参考同平台大佬)

当遇到Keil编译时报错找不到某个头文件,如stm32f4xx_dma.h,可以尝试查找UV4文件夹中的UVCC.ini文件,用记事本打开并添加缺失的头文件路径。这样能消除编译错误,使程序正常运行。

程序正常编译可以通过,也不报错,但是头文件“sys.h”有一个下划红线(因为我的已经改过了,所以此处用红色标记了下),鼠标光标靠近,提示我有错误:KEIL报错:fatal error in include chain(stm32f4xx_conf.h): stm32f4xx_dma.h not found  ,也是找到了网上也有人遇到了相同的问题,https://blog.youkuaiyun.com/gin_love/article/details/87633814 附上链接

解决办法: 找到keil软件安装路径的UV4 文件夹,搜索找到文件夹中的 UVCC.ini 文件,用记事本打开,将报错的那个头文件添加到文件中 。

添加成功,那个下划线就消失了,舒服了。

*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'D:\Keil5\ARM\ARMCC\Bin' Rebuild target 'OLED' compiling lcd.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" ..\HARDWARE\LCD\lcd.c: 0 warnings, 1 error compiling main.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" main.c: 0 warnings, 1 error compiling stm32f4xx_it.c... stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" stm32f4xx_it.c: 0 warnings, 1 error compiling delay.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" ..\SYSTEM\delay\delay.c: 0 warnings, 1 error compiling usart.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" ..\SYSTEM\usart\usart.c: 0 warnings, 1 error compiling misc.c... ..\FWLIB\src\misc.c(76): error: #5: cannot open source input file "misc.h": No such file or directory #include "misc.h" ..\FWLIB\src\misc.c: 0 warnings, 1 error compiling stm32f4xx_syscfg.c... ..\FWLIB\src\stm32f4xx_syscfg.c(50): error: #5: cannot open source input file "stm32f4xx_syscfg.h": No such file or directory #include "stm32f4xx_syscfg.h" ..\FWLIB\src\stm32f4xx_syscfg.c: 0 warnings, 1 error compiling sys.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" ..\SYSTEM\sys\sys.c: 0 warnings, 1 error compiling stm32f4xx_hal.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c: 0 warnings, 1 error compiling system_stm32f4xx.c... stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" system_stm32f4xx.c: 0 warnings, 1 error compiling lcd_init.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" ..\HARDWARE\LCD\lcd_init.c: 0 warnings, 1 error compiling stm32f4xx_rcc.c... ..\FWLIB\src\stm32f4xx_rcc.c(59): error: #5: cannot open source input file "stm32f4xx_rcc.h": No such file or directory #include "stm32f4xx_rcc.h" ..\FWLIB\src\stm32f4xx_rcc.c: 0 warnings, 1 error assembling startup_stm32f40_41xxx.s... compiling stm32f4xx_gpio.c... ..\FWLIB\src\stm32f4xx_gpio.c(84): error: #5: cannot open source input file "stm32f4xx_gpio.h": No such file or directory #include "stm32f4xx_gpio.h" ..\FWLIB\src\stm32f4xx_gpio.c: 0 warnings, 1 error compiling stm32f4xx_hal_rcc.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c: 0 warnings, 1 error compiling stm32f4xx_hal_cortex.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c: 0 warnings, 1 error compiling key.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" key.c: 0 warnings, 1 error compiling stm32f4xx_usart.c... ..\FWLIB\src\stm32f4xx_usart.c(92): error: #5: cannot open source input file "stm32f4xx_usart.h": No such file or directory #include "stm32f4xx_usart.h" ..\FWLIB\src\stm32f4xx_usart.c: 0 warnings, 1 error compiling stm32f4xx_hal_dma.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c: 0 warnings, 1 error compiling stm32f4xx_hal_gpio.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c: 0 warnings, 1 error compiling stm32f4xx_hal_dma_ex.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c: 0 warnings, 1 error compiling stm32f4xx_hal_rcc_ex.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c: 0 warnings, 1 error assembling startup_stm32f407xx.s... compiling stm32f4xx_hal_uart.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c: 0 warnings, 1 error compiling stm32f4xx_hal_tim.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c: 0 warnings, 1 error compiling system_stm32f4xx.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" RTE\Device\STM32F407ZG\system_stm32f4xx.c: 0 warnings, 1 error compiling led.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" ..\HARDWARE\LED\led.c: 0 warnings, 1 error compiling stm32f4xx_hal_usart.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c: 0 warnings, 1 error compiling stm32f4xx_hal_tim_ex.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c: 0 warnings, 1 error compiling stm32f4xx_hal_pwr_ex.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c: 0 warnings, 1 error compiling stm32f4xx_hal_pwr.c... ..\USER\stm32f4xx_conf.h(34): error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory #include "stm32f4xx_adc.h" D:\Keil5\ARM\PACK\Keil\STM32F4xx_DFP\2.16.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c: 0 warnings, 1 error "..\OBJ\LCD.axf" - 29 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:03 请帮我分析剩下的问题,刚才将fwlib\inc删去路径了
07-12
你已经删除了 `FWLIB\inc` 这个包含路径,这是一个正确的第一步。但目前的错误信息说明: > ``` > error: #5: cannot open source input file "stm32f4xx_adc.h": No such file or directory > ``` 这表示工程中某些 `.c` 文件或配置文件(如 `stm32f4xx_conf.h`)仍然在尝试引用一些头文件,比如: - `stm32f4xx_adc.h` - `misc.h` - `stm32f4xx_gpio.h` - `stm32f4xx_rcc.h` - `stm32f4xx_usart.h` 这些是标准外设库(Standard Peripheral Library)中的头文件。 --- ## ✅ 问题原因分析 ### 🚫 错误核心原因: 你**正在使用 HAL 库开发 STM32 程序**,但你的工程中仍存在大量 **标准外设库(StdPeriph)的遗留代码和引用**。 这些错误是因为: 1. `stm32f4xx_conf.h` 中包含了 `#include "stm32f4xx_adc.h"` —— 这是 StdPeriph 的配置方式。 2. 多个 `.c` 文件(如 `misc.c`, `stm32f4xx_gpio.c`, `stm32f4xx_usart.c`)属于标准外设库源码,它们也在试图引用对应的 StdPeriph 头文件。 3. 工程中没有添加 StdPeriph 库的路径,也没有启用其支持,因此编译器找不到这些文件。 --- ## ✅ 解决方案:彻底切换为 HAL 库模式 如果你的目标是使用 **HAL 库** 开发,而不是使用标准外设库,请执行以下步骤: --- ## ✅ 步骤一:删除所有 StdPeriph 相关的 `.c` 文件 从工程中移除以下文件(如果存在): ``` misc.c stm32f4xx_gpio.c stm32f4xx_rcc.c stm32f4xx_usart.c stm32f4xx_syscfg.c ... ``` 这些文件来自标准外设库,不适用于 HAL 工程。 --- ## ✅ 步骤二:检查并清理 `stm32f4xx_conf.h` 打开 `stm32f4xx_conf.h`,找到如下行: ```c #include "stm32f4xx_adc.h" ``` 将它改为: ```c #include "stm32f4xx_hal.h" ``` 或者直接删除这一行,因为 HAL 库会自动处理模块依赖。 确保其他 StdPeriph 相关的 include 也全部被清除。 --- ## ✅ 步骤三:确认只使用 HAL 库头文件 在你的所有 `.c` 文件中,应只包含 HAL 库的头文件,例如: ```c #include "stm32f4xx_hal.h" // 必须放在最前面 #include "main.h" ``` 不要出现如下内容: ```c #include "stm32f4xx_gpio.h" // ❌ 标准外设库头文件 #include "misc.h" // ❌ 标准外设库头文件 ``` --- ## ✅ 步骤四:确保工程中已正确启用 HAL 库支持 在 Keil 中: - 打开 `Project → Manage → Run-Time Environment...` - 在左侧选择: - `CMSIS → CORE` - `Device → Startup` - `Device → System` - `RTOS → None` - 在右侧确保启用了: - `STM32Cube Framework (API) → Classic` 或 `STM32CubeMX` 这样会自动包含 HAL 库和 CMSIS 支持。 --- ## ✅ 步骤五:重新编译工程 完成以上修改后: - 清理工程:点击 `Project → Clean Targets` - 重新构建:点击 `Project → Build Target` --- ## ✅ 示例:一个最小化的 main.c 使用 HAL 库 ```c #include "stm32f4xx_hal.h" int main(void) { HAL_Init(); SystemClock_Config(); __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitTypeDef gpio; gpio.Pin = GPIO_PIN_5; gpio.Mode = GPIO_MODE_OUTPUT_PP; gpio.Pull = GPIO_NOPULL; gpio.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &gpio); while (1) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); HAL_Delay(500); } } ``` --- ## ✅ 总结建议 | 问题 | 原因 | 解决方法 | |------|------|----------| | 缺少 `stm32f4xx_adc.h` 等文件 | 引用了标准外设库 | 删除 StdPeriph 相关引用 | | `misc.h`、`stm32f4xx_gpio.c` 报错 | 混合使用了 StdPeriph 和 HAL | 移除 StdPeriph 源文件 | | `stm32f4xx_conf.h` 包含错误 | 是 StdPeriph 配置文件 | 修改为 HAL 模式或删除 | | 编译器报错过多 | 工程结构混乱 | 新建纯净的 HAL 工程更清晰 | ---
评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值