<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          STM32庫(kù)函數(shù)配置

          作者: 時(shí)間:2016-12-02 來(lái)源:網(wǎng)絡(luò) 收藏
          stm32固件庫(kù)V3.0以上的版本,main等源文件中不再直接包含stm32f10x_conf.h,而是stm32f10x.h,stm32f10x.h則定義了啟動(dòng)設(shè)置,以及所有寄存器宏定義,此文件中需要注意的有:

          使用V3.0以上版本固件庫(kù)的方法如下:

          本文引用地址:http://www.ex-cimer.com/article/201612/325031.htm

          1.選擇device(配置函數(shù)STM32F10x.h,具體配置方法如下)

          在STM32F10x.h中有如下代碼:

          #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_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

          該代碼的是讓用戶根據(jù)自己所使用的芯片的存儲(chǔ)器(flash)大小,選擇相應(yīng)的flash編程算法,如果用戶使用的是大容量存儲(chǔ)芯片(如STM32F103VCT6),則只需要將對(duì)應(yīng)大大容量存儲(chǔ)器前面的屏蔽符去掉即可,去掉后為:

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

          其它部分代碼不變。

          如果使用的是中等容量的存儲(chǔ)器芯片(如stm32f103c8t6),同樣是將對(duì)應(yīng)代碼前面的屏蔽符去掉即可,如:

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

          2.時(shí)鐘頻率配置(配置函數(shù):system_stm32f10x.c,具體配置方法如下:)

          #if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)

          /* #define SYSCLK_FREQ_HSEHSE_VALUE */

          #define SYSCLK_FREQ_24MHz24000000

          #else

          /* #define SYSCLK_FREQ_HSEHSE_VALUE */

          /* #define SYSCLK_FREQ_24MHz24000000 */

          /* #define SYSCLK_FREQ_36MHz36000000 */

          /* #define SYSCLK_FREQ_48MHz48000000 */

          /* #define SYSCLK_FREQ_56MHz56000000 */

          #define SYSCLK_FREQ_72MHz72000000

          #endif

          由上述代碼可見(jiàn)默認(rèn)是使用72MHz的時(shí)鐘頻率,如果需要使用其它頻率,只需做相應(yīng)的修改即可,如果使用的是72MHz時(shí)鐘頻率可以不用配置此項(xiàng)。

          3.選擇外部時(shí)鐘(配置函數(shù)stm32f10x.h,具體配置方法如下:)

          #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是stm32f105和stm32f107互聯(lián)型的device,用到此器件外部要選用25MHz的晶體,由于前面的代買沒(méi)有取消/* #define STM32F10X_CL */ /*!< STM32F10X_CL: STM32 Connectivity line devices */的注釋,所以此處默認(rèn)的外部8MHz的晶體。

          4.開啟外設(shè)總開關(guān)USE_STDPERIPH_DRIVER(配置函數(shù):stm32f10x.h,具體配置方法如下:)

          #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*/

          #endif

          默認(rèn)情況下STM32的標(biāo)準(zhǔn)是關(guān)閉的,如果不適用片內(nèi)外設(shè),則不要取消/*#define USE_STDPERIPH_DRIVER*/的注釋

          ,如果需要使用STM32的標(biāo)準(zhǔn)外設(shè)則需要開啟固件外設(shè),即去掉前面的屏蔽符,修改后如下:

          #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

          #endif

          5.最后一步是開啟需要使用的外設(shè)(配置函數(shù):stm32f10x_config.h,具體配置步驟如下:)

          /* Includes ------------------------------------------------------------------*/

          /* Uncomment the line below to enable 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" */

          /*#include "misc.h" *//* High level functions for NVIC and SysTick (add-on to CMSIS functions) */

          默認(rèn)是關(guān)閉所有外設(shè)的,用戶需要使用哪個(gè)外設(shè),就將該外設(shè)前面的注釋去掉即可。

          到這里庫(kù)函數(shù)的配置就全部介紹完畢了,建一個(gè)工程需要修改這么多配置是不是太麻煩了呢,的確是比較麻煩,最后再給大家介紹一種簡(jiǎn)單的配置方法,用宏定義配置這些參數(shù),keil MDk支持在編譯器中添加宏定義,這里就以keil MDK為例,給大家介紹。

          先在keil MDK中點(diǎn)擊tagart option選項(xiàng),彈出如下圖所示窗口:

          然后點(diǎn)擊C/C++選項(xiàng),彈出如下窗口:

          最后在Difine的方框中添加上需要聲明的宏定義即可。

          這里總結(jié)一下一般工程中需要添加的宏定義:

          1.STM32F10X_HD//選擇用戶所使用芯片的存儲(chǔ)器容量(這里選擇的是大容量存儲(chǔ))

          2.USE_STDPERIPH_DRIVER//打開標(biāo)準(zhǔn)外設(shè)總開關(guān)

          3.SYSCLK_FREQ_72MHz//選擇時(shí)鐘頻率(默認(rèn)也是該選項(xiàng))

          4.HSE_VALUE//選擇使用外部高速時(shí)鐘(默認(rèn)也是該選項(xiàng))

          注意:stm32f10x.h文件的最后有這樣的代碼:

          #ifdef USE_STDPERIPH_DRIVER

          #include "stm32f10x_conf.h"

          #endif

          stm32f10x_conf.h中包含了所有外設(shè)的頭文件,因此任意源文件只要包含了stm32f10x.h,就可以在源文件調(diào)用任意外設(shè)的函數(shù)。

          若有外設(shè)為使用到,在stm32f10x_conf.h注釋相應(yīng)部分,項(xiàng)目編譯時(shí)就不會(huì)在編譯去掉的外設(shè)。



          關(guān)鍵詞: STM32庫(kù)函數(shù)配

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();