Tangwx

Tangwx

博客网站

02. Create a new STM32 project

2 Creating an STM32 Project#

2 Creating an STM32 Project#

2.1 STM32F10X Model Classification and Abbreviations#

STM32F103C8T6: The flash of C8T6 is 64K, so we choose the MD startup file.

AbbreviationMeaningFlash CapacityModel
LD_VLValue Line Low-density Product16~32KSTM32F100
MD_VLValue Line Medium-density Product64~128KSTM32F100
HD_VLValue Line High-density Product256~512KSTM32F100
LDLow-density Product16~32KSTM32F101/102/103
MDMedium-density Product64~128KSTM32F101/102/103
HDHigh-density Product256~512KSTM32F101/102/103
XLExtra Large Capacity ProductGreater than 512KSTM32F101/102/103
CLConnectivity Line Product-STM32F105/107

2.2 Steps to Create a New Project#

Create a project folder, create a new project in Keil, and select the model.

Create folders named Start, Library, User, etc. in the project folder, and copy the files from the firmware library to the project folder.

Create corresponding groups named Start, Library, User, etc. in the project, and add the files from the folders to the project groups.

In the project options, declare all folders that include header files in C/C++, Include Paths.

In the project options, define USE_STDPERIPH_DRIVER in C/C++, Define. Other projects also declare a string STM32F10x_MD here, but Keil5 automatically declares it for us when creating a new project, so there is no need to repeat the declaration.

In the project options, select the corresponding debugger from the drop-down list in Debug, Settings, Flash Download, and check Reset and Run.

2.3 Project Architecture Diagram#

image-20220809173713894

2.4 keil 5 New Project Structure Diagram#

image-20220821155147410

Start Folder:#

.s startup file, only one can be added in Keil software, this time we choose startup_stm32f10x_md.s startup file.

stm32f10x.h: STM32 peripheral register description file, similar to REGX52.h for 51 microcontrollers, used to describe which registers STM32 has and their corresponding addresses.

system_stm32f10x.c and system_stm32f10x.h files are used for clock configuration. The main frequency of STM32 is configured by the functions in the system files.

core_cm3.c and core_cm3.h files are the register descriptions of the core, and they also include some configuration functions for the core, so an additional .c file is added.

Then add the header file path of the Start folder in the project options, otherwise the software will not find the .h file.

Library Folder:#

The inc and src folders contain the .h and .c library files encapsulated by ST.

System Folder:#

The System folder contains system resources, such as delay.c and delay.h.

User Folder:#

main.c file.

stm32f10x_conf.h file is used to configure the inclusion relationship of library function header files, and it also contains a function definition for parameter checking, which is required for all library functions.

stm32f10x_it.c and stm32f10x_it.h files are used to store interrupt functions.

Wiring method:

image

ST-LINK V2STM32
3.3V3V3
SWDIOSWIO
SWCLKSWCLK
GNDGND

main.c

#include "stm32f10x.h"                  // Device header

int main(void)
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); // Enable clock for Port C
	// Define a structure
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // General purpose push-pull output
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; // Pin 13
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 50MHz speed
	// Configure port mode
	GPIO_Init(GPIOC, &GPIO_InitStructure);
	// Set port high or low level
	//GPIO_SetBits(GPIOC, GPIO_Pin_13);// High level
	GPIO_ResetBits(GPIOC, GPIO_Pin_13);// Low level
	while(1)
	{
		
	}
}

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.