Keil新建Stm32标准工程中 Preprocessor Symbols的作用

(转自正点原子的回复)

标准的工程新建办法,是要添加" USE_STDPERIPH_DRIVER,STM32F10X_HD的.
USE_STDPERIPH_DRIVER,是告诉编译器,我们需要使用标准库了(实际上是.c/.h文件里面的一个宏,通过这个宏决定是不是要用某些资源,比如库函数的使用)
STM32F10X_HD,则是表示我们使用的芯片是大容量的stm32,从而告诉那些.c/.h文件,使用相关代码.

另外,很重要的一个文件,常被初学者忽略,那就是:stm32f10x_conf.h
很多库函数相关的.h文件,是在这个里面被包含进来的.
所以你很多时候,只看到我们代码包含了stm32f10x.h了,事实上,由于我们定义了:USE_STDPERIPH_DRIVER,所以在stm32f10x.h里面,会包含:stm32f10x_conf.h
而stm32f10x_conf.h会包含各种外设的.h文件,如下:
#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"
..............


这样,我们就把这些.h文件添加到了你的工程里面,上面的代码,我们很多.h文件都是被屏蔽了,所以如果你在使用的时候,遇到提示对应外设的定义没有而出错的时候,不妨看看你的stm32f10x_conf.h里面,有没有注释掉对应外设的头文件.

  • 15
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值