STM32新建工程步骤
? 1、? 新建工程,然后选择芯片型号。 选定芯片后添加启动文件.s文件。 2、? 将文件添加组进行分类: 其中包含ASM组、USR组、FWlib组合CMSYS组。 l? ASM组为.s启动文件; l? USR组为用户程序文件组,一般至少需要有main.c,如需要使用中断,将stm32fxxx_it.c也放在该组中; l? FWlib组为ST公司提供的官方库文件,如下图所示, 将SRC中的.c文件进行有选择的选入,只选择需要的,免得编译过程太费时,inc文件夹中文.h头文件,可在Target Options中设置包含头文件的路径,将在Target Options设置中具体说明。SRC资源如下所示。 CMSYS组由系统内核文件以及芯片系列应用组成,一下分别为1系列和2系列的CM组CMSYS。 System_stm32fxxx.c主要为系统时钟的定义,如果用到外部时钟,需要进行外部时钟的初始化和配置。 3、? 根据芯片类型配置相应文件。 stm32fxxx.h文件的配置: 对于f1系列,需要进行芯片类型选择,如下图所示, 并且将 中的#define USE_STDPERIPH_DRIVER注释去掉, ,如果不去掉注释,也可以在Target Options中的C/C++中定义,如下图所示。 对于f2系列则无芯片类型选择,后面的去掉注释同f1系列。 4、? Target Options设置。 Target:选外部晶振,并勾选Use MicroLIB Output:如果需要输出Hex,则勾选生成hex文件选项,一般选上为好。 C/C++:Define: 如果定义USE_STDPERIPH_DRIVER,就可以使用"stm32f2xx_conf.h"头文件,该头文件中是用来使能所有需要用到的外设功能。"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设置头文件的路径,务必设置正确,否则可能无法找到头文件进行正常的编译。 勾选ELF,这样不需要用到的程序就不会编译。 Linker:使用选定芯片的存储器空间,因为你开始已定义芯片类型,会自动映射正确的存储空间。如不勾选,则务必确保存储空间设置正确。 Debug:根据具体要求来选择,如果用J-Link,则如下图选择J-Link,如使用ULINK等其他设备进行下载,则进行相应的修改。并且别忘了勾选Run to main()。 选定J-link后点击Settings进行设置。 只要连接上J-link,在Debug下便会出现类似于下面的信息,前提是你装了J-link的驱动。 在Flash Download中单击Add添加处理器的Flash大小,根据具体型号选择。模式里面可以选择清空整个芯片或者只清空段,或者不清除,一般选择清除段。 ? ? Utilities:选择下载器类型。 ? ? 由以上步骤,工程建立的设置工作已经结束,可以进行程序的编译和下载工作。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |