STM32新建工程出现已包含“stm32f10x.h”头文件但依然提示部分固件库变量未定义的问题

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
  • 13
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
由于STM32F10x.h头文件比较大,这里只展示其中部分主要内容的代码。完整的STM32F10x.h头文件可以在STMicroelectronics官网上下载。 ```c #ifndef __STM32F10x_H #define __STM32F10x_H #include "core_cm3.h" // CMSIS头文件包含Cortex-M3内核相关的宏和函数 // 定义STM32F10x系列微控制器的型号,例如STM32F103xB #if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && \ !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL) #define STM32F10X_LD #endif // 定义STM32F10x系列微控制器的系统时钟频率 #if !defined HSI_VALUE #define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ #if !defined HSE_VALUE #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ #define SYSCLK_FREQ_HSI HSI_VALUE /*!< System clock frequency with HSI as reference clock */ #define SYSCLK_FREQ_72MHz 72000000UL /*!< System clock frequency with PLL enabled and HSE as reference clock */ // 定义一些常用的类型和宏 typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus, BitStatus; typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus; #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) #define IS_FLAG_STATUS(STATUS) (((STATUS) == RESET) || ((STATUS) == SET)) #define IS_IT_STATUS(STATUS) (((STATUS) == RESET) || ((STATUS) == SET)) #define IS_BIT_STATUS(STATUS) (((STATUS) == RESET) || ((STATUS) == SET)) #define IS_ERROR_STATUS(STATUS) (((STATUS) == ERROR) || ((STATUS) == SUCCESS)) // 定义IO口类型 typedef struct { __IO uint32_t CRL; __IO uint32_t CRH; __IO uint32_t IDR; __IO uint32_t ODR; __IO uint32_t BSRR; __IO uint32_t BRR; __IO uint32_t LCKR; } GPIO_TypeDef; // 定义外设寄存器类型 typedef struct { __IO uint32_t CR1; __IO uint32_t CR2; __IO uint32_t SR; __IO uint32_t DR; __IO uint32_t CRCPR; __IO uint32_t RXCRCR; __IO uint32_t TXCRCR; __IO uint32_t I2SCFGR; } SPI_TypeDef; // 定义一些常用的函数 void NVIC_EnableIRQ(IRQn_Type IRQn); void GPIO_Init(GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, uint32_t GPIO_Mode); #endif /* __STM32F10x_H */ ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值