转自正点原子的回复)
标准的工程新建办法,是要添加" 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里面,有没有注释掉对应外设的头文件.