1、新建工程,然后選擇芯片型號(hào)。
選定芯片后添加啟動(dòng)文件.s文件。
2、將文件添加組進(jìn)行分類:
其中包含ASM組、USR組、FWlib組合CMSYS組。
lASM組為.s啟動(dòng)文件;
lUSR組為用戶程序文件組,一般至少需要有main.c,如需要使用中斷,將stm32fxxx_it.c也放在該組中;
lFWlib組為ST公司提供的官方庫文件,如下圖所示,
將SRC中的.c文件進(jìn)行有選擇的選入,只選擇需要的,免得編譯過程太費(fèi)時(shí),inc文件夾中文.h頭文件,可在Target Options中設(shè)置包含頭文件的路徑,將在Target Options設(shè)置中具體說明。SRC資源如下所示。
CMSYS組由系統(tǒng)內(nèi)核文件以及芯片系列應(yīng)用組成,一下分別為1系列和2系列的CM組CMSYS。
System_stm32fxxx.c主要為系統(tǒng)時(shí)鐘的定義,如果用到外部時(shí)鐘,需要進(jìn)行外部時(shí)鐘的初始化和配置。
3、根據(jù)芯片類型配置相應(yīng)文件。
stm32fxxx.h文件的配置:
對(duì)于f1系列,需要進(jìn)行芯片類型選擇,如下圖所示,
并且將
中的#define USE_STDPERIPH_DRIVER注釋去掉,
,如果不去掉注釋,也可以在Target Options中的C/C++中定義,如下圖所示。
對(duì)于f2系列則無芯片類型選擇,后面的去掉注釋同f1系列。
4、Target Options設(shè)置。
Target:選外部晶振,并勾選Use MicroLIB
如果需要輸出Hex,則勾選生成hex文件選項(xiàng),一般選上為好。
Define:
如果定義USE_STDPERIPH_DRIVER,就可以使用"stm32f2xx_conf.h"頭文件,該頭文件中是用來使能所有需要用到的外設(shè)功能。"stm32f2xx_conf.h"包含了如下頭文件的定義。
/* Includes ------------------------------------------------------------------*/
/* Uncomment the line below to enable peripheral header file inclusion */
/* #include "stm32f2xx_adc.h" */
/* #include "stm32f2xx_can.h" */
/* #include "stm32f2xx_crc.h" */
/* #include "stm32f2xx_cryp.h" */
/* #include "stm32f2xx_dac.h" */
/* #include "stm32f2xx_dbgmcu.h" */
/* #include "stm32f2xx_dcmi.h" */
/* #include "stm32f2xx_dma.h" */
/* #include "stm32f2xx_exti.h" */
/* #include "stm32f2xx_flash.h" */
/* #include "stm32f2xx_fsmc.h" */
/* #include "stm32f2xx_hash.h" */
#include "stm32f2xx_gpio.h"
/* #include "stm32f2xx_i2c.h" */
/* #include "stm32f2xx_iwdg.h" */
/* #include "stm32f2xx_pwr.h" */
#include "stm32f2xx_rcc.h"
/* #include "stm32f2xx_rng.h" */
/* #include "stm32f2xx_rtc.h" */
/* #include "stm32f2xx_sdio.h" */
/* #include "stm32f2xx_spi.h" */
/* #include "stm32f2xx_syscfg.h" */
/* #include "stm32f2xx_tim.h" */
#include "stm32f2xx_usart.h"
/* #include "stm32f2xx_wwdg.h" */
/* #include "misc.h" *//* High level functions for NVIC and SysTick (add-on to CMSIS functions)*/
Include Paths:
在Include Paths設(shè)置頭文件的路徑,務(wù)必設(shè)置正確,否則可能無法找到頭文件進(jìn)行正常的編譯。
勾選ELF,這樣不需要用到的程序就不會(huì)編譯。
使用選定芯片的存儲(chǔ)器空間,因?yàn)槟汩_始已定義芯片類型,會(huì)自動(dòng)映射正確的存儲(chǔ)空間。如不勾選,則務(wù)必確保存儲(chǔ)空間設(shè)置正確。
根據(jù)具體要求來選擇,如果用J-Link,則如下圖選擇J-Link,如使用ULINK等其他設(shè)備進(jìn)行下載,則進(jìn)行相應(yīng)的修改。并且別忘了勾選Run to main()。
選定J-link后點(diǎn)擊Settings進(jìn)行設(shè)置。
只要連接上J-link,在Debug下便會(huì)出現(xiàn)類似于下面的信息,前提是你裝了J-link的驅(qū)動(dòng)。
在Flash Download中單擊Add添加處理器的Flash大小,根據(jù)具體型號(hào)選擇。模式里面可以選擇清空整個(gè)芯片或者只清空段,或者不清除,一般選擇清除段。
選擇下載器類型。
由以上步驟,工程建立的設(shè)置工作已經(jīng)結(jié)束,可以進(jìn)行程序的編譯和下載工作。