当前位置:网站首页>How to build a new project for keil5mdk (with super detailed drawings)

How to build a new project for keil5mdk (with super detailed drawings)

2022-07-06 11:15:00 Mo tuoruxi

One Build an engineering framework

1. Create a new folder on your computer , Name it Template

2.

Click on MDK Menu for :Project –>New Uvision Project , Then locate the directory to the folder you just created
Template under , Create subfolders under this directory USER( Our code engineering files are placed in USER
Catalog ) The name of the project is Template, Click save .

 3. Choose chip model ( Be sure to install the corresponding device pack Will show these inside Rong oh !

  Click on OK, If other interfaces appear , Click Cancel ;MDK Will pop up Manage Run-Time Environment Dialog box , We don't introduce it here , Click on Cancel that will do

  Get the following interface , Here we only make a framework , You also need to add startup code , as well as .c Documents, etc.

  here USER The folder will be as shown in the following figure (Template.uvprojx It's engineering documents , It's critical , It can't be deleted easily .Listings and Objects The folder is MDK Automatically generated folder , Used to store intermediate files generated during compilation ) We choose to put Listings and Objects These two folders are deleted , In the next step, rebuild the folder .

  Two stay Template work Under the program directory , newly build 3 A folder CORE, OBJ as well as STM32F10x_FWLib.

Used to store core files and startup files ,OBJ It is used to store compilation process files and hex file ,STM32F10x_FWLib As the name suggests, folders are used to store ST Official library function source file .USER The directory is used to put project files , And store the main function file main.c, And others include system_stm32f10x.c wait .

 

  3、 ... and    Copy the source code file in the official firmware library package to our project directory (CORE, OBJ ,STM32F10x_FWLib) Under the folder

STM32F10x_FWLib Folder

Open the official firmware library package , Go to the directory where we prepared the firmware library package
STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\STM32F10x_StdPeriph_Driver below ,
Put the src,inc Folder copy To what we just established STM32F10x_FWLib Under the folder .
src It's a firmware library .c file ,inc The storage is corresponding to .h file , You might as well open these two file directories and have a look
Here are the documents , Each peripheral corresponds to a .c Documents and a .h The header file

2.  CORE Folder ( Startup file )

(1)  Official firmware library package , Locate to directory
STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\CoreSupport below , Will file core_cm3.c And documents core_cm3.h Copied to the CORE Next Noodles Go to .
(2)  however after set position To Objective record
STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm below , Put inside startup_stm32f10x_hd.s File copy to CORE below .
Now look at our CORE Files under the folder :

3 USER Folder  

(1)

STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x below
Put the three files inside stm32f10x.h,system_stm32f10x.c,system_stm32f10x.h, Copy it to our USER Under the catalogue .
(2)
STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template Below 4 Individual article Pieces of
main.c,stm32f10x_conf.h,stm32f10x_it.c,stm32f10x_it.h Copied to the USER Below directory .
in total 9 individual , In addition to the two brought with you ,4 individual .h,3 individual .c

Four take These documents (CORE USER FWILD) Join our project
Right click on the Target1, choice Manage Project Items——> Project Targets One column , We will
(1)Target Change the name to Template
2) Delete one and add three    
stay Groups Delete one from the column Source Group1
Set up three GroupsUSER,CORE,FWLIB
And then click OK, You can see our Target And the name Groups situation .

 

5、 ... and towards Group Add the files we need

1 FWLID

Right click and click
Tempate, Choose to Manage Project Itmes, Then select the file you want to add Group, Here is the first step I
We choose FWLIB , however after spot blow Right edge Of Add Files, set position To I People Just. only build state The catalog of STM32F10x_FWLib/src below , Select all the files in it ( Ctrl+A), And then click Add, then Close.
You can see Files Below the list are the files we added .

 2 CORE

In the same way , take Groups Locate the CORE and USER below , Add the required files . here
our CORE The following files need to be added are core_cm3.c,startup_stm32f10x_hd.s ( Be careful , Default added
When the file type is .c, That is to add startup_stm32f10x_hd.s When you start the file , You need to choose the file type
by All files To see this file )

3 USER

USER The files to be added under the directory are main.c,stm32f10x_it.c, system_stm32f10x.c.

So the files we need to add have been added to me We are in the project , Finally, click OK, Back to the main project interface . 

  6、 ... and Generate compiled files

Click on the magic wand , And then choose “Output” Under the options “Select folder for objects…, Then choose
Choose the directory we created above OBJ Catalog . Attention here , If we don't set Output route , that
The default directory for storing intermediate compilation files is MDK Automatically generated Objects Contents and Listings Catalog .

7、 ... and Add header file

It's big here Be careful at home , For any project , We all need to include the paths of all header files referenced in the project
Come in . Return to the project main menu , Click on the magic wand , Come up with a menu , And then click c/c++ Options . And then click
Include Paths The button on the right . Pop up an add path The dialog , And then we're going to the top of the graph 3 Add a directory
add . remember ,keil Will only look in the first level directory , So if you have subdirectories under your directory , Remember path
Be sure to navigate to the last level subdirectory . And then click OK.

 

 

  8、 ... and Configure global macro definition variables

Locate the c/c++ Interface , Then fill in “STM32F10X_HD,USE_STDPERIPH_DRIVER” To Define In the input box ( Please note that , Two identifiers There is a comma in the middle, not a period , If you are not sure what you entered is correct , Please open any of our CDs directly Library function instance , Then copy this string of words ).

  Nine Open the project USER Below main.c file , Copy the following overlay before compiling main.c The procedure in , Remember to return on the last line (enter), Otherwise, there will be a warning during compilation .

#include "stm32f10x.h"
void Delay(u32 count)
{
u32 i=0;
 for(;i<count;i++);
}
int main(void)
{
 GPIO_InitTypeDef GPIO_InitStructure;
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|
RCC_APB2Periph_GPIOE, ENABLE); //?? PB,PE ????
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED0-->PB.5 ????
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //????
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO ???? 50MHz
 GPIO_Init(GPIOB, &GPIO_InitStructure); //??? GPIOB.5
 GPIO_SetBits(GPIOB,GPIO_Pin_5); //PB.5 ???
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED1-->PE.5 ????
 GPIO_Init(GPIOE, &GPIO_InitStructure); //??? GPIO
 GPIO_SetBits(GPIOE,GPIO_Pin_5); //PE.5 ??? 
 while(1)
{
 GPIO_ResetBits(GPIOB,GPIO_Pin_5);
 GPIO_SetBits(GPIOE,GPIO_Pin_5);
	Delay(3000000);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
GPIO_ResetBits(GPIOE,GPIO_Pin_5);
Delay(3000000); 
} } 

  Recompile the code , We can be in OBJ I see it in the folder .hex file .

 

 

Actually, it passes through the front Of step , Our project template has been established . But in us ALIENTEK Provide
In the experiment of , Every experiment has one SYSTEM Folder , There is 3 The subdirectories are sys,usart,delay,
It stores the common code that we need to use in every experiment , The code is written by us ALIENTEK To write , This code
The principle of is explained in detail in Chapter 5 , We just introduce it into the project , Convenient for later experiments
engineering .
First , Find our experimental CD , Open the experiment of any firmware library , You can see that there is a SYSTEM writing
Clip , For example, we open the experiment 1 The project catalogue is as follows :
You can see there's one SYSTEM Folder , Get into SYSTEM Folder , There are three subfolders in it
delay,sys,usart, Each subfolder has a corresponding .c Document and .h file . Next, we will put these three directories
Face code is added to our project .
Use the steps we explained before 13 The way to , Create a new group in the project , Name it SYSTEM, Then add these three
Under folders .c The documents are sys.c,delay.c,usart.c, Here's the picture :
Next, we will have the corresponding three directories (sys,usart,delay) Add to PATH In the middle , Because there are pictures under each directory
Ought to be .h The header file , Please refer to step 7、 ... and   that will do , The screenshot after adding is :

 

 

 

Finally, click OK. In this way, our project template is completely completed , So we can call ALIENTEK Provided
SYSTEM Functions in the folder .
If there is a mistake , Welcome private message !
I hope it will help you who are working hard !

 

原网站

版权声明
本文为[Mo tuoruxi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131633257239.html