Students who want to learn single-chip microcomputers have a look, the MDK5 project of the STM32 firmware library is established and the LED is lit

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:

d2f46aa961bb63ad645b51c15a47658e.png

Among them, stm32f10x_stdperiph_lib_um.chm is the help document of the library.

Create STM32 project

·Open MDK5 and create New uVision Project.

78e4dd535b70dc2d48bf5a50d3edf0eb.png

·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.

f36a415ddb837eb2dc632eca3ba07ebc.png

·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.

b096999354f3932d1dd17408f0897dbb.png

After clicking OK, the Manage Run-Time Environment dialog box appears, just click Cancel to get the following interface:

88b438510245132c76217ee0700d2f08.png

Delete the Listings and Objects folders selected in the following boxes

645e121df18a6df0488e5e430be64e2b.png

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.


8070f9dd12db8c3f1180d1f0fd6f5d81.png

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.

ce61c9201ed1a2919d57262175be4491.png

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.

dae3a3be700240295373f59e8b150737.png

Add the files added in the previous steps to our project directory.

2ccdf8813d258a9352f97519f1f7400e.png

After the addition is complete, the project directory structure is as follows:

8369501990557fe44064d27d06748a20.png

Set the compilation intermediate files, the directory where the compiled files are stored

ba8bfcfc59cd34007c07a48a8c6ea2bd.png

Set the directory where the header file is located

ae12be821be1f84af2e5d82ccd09a207.png

The macro definitions required by the configuration project: STM32F10X_HD, USE_STDPERIPH_DRIVER

94727a70bf568d4a8cb1cb0c6931acf0.png

Set the compilation output file format

1292bea00033f325ba5889e280ab7b55.png

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.

97766c001f6f6f0462b51847421118d4.png

eded306e7c26a97504fb7f9a803aebed.png

#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

2b1fb1230b7de28e2480d7a3b3cd50cd.png

·Download the program

0f570000ebc13def946dbae67ef0026d.png

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.

Guess you like

Origin blog.csdn.net/danpianji777/article/details/123994335