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裏面,有沒有註釋掉對應外設的頭文件.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章