Tangwx

Tangwx

博客网站

02. Create a new STM32 project.

2 Creating STM32 Project#

2 Creating STM32 Project#

2.1 Classification and Abbreviations of STM32F10X Models#

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

AbbreviationMeaningFlash CapacityModel
LD_VLLow-density Value Line16~32KSTM32F100
MD_VLMedium-density Value Line64~128KSTM32F100
HD_VLHigh-density Value Line256~512KSTM32F100
LDLow-density16~32KSTM32F101/102/103
MDMedium-density64~128KSTM32F101/102/103
HDHigh-density256~512KSTM32F101/102/103
XLExtra-largeGreater than 512KSTM32F101/102/103
CLConnectivity Line-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.

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

Project options, C/C++, define USE_STDPERIPH_DRIVER in the 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.

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

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 to configure the clock. 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 of 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:#

inc and src folders contain pre-packaged .h and .c library files from 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.