我是想在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一年吧,没怎么搞