刚开始学习STM32,我在添加库文件的时候将全部外设的.c文件都添加进去了。

我是想在stm32f10x_config.h中配置的,我需要使用那些外设就将其头文件包含进来即可。实际上的情况是,我只包含了两个头文件,可是编译的时候却将全部的外设.c文件全部包含进来。请问这是为什么?谢谢。

#include "stm32f10x_conf.h"这个文件里已经把所有的给包含进去了,


#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"、



你需要把那些不需要的给注释掉。。。。不行的话欢迎反馈交流

追问

我就是这个样子做的,可是编译的时候为什么还是都给编译进去了?

追答

不好意思,开始没看清下边的详细描述,理解错问题了。。。c文件只要包含进来就会被编译的,编译时你看下边的Build Output框,它就是按照上下顺序把你的工程里的每一个c文件给编译一遍,至于你说的想在stm32f10x_config.h来注释掉头文件的方法来阻止它编译那些文件是行不通的。。相反,如果例如你把在里面把#include "stm32f10x_gpio.h"注释掉,但是仍然包含了stm32f10x_gpio.c而且用到了stm32f10x_gpio.h里面定义的各种变量(如GPIO_Pin_8,GPIO_Pin_Mode什么的),就会报错,如下就是我测验的结果:


..\..\Include\SD\sdio_sdcard.c(141): error:  #20: identifier "GPIO_InitTypeDef" is undefined
..\..\Include\SD\sdio_sdcard.c(156): error:  #20: identifier "GPIO_Pin_8" is undefined
..\..\Include\SD\sdio_sdcard.c(156): error:  #20: identifier "GPIO_Pin_9" is undefined
..\..\Include\SD\sdio_sdcard.c(156): error:  #20: identifier "GPIO_Pin_10" is undefined
..\..\Include\SD\sdio_sdcard.c(156): error:  #20: identifier "GPIO_Pin_11" is undefined

很多错误的。。。


这个原则就是:用到什么外设就包含什么外设的c文件,然后在stm32f10x_config.h里把相应头文件给包含进来。。。。


我个人理解这样的。。我也是才学stm32一年吧,没怎么搞

温馨提示:内容为网友见解,仅供参考
第1个回答  2014-03-07
在编写C程序时,
我们用到的已经有的文件用include<***.*>添加,
然后***.*里面又有各种###.#,
所以在编译时,凡是引用到的文件,编译器都会添加到你写的程序里面。这样编译才不会出错。
第2个回答  2014-03-17
你把很多源文件加到了一个工程里面 你编译这个工程肯定会编译这个.c文件的 在config.h中只是确定调不调用 和编不编译那个.c文件是两码事
第3个回答  推荐于2018-06-06
stm32f10x.h 中有语句

#ifdef USE_STDPERIPH_DRIVER
#include "stm32f10x_conf.h"
#endif

USE_STDPERIPH_DRIVER 在keil中有定义 所以包含了 stm32f10x_conf.h本回答被网友采纳
相似回答