Stm32 standard peripheral library usage details.

Source: Internet
Author: User

The stm32 standard peripheral library is a peripheral driver for the entire series of stm32 chips. With it, we can greatly accelerate the development of stm32.
First, download the latest stm32 standard peripheral library from the website of st. The latest version is v3.5.0.

Decompress the ZIP file to obtain the following folders and files:
Stm32f10x_stdperiph_lib_v3.5.0 \
_ Htmresc
Libraries
Project
Utilities
Release_notes.html
Stm32f10x_stdperiph_lib_um.chm


Among them, libraries contains the source code of the Library. The project contains the use example of each stm32 peripheral and a project template. Utilities is an example of using the st evaluation board. stm32f10x_stdperiph_lib_um.chm teaches us how to use the standard peripheral library.

Project directory structure
Since we are going to use a 32-bit microcontroller, it should be a large project, so we should also make a plan for the project directory. Here I recommend the directory structure I use. Assume that the project name is "template" and a folder named "template" is created. The directory contains three fixed folders: Doc, SRC, include, and Doc, which are used to store project-related documents, SRC: Put the source code. In SRC, each function module has a folder. include: Put the public header files to be used by each module. The output file contains two subfolders (OBJ and list.

Template \
Doc
SRC
Include
Output \ OBJ
\ List

Sort library code
Many codes in the cmsis folder under libraries are related to compilers and chips, resulting in many folders and large depth, which is not conducive to engineering maintenance. In fact, a project usually uses fixed compilers and chips, therefore, it is necessary to sort out the database.
Create the libstm32 directory under SRC
1. Copy the content under libraries \ stm32f10x_stdperiph_driver \ To The libstm32 directory.
2. create a cmsis folder under the libstm32 directory, and set core_cm3.c, core_cm3.h, and libraries \ cmsis \ cm3 \ devicesupport \ ST \ stm32f10x \ stm32f10x under libraries \ cmsis \ cm3 \ coresupport. h, system_stm32f10x.c, and system_stm32f10x.h are copied to the cmsis folder.
3. Copy the startup files under libraries \ cmsis \ cm3 \ devicesupport \ ST \ stm32f10x \ Startup \ Arm \ To The cmsis folder Based on the selected chip type. Here, I copied startup_stm32f10x_hd.s (the Startup File of large-capacity stm32 chip ).

Below is a brief introduction to the library file:
The content in libraries \ stm32f10x_stdperiph_driver \ is well understood as the driver code of each peripheral module of stm32.
Misc. h and Misc. C are the driver code of Objective C and objective ick related to the cm3 kernel.
What is libraries \ cmsis? Cmsis: Cortex microcontroller software interface standard, is the hardware abstraction layer of the cortex series processor. It can be understood as the software interface of the cortex kernel.
Core_cm3.c, core_cm3.h
Their directory name is coresupport, indicating that these two files are cm3 Kernel support files. Other chips that use the cm3 kernel can also be used, not necessarily stm32. These two files are used to obtain and set the cm3 kernel and configure some kernel registers.
Stm32f10x. H, system_stm32f10x.c, system_stm32f10x.h and startup_stm32f10x_hd.s are in the devicesupport Directory, which indicates that these files are related to the specific chip, that is, the file supporting the stm32 chip. Stm32f10x. H is the entrance to the standard peripheral library. The code using the standard peripheral library must contain this header file. The system_stm32f10x.c and system_stm32f10x.h files provide functions to initialize the stm32 chip, configure the PLL, system clock, and built-in flash interface. Startup_stm32f10x_hd.s is the Startup file of the large-capacity stm32 chip.

Create a project
Use Keil MDK (I use version 4.12) to create a project under the template directory. The project name is template. It doesn't matter which one of the stm32 series chips is selected (I chose stm32f101rc, because my board uses this chip ), next, you should select no when the pop-up shows whether to copy the startup code to the project folder, because the startup code already exists in the standard peripheral library.
Change the top-level directory name in the project window in uv4 to template, and change the first group name to libstm32. Load all. C and. s files under the libstm32 directory to the libstm32 in the project.
Create an init directory under SRC to place the system initialization code. Copy stm32f10x_it.c under project \ stm32f10x_stdperiph_template \ To the init folder, and copy stm32f10x_it.h and stm32f10x_conf.h to the include folder.
. Stm32f10x_conf.h is the configuration file of the standard peripheral library. For peripherals not required in the project, you can comment out the header files contained in it. Here, I suggest leaving only stm32f10x_gpio.h, stm32f10x_rcc.h, and Misc. H. What is used and then opened, so that compilation is faster and can be kept.

Use the stm32 standard peripheral Library
In fact, how to use the library section in the stm32f10x_stdperiph_lib_um.chm section describes how to use the stm32 standard peripheral library. Below I will list the steps below:
1. Add the startup code from libraries \ cmsis \ cm3 \ devicesupport \ ST \ stm32f10x \ Startup \ arm to the project based on the selected chip. This step has been done above.
2. In line 66-73 of stm32f10x. H, remove the corresponding comment based on the selected chip type. Here I remove the comment of the line stm32f10x_hd (large-capacity stm32 chip ).
3. Remove the use_stdperiph_driver comments from line 1 and enable the stm32 standard peripheral library.
4. in the 110-115 lines of system_stm32f10x.c, comment out the corresponding comment based on the selected chip clock speed. The comment of sysclk_freq_72mhz by default has been removed. If your chip clock speed is 72 MHz, no modification is required, here, my chip is 36 MHz. Comment sysclk_freq_72mhz and remove the sysclk_freq_36mhz comment.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.