天天看點

stm32f10x_conf.h 與 stm32f10x.h

stm32f10x_conf.h 與 stm32f10x.h  

剛才編寫stm32外設的程式時注意到,新版的固件庫V3.0以上 main等源檔案中不再直接包含stm32f10x_conf.h,而是stm32f10x.h,stm32f10x.h則定義了啟動設定,以及所有寄存器宏定義,此檔案中需要注意的有:

1、device選擇

#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL)

&& !defined (STM32F10X_XL) && !defined (STM32F10X_CL) 

  /* #define STM32F10X_LD */     /*!< STM32F10X_LD: STM32 Low density devices */

  /* #define STM32F10X_LD_VL */  /*!< STM32F10X_LD_VL: STM32 Low density Value Line devices */  

  /* #define STM32F10X_MD */     /*!< STM32F10X_MD: STM32 Medium density devices */

   #define STM32F10X_MD

  /* #define STM32F10X_MD_VL */  /*!< STM32F10X_MD_VL: STM32 Medium density Value Line devices */  

  /* #define STM32F10X_HD */     /*!< STM32F10X_HD: STM32 High density devices */

  /* #define STM32F10X_HD_VL */  /*!< STM32F10X_HD_VL: STM32 High density value line devices */  

  /* #define STM32F10X_XL */     /*!< STM32F10X_XL: STM32 XL-density devices */

  /* #define STM32F10X_CL */     /*!< STM32F10X_CL: STM32 Connectivity line devices */

#endif

此段代碼在stm32f10x.h的開始處,根據所用的器件 取消合适的注釋。我常用的是stm32f103c8t6  屬于Medium density Value Line devices.

2、外部時鐘頻率選擇

#if !defined  HSE_VALUE

 #ifdef STM32F10X_CL   

  #define HSE_VALUE    ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */

 #else 

  #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */

 #endif /* STM32F10X_CL */

#endif /* HSE_VALUE */

注意STM32F10X_CL,STM32F10X_CL是stm32f105 和stm32f107 互聯型的device,用到此器件外部要選用25MHz的晶體,由于前面的代買沒有取消  /* #define STM32F10X_CL */     /*!< STM32F10X_CL: STM32 Connectivity line devices */的注釋,是以此處預設的外部8MHz的晶體

3、外設宏定義USE_STDPERIPH_DRIVER

#if !defined  USE_STDPERIPH_DRIVER

/**

 * @brief Comment the line below if you will not use the peripherals drivers.

   In this case, these drivers will not be included and the application code will 

   be based on direct access to peripherals registers 

   */

  /*#define USE_STDPERIPH_DRIVER*/

如果不适用片内外設,則不要取消  /*#define USE_STDPERIPH_DRIVER*/的注釋

注意stm32f10x.h檔案的最後有這樣的代碼:

#ifdef USE_STDPERIPH_DRIVER

  #include "stm32f10x_conf.h"

stm32f10x_conf.h中包含了所有外設的頭檔案,是以任意源檔案隻要包含了stm32f10x.h,就可以在源檔案調用任意外設的函數。

若有外設為使用到,在stm32f10x_conf.h注釋相應部分,項目編譯時就不會在編譯去掉的外設。

繼續閱讀