Punctual atom STM32F103ZET6 study notes - new library function project template

STM32F10x series official firmware package free download link


Create a new STM32 project

Step 1: Create a project file

1. Create a new project directory temp

2. Create four new folders under the project directory temp

(1) USER : store the project file (template), the main function file main.c, and system_stm32f10x.c, etc.

(2) CORE : store core files and startup files.

(3) OBJ : store the compilation process files and hex files.

(4) STM32F103 : store the library function source code files officially provided by ST.

Project directory preview:

 3. Name the new project template and save it in the USER folder, and build the project according to the steps in the picture

 

 

 Step 2: Import the files in the stm32 firmware library

1. Open the STM32F10x firmware library file (the free download link is at the top of the article)

(1) Go to: STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\STM32F10x_StdPeriph_Driver, copy the src and inc folders under the directory to the STM32F103 folder we just created. src stores the .c file of the firmware library, and inc stores the corresponding .h file.
details as follows:
 

(2) Navigate to the directory: STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\CoreSupport, copy the file core_cm3.c and the file core_cm3.h to CORE. Then locate 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. Here we have explained that chips with different capacities use different startup files. Our chip STM32F103ZET6 is a large-capacity chip, so choose this startup file.

details as follows:

(3) Navigate to the directory: STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x, copy the three files inside stm32f10x.h, system_stm32f10x.c , system_stm32f10x.h to our 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.

The effect is as follows: (if there are LIistings and Objects folders, there is no effect)

 Step 3: Add all the previous files to the project

1. Add three folders USER, CORE, FYLIB under the project

(1) Right-click Target1, select Manage Components, change Target 1 to template according to the picture, delete Source Group 1 and create three folders USER, CORE, and FWLIB, and finally click OK:

(2) Add corresponding files to USER, CORE, FWLIB folders.
        1) Right-click the template, select Manage Components, select FWLIB, click Add Files, locate the existing folder STM32F103\src, and add all files to FWLIB (here all files are added to FWLIB for later use).
Effect preview:

  

         2) Use the same method to add corresponding files to the USER and CORE folders respectively. Here, the files that need to be added under our CORE are core_cm3.c, startup_stm32f10x_hd.s ( note that the file type is .c when added by default, that is, when adding startup_stm32f10x_hd.s startup file, you need to select the file type as All files to You can see this file ) , the files that need to be added under the USER directory are main.c, stm32f10x_it.c, system_stm32f10x.c, and finally click OK.

The effect is as follows: 

2. Set the location where the hex file is generated, the header file path and the macro definition

(1) Set the hex generation location: click the magic wand, select Output, click Select Folder for Objects, and locate it under the OBJ folder (if you do not set Output, the files generated by MDK5 compilation will be stored in the Listings and Objects folders).

(2) Set the header file path and macro definition global variables: Click the magic wand, select c/c++, click the button on the right of Include Path, a window for setting Path will pop up, and then we will add the three directories above the picture. Remember, keil will only search in the first-level directory, so if there are sub-directories under your directory, remember that the path must locate the last-level sub-directory. Then click OK, return to the c/c++ interface and fill in "STM32F10X_HD, USE_STDPERIPH_DRIVER" in the Define input box. Let me explain here, if you are using medium capacity, then modify STM32F10X_HD to STM32F10X_MD, and modify small capacity to STM32F10X_LD. Then click OK.

details as follows:

 

Step 4: Modify the main function and generate a hex file

1. Change the code in main.c under USER to the following code (the code provided for the punctual atom):

#include "stm32f10x.h"

void Delay(u32 count)
{
   u32 i=0;
   for(;i<count;i++);
}

int main(void)
{	
  GPIO_InitTypeDef  GPIO_InitStructure;
	 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|
  RCC_APB2Periph_GPIOE, ENABLE);	    //使用PE,PB端口时钟
  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);	  	       //初始化GPIO
  GPIO_SetBits(GPIOE,GPIO_Pin_5); 			 //PE.5输出高	  
  while(1)
	{
	  GPIO_ResetBits(GPIOB,GPIO_Pin_5);
	  GPIO_SetBits(GPIOE,GPIO_Pin_5);
		Delay(3000000);
		GPIO_SetBits(GPIOB,GPIO_Pin_5);
		GPIO_ResetBits(GPIOE,GPIO_Pin_5);
		Delay(3000000);
	}
}

2. Generate hex file

(1) Click the magic wand, enter the configuration menu, and select Output. Then tick the next three options. Among them, Create HEX file is to compile and generate a hex file , and Browser Information is to view variable and function definitions.

(2) After setting the above steps, download the hex file to the microcontroller with flymcu software, and you can observe that the two LED lights flash alternately.

Step 5: Add SYSTEM file

SYSTEM file

1. According to step 3, create a new SYSTEM folder in the project, and add delay.c, sys.c, usart.c in the provided SYSTEM file to the project folder SYSTEM.

The effect is as follows:

 2. Add the subdirectories delay, sys, and usart under the SYSTEM folder to Path according to the method of setting header files in step 3.2.

details as follows:

 At this point, the new project template has been set up, and finally remember to save all the files, otherwise it will be a waste of work.

Guess you like

Origin blog.csdn.net/qq_63306482/article/details/126180744