STM32新建工程出现已包含“stm32f10x.h”头文件但依然提示部分固件库变量未定义的问题
进入"stm32f10x.h"里面,有出现下列条件编译:
#ifdef USE_STDPERIPH_DRIVER
#include "stm32f10x_conf.h"
#endif
其中"stm32f10x_conf.h"含了所有固件库的头文件,如下图所示:
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F10x_CONF_H
#define __STM32F10x_CONF_H
/* Includes ------------------------------------------------------------------*/
/* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */
#include "stm32f10x_adc.h"
#include "stm32f10x_bkp.h"
#include "stm32f10x_can.h"
#include "stm32f10x_cec.h"
#include "stm32f10x_crc.h"
#include "stm32f10x_dac.h"
#include "stm32f10x_dbgmcu.h"
#include "stm32f10x_dma.h"
#include "stm32f10x_exti.h"
#include "stm32f10x_flash.h"
#include "stm32f10x_fsmc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_i2c.h"
#include "stm32f10x_iwdg.h"
#include "stm32f10x_pwr.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_rtc.h"
#include "stm32f10x_sdio.h"
#include "stm32f10x_spi.h"
#include "stm32f10x_tim.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_wwdg.h"
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
所以需要宏定义 USE_STDPERIPH_DRIVER(见上面文章第一段代码),编译器才会将“stm32f10x_conf.h”包含在“stm32f10x.h"里面。
解决方法
方法一:在 “Options for Target ‘projectName’ ” ——> “C/C++” ——> “Preprocessor Symbols” ——> “Define”栏里面填入:USE_STDPERIPH_DRIVER。
方法二:在上面文章第一段代码前面加入:#define USE_STDPERIPH_DRIVER,如下:
#define USE_STDPERIPH_DRIVER
#ifdef USE_STDPERIPH_DRIVER
#include "stm32f10x_conf.h"
#endif