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.
Abbreviation | Meaning | Flash Capacity | Model |
---|---|---|---|
LD_VL | Value Line Low-density Product | 16~32K | STM32F100 |
MD_VL | Value Line Medium-density Product | 64~128K | STM32F100 |
HD_VL | Value Line High-density Product | 256~512K | STM32F100 |
LD | Low-density Product | 16~32K | STM32F101/102/103 |
MD | Medium-density Product | 64~128K | STM32F101/102/103 |
HD | High-density Product | 256~512K | STM32F101/102/103 |
XL | Extra Large Capacity Product | Greater than 512K | STM32F101/102/103 |
CL | Connectivity 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#
2.4 keil 5 New Project Structure Diagram#
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.
2.5 Using STLink
to Connect the STM32 Microcontroller#
Wiring method:
ST-LINK V2 | STM32 |
---|---|
3.3V | 3V3 |
SWDIO | SWIO |
SWCLK | SWCLK |
GND | GND |
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)
{
}
}