I am a university teacher, and I will continue to output dry goods about single-chip microcomputer and embedded content on this platform in the future. I hope everyone will support it~
learning target
Create a Keil project of STM32 from scratch
Lights up an LED on the board
Project creation
Download firmware library
Firmware library STM32F10x_StdPeriph_Lib_V3.5.0: The relevant content can be private to me.
After decompression, it is as shown below:
Among them, stm32f10x_stdperiph_lib_um.chm is the help document of the library.
Create STM32 project
·Open MDK5 and create New uVision Project.
·Save the project file to the pre-created directory:
Because I am using the punctual atomic development board, I am used to placing the project files under the subdirectory USER.
·Select the chip model used
My board uses STM32F103RTC6, so here we choose STMicroelectronics->STM32F1 Series->STM32F103->STM32F103RCT6
Note: Be sure to install the corresponding device pack, this tutorial uses the Keil.STM32F1xx_DFP.1.0.5.pack installation package.
After clicking OK, the Manage Run-Time Environment dialog box appears, just click Cancel to get the following interface:
Delete the Listings and Objects folders selected in the following boxes
Create three new folders CORE, OBJ and STM32F10x_FWLib under the Template folder.
Among them:
CORE is used to store core files and startup files; OBJ is used to store
compilation process files and hex files; , is also used to store files such as main.c and system_stm32f10x.c. Copy the previously prepared firmware library under the STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\STM32F10x_StdPeriph_Driver directory, and copy the src,inc folder under the directory to the STM32F10x_FWLib folder we just created.
Copy the relevant startup files in the firmware library package to our project directory CORE.
Navigate to the directory STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\CoreSupport, and copy the file core_cm3.c and the file core_cm3.h to the CORE.
Navigate to the directory STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm, and copy the startup_stm32f10x_hd.s file to the CORE.
Navigate to the directory: STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x and copy the three files in it stm32f10x.h, system_stm32f10x.c, system_stm32f10x.h to our USER directory under.
Then copy the 4 files main.c, stm32f10x_conf.h, stm32f10x_it.c, stm32f10x_it.h under the USER directory under STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template.
Add the files added in the previous steps to our project directory.
After the addition is complete, the project directory structure is as follows:
Set the compilation intermediate files, the directory where the compiled files are stored
Set the directory where the header file is located
The macro definitions required by the configuration project: STM32F10X_HD, USE_STDPERIPH_DRIVER
Set the compilation output file format
Open the main.c file under the project USER, write a simple test code, and compile it.
Here we use the PC7 pin to control an LED to turn on and off periodically.
#include"stm32f10x.h" voidDelay(u32count){
u32i=0;
for(;i<count;i++);}
intmain(void){
GPIO_InitTypeDefGPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;//LED1-->PC.7 port configuration GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//Push-pull output GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//IO port speed is 50MHz GPIO_Init(GPIOC,&GPIO_InitStructure); //Initialize according to the set parameters GPIOA.8 GPIO_SetBits(GPIOC,GPIO_Pin_7);//PC.7 output high
while(1)
{
GPIO_ResetBits(GPIOC,GPIO_Pin_7);
Delay(3000000);
GPIO_SetBits(GPIOC,GPIO_Pin_7);
Delay(3000000);
}}
Downloader
Install JLINK driver
Setup_JLink_V512.exe to
configure SW download mode
·Download the program
After the program is downloaded, power on the board again, and find that the LED connected to PC7 keeps flashing.
At this point, the entire STM32 project has been created.
At the beginning of this year, I recorded a relatively systematic introductory single-chip microcomputer tutorial. The students who want it can just ask me to take it. It is free, and you can send me a private message~ There are also in the introduction.