STM32 learning experience II: New Project Template

Record what the future ~ easy to read
features: Reference punctual atomic instructional videos, firmware library templates / register template (formerly fonts are a common part, bold step template is a library function , italics register template step ).
1) Create a new empty folder (name Custom) used to store all future development process of developing a project, in that folder, create a new empty folder USER (USER recommended name);
2) MDK software program, click project → New μVision project Create a new project, enter the project file name, choose a good chip click the OK;
Here Insert Picture Description
Here Insert Picture Description
3) in the USER folder, Listings and Objects two folders used to store intermediate files generated during compilation (for now MDK5 compatible version before .1).
New CORE (core files and boot files), OBJ (compilation file and hex file), STM32F10x_FWLib (library function source file) three empty folders (folders tied with USER).
Here Insert Picture Description
Here Insert Picture Description
New CORE (core files and boot files) and OBJ (compilation file and hex file) two empty folder (the folder USER tied);

4) The STM32F10x_StdPeriph_Lib_V3.5.0 \ Libraries \ STM32F10x_StdPeriph_Driver in the src (storage of firmware library .c file), inc (stored corresponding .h file) two folders to STM32F10x_FWLib folder;
5) the STM32F10x_StdPeriph_Lib_V3.5.0 \ Libraries \ CMSIS \ CM3 \ CoreSupport in the core_cm3.c and core_cm3.h copied to the CORE folder;
6) the STM32F10x_StdPeriph_Lib_V3.5.0 \ Libraries \ CMSIS \ CM3 \ DeviceSupport \ ST \ STM32F10x \ startup \ arm in the startup_stm32f10x_hd.s copy [1] to file folder CORE, CORE this case there are three file folder;
Here Insert Picture Description
copy STM32F10x_StdPeriph_Lib_V3.5.0 \ Libraries \ CMSIS \ CM3 \ DeviceSupport \ ST \ STM32F10x \ startup \ arm in the file to the CORE startup_stm32f10x_hd.s folder;

7) The STM32F10x_StdPeriph_Lib_V3.5.0 \ Libraries \ CMSIS \ CM3 \ DeviceSupport \ ST \ STM32F10x in the stm32f10x.h, system_stm32f10x.c, system_stm32f10x.h copied to the USER folder;
8) will STM32F10x_StdPeriph_Lib_V3.5.0 \ Project \ STM32F10x_StdPeriph_Template Lane main.c, stm32f10x_conf.h, stm32f10x_it.c, stm32f10x_it.h copied to the USER folder, then USER folder more than seven files;
Here Insert Picture Description

9) in MDK software, right Target1, click the Manage Project Items ..., in Project Items interface, Groups column, delete the Source Group 1, the new USER, CORE, FWLIB, click OK (this can also rename Target1);
Here Insert Picture Description
in MDK software, right Target1, click the Manage Project Items ..., in Project Items interface, Groups column, delete the Source Group 1, the new USER, CORE click OK (this can also rename Target1);

10) In the MDK software, before the return to Manage Project Items interface, Project Items interface, select FWLIB, click Add Files, choose STM32F10x_FWLib \ src, check inside all of the .c file, click Add (in fact, just add .c files need to use);
11) selected CORE, click Add files, add in the CORE folder in the core_cm3.c and startup_stm32f10x_hd.s;
select CORE, click Add files, the CORE folder in the startup_stm32f10x_hd. s [3] add in;
12) to select USER, click Add files, add in the USER folder in main.c, stm32f10x_it.c and system_stm32f10x.c;
in MDK software, create a new file test.c (ie, the main function files [2], the name can be customized), stored in the USER folder, then Manage Project Items interface, Project Items option, select USER, add just the new .c files come in);
13) in MDK software , click the magic wand in the Output option, check Create HEX file, click select folder for Objects, select the OBJ file folder (to give up the compilation process files stored in Listings and Objects in);
Here Insert Picture Description

Here Insert Picture Description
14) In the C / C ++ option, click the Include Paths of ... the right to add three header files directory, enter STM32F10X_HD, USE_STDPERIPH_DRIVER in the Define Lane;

Here Insert Picture Description
Here Insert Picture Description
In the C / C ++ option, the Define a column input STM32F10X_HD;

15) At this point, the project template has been created. Next, add common code ALIENTEK provided. SYSTEM folder will be copied to the project file (with the USER folder tied), in MDK software, right Target1, click the Manage Project
the Items ... in the Project Items interface, Groups column, the new SYSTEM, select SYSTEM, click Add files, add the SYSTEM folder of sys.c, delay.c and usart.c come in, and then click the OK;
16) click the magic wand in C / C ++ option, click the Include Paths of ... the right to add SYSTEM folder of three headers, new construction template finalized.
Notes:
[1] is a piece of hardware-startup_stm32f10x_hd.s assembly code, the main functions: 1) to initialize the stack (SP); and 2) initializing the program counter (PC); 3) address of the vector table entry is provided exception event; 4 ) Main function call. ST companies have three files, corresponding to different chips STM32:
startup_stm32f10x_ld.s FLASH≤32K corresponding to the STM32 chip;
startup_stm32f10x_md.s 64K≤FLASH≤128K corresponding to the STM32 chip;
startup_stm32f10x_hd.s 256K≤FLASH corresponding to the STM32 chip.
[2] The main function template file may register to write: `` `

#include “sys.h”
#include “usart.h”
#include “delay.h”

int main(void)
{
      u8 t=0;
      Stm32_Clock_Init(9);       //系统时钟设置
      delay_init(72);            //延时初始化
      uart_init(72,115200);       //串口初始化为115200
      while(1)
      {
           printf(“t:%d\r\n”,t);
           delay_ms(500);
           t++;
       }
}

[3] startup_stm32f10x_hd.s difference register templates and template library functions that need to register the template Note three lines of code:

;IMPORT  SystemInit
;LDR     R0, =SystemInit
;BLX     R0 
Published 24 original articles · won praise 2 · Views 4131

Guess you like

Origin blog.csdn.net/Leisure_ksj/article/details/105034333