当前位置:网站首页>Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail

2022-07-06 01:44:00 Moqim Flourite.

notes : This learning is based on the wildfire learning video , It is recommended to watch all videos before the firmware library , To lay a good foundation . See Wildfire Forum .

( Because it still needs some foundation of wildfire , I will first write it according to the logic I understand , Students who don't understand recommend finishing the video about register to firmware library )

Guess firmware library

According to what we have learned 51 Single chip microcomputer , You can infer which files will be included in the firmware library .
( The following conjecture comes from Wildfire )

1、 Compile the startup file
Starup_stm32f10x_hd.s: Set stack pointer 、 Set up PC The pointer 、 Initialize interrupt vector table 、 Configure the system clock 、 call C Library function _main Finally go to C The world of ;

2、 Clock configuration file
system_stm32f10x.c: Put the external clock HSE=8M, after PLL Frequency doubling is 72M;

3、 Peripheral related
stm32f10x.h: Implement the register mapping of peripheral devices outside the kernel ;
xxx:GPIO、USRAT、I2C、SPI、FSMC;
stm32f10x_xx.c: Peripheral driver library file ;
stm32f10x_xx.h: The initialization structure used to store peripherals , The peripheral initializes the parameter list of structure members , Declaration of peripheral firmware library function ;

4、 Kernel dependent
CMSIS - Cortex Microcontroller software interface standard ;
core_cm3.h: Implement the register mapping of peripherals in the kernel ;
core_cm3.c;

NVIC( Nested vector interrupt controller )、SysTick( System ticking timer )
misc.h;
misc.c;

5、 Configuration file of header file
stm32f10x_conf.h: Header file of header file ( Header file that contains all peripheral header files );

6、 Dedicated to storing interrupt service functions C file
stm32f10x_it.c;
stm32f10x_it.h;

Understand the firmware library

Open the firmware library file in the match point resource package —— Please add a picture description
There's a path on it ( In fact, it was a folder at the beginning , Just click crazy ).

After opening, we can see four folders ——
( picture source : Wildfire )
 Please add a picture description
In the first folder are several icons , Don't worry about him ;
The second folder is the library source code and startup files , The library file we want to call is right here ;
In the third folder is the routine of the official evaluation version , We can copy the configuration code inside , By modifying parameters to achieve the functions we need , It is convenient for us to quickly configure code ;
The fourth file is the library usage help document , You can look at it , But he is all English .

understand Libraries Folder

Open the second folder Libraries——
 Please add a picture description
There are two folders in it :CMSIS,STM32F10x_StdPeriph_Driver.

Through the name, we can know that the first one is the kernel file , The second is the peripheral driver file .
(CMSIS - Cortex Microcontroller software interface standard )
(Peripheral peripherals ,Driver The driver )

understand CMSIS Folder

Let's open it first CMSIS Folder ——
 Please add a picture description
Other documents are useless , Let's continue to drive CM3 Folder ——
( It's useless because ... Ah, this , How to put it? , These files cannot be called in the program , If you are interested, just take a look )
 Please add a picture description
Here is a brain diagram .( Brain map is made with reference to wildfire )
Select ARM Because we are ARM As the core board ;
choose md The startup file is because the Blue Bridge Cup is STM32F103RBT6 The board of ,R yes 64 One pin ,B yes 128K,T yes QFR encapsulation ,6 Is the operating temperature -40-85 Centigrade .
For details, please refer to this blog @chiaixian2107-STM32F103RBT6 Model description .

( I'm not referring to this blog , I remember it before )
 Please add a picture description
 Please add a picture description
( source : Chapter 1 of Chinese version of reference data 1.2 The glossary )
According to the official explanation , We knew we should choose md Medium capacity .

understand STM32F10x_StdPeriph_Driver Folder

Next let's see STM32F10x_StdPeriph_Driver The folder . Please add a picture description
There are only two folders ( that HTML Never mind the document ),
among inc Express include, Inside is the header file of each peripheral ;
So the corresponding ,src The inside is for each peripheral .c The file .
 Please add a picture description
Here is attached .c Diagram of file , You can read the header file by yourself .
 Please add a picture description

understand Project Folder

open Project Folder ——
 Insert picture description here
By name , We can know ——
The first is the peripheral routine file , There are routines for each peripheral , The program we write later can be copied directly here ;
The second is the template file , Similar to what the government gave us LCD Template file , There are some drivers in the just Libraries Not in the file , We can copy it here .

open STM32F10x_StdPeriph_Template file ——
 Please add a picture description
Inside stm32f10x_conf.h、stm32f10x_it.c、stm32f10x_it.h We need to join our project later .

open STM32F10x_StdPeriph_Examples file —— Please add a picture description
Inside are the routines of various peripherals , We can use it when we officially start learning programs .

Start new project

New folder

OK, After understanding the library file , We officially started the new project .

First , Create a new folder , Then create the following folders in the folder —— Insert picture description here
( This is what I learned from Wildfire )
first Doc Folder , Put on a readme.txt file , It is used to write the function of the program and some small remarks ;
the second Libraries Folder , It is used to hold the files we will copy from the library later ;
Third Output Folder , The generated file used to install the program ;
The fourth one Project Folder , Used for Engineering , We build the project in this ;
The fifth one User Folder , Used to hold our own writing .c and .h file .

Add library file

First add the entire library to Libraries In the folder .

CMSIS Folder

As we said before , Only keep the framed files , Delete everything else , And put them all in CMSIS, Instead of staying CMSIS In the folder ( Otherwise, adding header files later is troublesome )——
 Please add a picture description
 Insert picture description here

STM32F10x_StdPeriph_Driver Folder

This one will be moved over , After all, this is the driver file of all peripherals —— Insert picture description here

STM32F10x_StdPeriph_Template Folder

This is the official routine file , We just put the inside stm32f10x_conf.h、stm32f10x_it.c、stm32f10x_it.h Just join our project —— Insert picture description here

Configuration Engineering

New project documents

Then open the Keil4, Click new project , Select chip type as stm32f103rb—— Insert picture description here

 Insert picture description here

Add project folder

And then click on this “ product ”—— Insert picture description here
Add the following folders —— Insert picture description here
( Double click that name to change it , To add, press the dotted box on the left of the Red Cross )

Add files

Then configure the folders in the project according to the following figure ——
 Insert picture description here

Setup project

Click on this magic wand ——
 Insert picture description here

Debug and build

Tick the following three ——
( The first is debugging information , The second is generation hex file , The third is browsing information , Click a function to jump to its definition or declaration )

 Insert picture description here
Then change the address of the generated file ——
Same page , Click the button below ——
 Insert picture description here
And then choose Output Folder , Then click OK ——
 Insert picture description here

Configure preprocessor declaration  Insert picture description here

In my picture, it has been configured , Now let's see why we need to configure it like this ( All in stm32f10x.h In file )——

STM32F10X_MD

 Insert picture description here
The first paragraph :Library_configuration_section Library configuration
The second paragraph :Uncomment the line below according to the target STM32 device used in you application According to the target used in the application stm32 Uncomment the line below the device
( Explain that we need to choose our equipment , As we said before, our equipment is medium capacity , So choose STM32F10X_MD)
The third paragraph :To avoid modifying this file each time you need to switch between these devices, you can define the device in your toolchain compiler preprocessor.
To avoid modifying the file device every time you need to switch between these files , You can define devices in the toolchain compiler preprocessor .
( So we need to take STM32F10X_MD Defined in the preprocessor )

Then why do you have to configure it ?
 Insert picture description here
Let's talk about , If you don't define this device type ,“Please select first the target STM32F10x device used in your application (in stm32f10x.h file)”(“ Please first select the target to use in your application STM32F10x equipment ( stay STM32F10x .h In file )”).

USE_STDPERIPH_DRIVER

 Insert picture description here
Comment the line below if you will not use the peripherals drivers.
In this case, these drivers will not be included and the application code will be based on direct access to peripherals registers
If you do not use peripheral device drivers , Please comment on the following line .
under these circumstances , These drivers will not be included , The application code will be based on direct access to external registers .

in other words , If you don't define this USE_STDPERIPH_DRIVER , Then we can't use peripherals . So of course we have to define .
Same as above , For convenience , Also define it in the preprocessor .

Be careful , Separated by commas , Don't use semicolons and other symbols !

Add the header file path

I believe everyone is familiar with this , Just put a piece of my path as a reference ——
 Insert picture description here
 Insert picture description here

Configure debugging tools

We are choosing CooCox Debugger——
 Insert picture description here
Then click the next settings——
The first two choose according to this , The third one doesn't matter .
Generally, if the board is inserted , You have selected the model of the board that will be displayed on the right , If not, restart the project ,JTAG Sometimes it's like this ——
 Insert picture description here
Then click Flash Download——
spot Add, Then find the model I have added below , Just add ( Because we are RBT6 Well ,B Namely 128K)——
 Insert picture description here

 Insert picture description here

This last , Uncheck the circle on the right ( Selected by default , If selected , The left circle cannot be changed ), Then select the circle on the left CooCox Debugger That's it ——
 Insert picture description here

test

stay main.c The file contains one of the simplest

#include <stm32f10x.h>
int main(){
    
  return 0;
}

then , function !

If the following figure is shown ,
 Please add a picture description
It means that the project file is configured !

If you feel useful, please give me a compliment , thank you ~

原网站

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