[STM32] Detailed explanation of creating project templates for STM32F103ZET6 (firmware library)

00. Table of Contents

01. Firmware Library Overview

In order to facilitate users to develop programs, ST (STMicroelectronics) provides a rich set of STM32 standard peripheral function libraries, referred to as firmware libraries .

Firmware library version :

STM32F10x_StdPeriph_Lib_V3.5.0

02. Create project steps

2.1 Before creating the project, we create a folder named 00_Template under a certain directory on the computer.

The author's directory is E:\Program Data\Keil\00_Template

2.2 Create four directories under the above 00_Template directory

Insert image description here

CORE is used to store core files and startup files, OBJ is used to store compilation process files and hex files, and the STM32F10x_FWLib folder, as its name implies, is used to store library function source code files officially provided by ST.

2.3 Click the menu of MDK: Project –> New Uvision Project,

Insert image description here

2.4 Locate the directory under the folder 00_Template just created, and then locate it under the USER directory. Our project files will be saved under the USER folder. Name the project Template and click Save.

Insert image description here

2.5 Selecting the CPU interface means selecting our chip model.

STMicroelectronics→STM32F1 Series→STM32F103→STM32F103ZET6 (if you are using other series of chips, just select the corresponding model)

Insert image description here

Kind tips

You must install the corresponding device pack to display these contents!

2.6 MDK will pop up the Manage Run-Time Environment dialog box, click Cancel.

Insert image description here

2.7 After clicking Cancel, you will get the following interface

Insert image description here

2.8 Copy the src and inc folders under the firmware library directory to the STM32F10x_FWLib folder we just created.

Firmware library directory: STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\STM32F10x_StdPeriph_Driver

Destination directory: 00_Template\STM32F10x_FWLib

Insert image description here

2.9 Copy the relevant startup files in the firmware library package to our project directory CORE.

STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\CoreSupport Next, copy the file core_cm3.c and the file core_cm3.h to the CORE directory.

2.10 Copy the startup_stm32f10x_hd.s file inside to CORE

Navigate to the directory STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\a
rm and copy the startup_stm32f10x_hd.s file inside to CORE.

Insert image description here

2.11 Copy the three files stm32f10x.h, system_stm32f10x.c, system_stm32f10x.h to our USER directory.

STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x Next, copy the three files stm32f10x.h, system_stm32f10x.c, system_stm32f10x.h to our USER directory.

2.12 Copy the four files main.c, stm32f10x_conf.h, stm32f10x_it.c, stm32f10x_it.h to the USER directory.

Then copy the four files main.c, stm32f10x_conf.h, stm32f10x_it.c, stm32f10x_it.h under STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template to the USER directory.

Insert image description here

2.13 Add the above files to our project. Right-click Target1 and select Manage Project Items.

Insert image description here

2.14 In the Project Targets column, we change the Target name to Template, then delete a SourceGroup1 in the Groups column and create three Groups: USER, CORE, and FWLIB. Then click OK.

Insert image description here

2.15 Right-click on Tempate, select Manage Project Itmes, then select the Group to which files need to be added and add the corresponding files.

We select FWLIB, then click Add Files on the right, navigate to the directory we just created, under STM32F10x_FWLib/src, select all the files in it (Ctrl+A), then click Add, and then Close.

The files that need to be added under CORE are core_cm3.c and startup_stm32f10x_hd.s (note that the file type is .c when added by default, that is, when adding the startup_stm32f10x_hd.s startup file, you need to select the file type as All files to see this document),

The files that need to be added under the USER directory are main.c, stm32f10x_it.c, system_stm32f10x.c. In this way, the files we need to add have been added to our project, and finally click OK
Insert image description here

2.16 Select the directory where intermediate files will be stored after compilation

Before compiling, we must first select the directory where the intermediate files will be stored after compilation. The method is to click the magic wand, then select "Select folder for objects..." under the "Output" option, and then select the directory as the OBJ directory we created above. Please note here that if we do not set the Output path, the default compilation intermediate file storage directory is the Objects directory and Listings directory automatically generated by MDK.

Insert image description here

2.17 Set header file directory

For any project, we need to include the paths of all header files referenced in the project. Return to the project main menu, click the magic wand, a menu will pop up, then click the c/c++ option. Then click the button to the right of Include Paths. A dialog box for adding path pops up, and then we add the three directories above. Remember, keil will only search in the first-level directory, so if there are subdirectories under your directory, remember that the path must be located at the last subdirectory. Then click OK.

Insert image description here

What happens after adding the directory

Insert image description here

2.18 Add macro definition

STM32F10X_HD,USE_STDPERIPH_DRIVER

Insert image description here

2.19 Copy main.c and change it to the following code

#include "stm32f10x.h"

//初始化PB5和PE5为输出口.并使能这两个口的时钟		    
//LED IO初始化
void LED_Init(void)
{
    
    
	GPIO_InitTypeDef  GPIO_InitStructure;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE, ENABLE);	 //使能PB,PE端口时钟
	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;				 //LED0-->PB.5 端口配置
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;		 //IO口速度为50MHz
	GPIO_Init(GPIOB, &GPIO_InitStructure);					 //根据设定参数初始化GPIOB.5
	GPIO_SetBits(GPIOB,GPIO_Pin_5);						 //PB.5 输出高

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;	    		 //LED1-->PE.5 端口配置, 推挽输出
	GPIO_Init(GPIOE, &GPIO_InitStructure);	  				 //推挽输出 ,IO口速度为50MHz
	GPIO_SetBits(GPIOE,GPIO_Pin_5); 						 //PE.5 输出高 
}
 
 void delay_ms(u32 count)
 {
    
    
	u32 i=0;
	for(;i<count * 10000;i++);
 }

 
int main(void)
{
    
     
	LED_Init();		        //初始化LED端口
	while(1)
	{
    
    
		GPIO_ResetBits(GPIOB,GPIO_Pin_5);  //LED0对应引脚GPIOB.5拉低,亮  等同LED0=0;
		GPIO_SetBits(GPIOE,GPIO_Pin_5);   //LED1对应引脚GPIOE.5拉高,灭 等同LED1=1;
		delay_ms(300);  		   //延时300ms
		
		GPIO_SetBits(GPIOB,GPIO_Pin_5);	   //LED0对应引脚GPIOB.5拉高,灭  等同LED0=1;
		GPIO_ResetBits(GPIOE,GPIO_Pin_5); //LED1对应引脚GPIOE.5拉低,亮 等同LED1=0;
		delay_ms(300);                     //延时300ms
	}
} 

2.20 configuration allows the hex file to be generated after compilation.

Also click the magic wand to enter the configuration menu and select Output. Then check the three options above and below. Among them, Create HEX file is compiled to generate a hex file, and Browser Information allows you to view variable and function definitions.

Insert image description here

2.21 Compile the entire project. If no errors are reported, the entire project has been created.

03. Discussion

Reference: [STM32] STM32F103C8T6 non-ASM statement in naked function is not supported

04. Appendix

Guess you like

Origin blog.csdn.net/dengjin20104042056/article/details/133436710