STM32 HAL库 error: #20: identifier "HAL_StatusTypeDef" is undefined问题

error: #20: identifier “HAL_StatusTypeDef” is undefined

我使用的是stm32l0的芯片,由于没有标准库可用,无奈只有折腾HAL库了。

首先,说下上面的错误怎么来的。我使用stm32cubeMX自动生成了代码,并且自己在工程里面新建了文件,文件里面需要用到HAL外设库中定义的宏定义,本来应该添加包含“stm32l0xx_hal_dac.h”,但是我发现”stm32l0xx_hal_conf.h” 中有所有外设的头文件,并且通过宏定义打开,所以我在该文件中添加了下面的语句:

#include "stm32l0xx_hal_conf.h" 

编译后就出现了如下错误:
../Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_hal.h(374): error: #20: identifier
“HAL_StatusTypeDef” is undefined
HAL_StatusTypeDef HAL_Init(void);
../Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_hal.h(375): error: #20: identifier
“HAL_StatusTypeDef” is undefined
HAL_StatusTypeDef HAL_DeInit(void);
../Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_hal.h(378): error: #20: identifier
“HAL_StatusTypeDef” is undefined
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority);
..\Drv\dac\drv_dac.c: 0 warnings, 3 errors

一直想不明白,“HAL_StatusTypeDef”变量在“stm32l0xx_hal_def.h”中已经有了定义,并且该变量也能成功跳转被找到。我已经包含了宏定义文件“stm32l0xx_hal_conf.h”,宏定义”HAL_DAC_MODULE_ENABLED“也使能了,添加的文件中变量也能成功跳转找到“stm32l0xx_hal_dac.h”中的定义,为什么会报错!

后来,我在整理main.c文件发现,其添加的头文件是“stm32l0xx_hal.h”,而不是文件“stm32l0xx_hal_conf.h”,于是,我将自己添加文件中改为

#include "stm32l0xx_hal.h" 

再次编译工程,居然编译成功了。其中的原因,我还没有想明白,想明白了再回来补上。如果有大神知道原因,请指教!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章