In order to facilitate porting and development and reduce a lot of unnecessary troubles, ST company encapsulates many functions into a firmware library
1. Introduction of CMSIS Standard
The full English name of the CMSIS standard is Cortex Microcontroller Software Interface Standard, which translates to the ARM Cortex microcontroller software interface standard. Because there are many chip manufacturers based on Cortex core, not just ST company. In order to solve the software compatibility problem of Crotex chips produced by different manufacturers, ARM and other chip manufacturers developed this CMSIS standard.
2. Introduction to the folders and files in the firmware library
1. _htmresc folder
Store ST company logo
2. There are two subfolders CMSIS and STM32F10x_StdPeriph_Driver under the Libraries folder
CMSIS: Store files conforming to the CMSIS standard, STM32 startup files, core files, peripheral header files, etc.
STM32F10x_StdPeriph_Driver: Peripheral driver files, including two subfolders inc and src
inc: Store the header file.h of the peripheral
src: store the source file of the peripheral.c
Two files stm32f10x_gpio and stm32f10x_rcc are generally used frequently
3. There are two subfolders STM32F10x_StdPeriph_Examples and STM32F10x_StdPeriph_Template under the Project folder
STM32F10x_StdPeriph_Examples: Peripheral driver examples provided by ST
STM32F10x_StdPeriph_Template: ST official firmware library template, usually not used, design by yourself
4. Utilities file is the source file of ST company screen version
5. The stm32f10x_stdperiph_lib_um.chm help document is very important
6. Focus on a few documents
The core_cm3.h and core_cm3.c under the latest STM32 firmware library v3.5\Libraries\CMSIS\CM3\CoreSupport are core files and do not need to be changed
The latest STM32 firmware library v3.5\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x stores some files for system initialization and does not need to be moved. The startup folder contains startup files, and the startup folder contains several folders It is distinguished according to the compiler, the Keil5 compiler uses the files in the arm folder
Select the startup file according to the chip type. The hd at the end means high capacity, md medium capacity, and ld low capacity. You can find out what capacity the chip uses on Baidu.
The stm32f10x.h header file under the latest STM32 firmware library v3.5\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x is equivalent to the c51.h header file in the microcontroller. It is very important. It defines the bus, memory, and registers of stm32 , Clock, interrupt, etc.
The latest STM32 firmware library v3.5\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x under the system_stm32f10x.c and system_stm32f10x.h files contains the access layer program of the on-chip peripherals, and the system initialization function is also inside.
Three, library function template creation
(1) Acquisition of firmware library
To create a library function project template, you first need a firmware library package. There are many versions of the firmware library. We provide you with the latest version V3.5. If there is a new version later, you can create the library function project in the same way. template. The firmware library package is stored in the CD "8--STM32 related information\STM32 latest firmware library v3.5", and you can use it directly. If your friends don’t bother you, you can download it on the ST official website or search through Baidu, but you must download the STM32F1 firmware library. If you download the STM32F4 firmware library, you can download the project template created by the firmware library to the development later. There will be problems on the board. In order to ensure that the firmware library package in the CD is not modified, you can back it up.
(2) Create a function project
1. Create a file such as "library function template creation" folder, and create three new subfolders in the folder
The User folder is used to store the program files written by the user, the required header files, etc.; the Obj folder stores the process files generated by the system; the Libraries folder stores the files obtained from the firmware library
2. Copy the files you need
Create a CMSIS subfolder in the Libraries folder, and copy the following five files to the CMSIS folder:
Copy the two files in the firmware library: STM32 latest firmware library v3.5\Libraries\CMSIS\CM3\CoreSupport directory
Copy the startup file and copy the firmware library: STM32 latest firmware library v3.5\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm in the startup_stm32f10x_hd.s file
Copy the two files in the firmware library: STM32 latest firmware library v3.5\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x directory
3. Header files and source files
In the firmware library folder, copy the STM32F10x_StdPeriph_Driver folder in the STM32 latest firmware library v3.5\Libraries directory to the directory Libraries created by yourself
4. User folder
In the firmware library, copy the five files under the latest STM32 firmware library v3.5\Project\STM32F10x_StdPeriph_Template to your User directory
Copy the stm32f10x.h file under the firmware library directory: STM32 latest firmware library v3.5\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x to the User folder
5. Create a project
Create your own project in the new folder "library function template creation", and be careful not to use the Chinese name
6. Add files to the project
To facilitate management, we create a directory, click on the directory creation icon
Click New to create the following four directories
Add files to the directory, select the User directory, and click Add
Add the two files in the User directory
Add startup files in the Startup directory
Remember to select the file type as .s file
Add peripheral driver files under the StdPeriph_Driver directory, and add the two most commonly used peripheral driver files
Add files under the CMSIS directory
Click OK and exit
7. Configure the magic wand
Click on the magic wand icon, use MicroLIB, which is convenient for output with printf
In the Output interface, select Create HEX File
Put the Objects output file in a folder defined by yourself
Similarly, put the Listings output file in a folder defined by yourself
In the C/C++ interface, you need to add macro definitions USE_STDPERIPH_DRIVER, STM32F10X_HD, otherwise an alarm will appear. Note that there is a comma between the two macros.
Add the path of the header file
Add three paths
Click save to exit the magic wand
8. Process the main.c file
Double-click to open the main.c file, delete all the contents inside, and enter the program
#include "stm32f10x.h"
int main()
{
while(1)
{
}
}
Compile, no errors and no warnings, the template is created successfully. If there is an error, you can refer to the following solutions 1.error: firmware library template programming: 4 error solutions about core_cm3.c_not silly gown-CSDN blog