[STM32Cube_00] First acquaintance with HAL firmware library

1. CMSIS standard and library hierarchy

  Because the cores used in Cortex series chips are the same,The difference is mainly the difference between the on-chip peripherals outside the coreHowever, these differences make it difficult to transplant software on chips with the same core and different peripherals. In order to solve the compatibility problem of Cortex microcontroller software produced by different chip manufacturers, ARM and chip manufacturers established the CMSIS standard (Cortex MicroController Software Interface Standard).

  The so-called CMSIS standard is actually a new oneSoftware abstraction layer

1.1 Introduction to library directories and files

STM32Cube_FW_F1_V1.8.0

  • Documentation: Under the folder is the HAL library help document, which mainly describes how to use the driver library to write your own applications. To put it vividly, it is to tell us: ST company has written the drivers for each peripheral for you. If you want to know how to use these examples, please come to me for help. Unfortunately, this help document is in English, which is a big obstacle for many friends who are not good at English. But here I want to tell you that English is only a tool, and we must not let it become an obstacle to our learning. In fact, these English is still very simple, what we need is the courage to win it.
  • Drivers: Under the folder is the official CMSISI library, HAL library, and onboard peripheral drivers.
  • Middlewares: Middleware, including ST official STemWin, STM32_Audio, STM32_USB_Device_Library, STM32_USB_Host_Library; there are also third-party fatfs file
    systems and so on.
  • Project : Under the folder are examples and project templates for the official release demo board written with the driver library.
  • Utilities: Practical common components such as LCD_LOG Practical LCD print debugging information.
  • Release_Note.html: The version update description of the library.

When using library development, we need to putDriversDirectory CMSIS, STM32F1xx_HAL_Drivercore and peripheral libraries to add to our project can be.


There are two folders in the Drivers directory CMSIS, STM32F1xx_HAL_Driver. Let's look CMSISat the folder first.

Two, CMSIS folder


First look at the =include= file. What

the Include folder contains is the Cortex-M core common header files located in the core device function layer of the CMSIS standard. Their function is to design SOC for those chip vendors who use the Cortex-M core. The designed chip peripheral provides an interface to the kernel and defines some kernel-related registers (similar to the stm32F103xx.h file we wrote earlier, but defines the registers of the kernel part).

2.1 stm32F103xx.h file

File Directory:Drivers \CMSIS\Device\ST\stm32f1xx\Include

  stm32F103xx.h This file is very important, it is a file related to the bottom of the STM32 chip. Contains all peripheral register addresses and structure type definitions in STM32. This header file must be included wherever the STM32 HAL library is used.

Look at =Source=File

2.2 system_stm32f1xx.c file

File Directory:STM32Cube_FW_F1_V1.8.0\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates

  This file contains functions for initializing the system clock and expanding external memory after the STM32 chip is powered on. For example, the "SystemInit" function called by the startup file is used to initialize the clock after power on. The definition of this function is stored in the system_stm32f1xx.cfile. For STM32F103 series chips, after calling this SystemInitfunction of the library , the system clock is initialized to 72MHz. If necessary, you can modify the content of this file and set it to the clock frequency you need.

2.3 Startup file

File Directory:STM32Cube_FW_F1_V1.8.0\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates

  In this directory, there are many folders, such as "ARM", "gcc", "iar", etc. These folders contain the assembly startup files corresponding to the compilation platform, which should be selected according to the compilation platform in actual use. The MDK startup file we use is in the "ARM" folder. The "strartup_STM32F103xx.s" is the startup file of the STM32F103 chip. The startup files used in the previous two chapters projects are copied from here. If you use other types of chips, you must select the corresponding startup file here. For example, the STM32F103 model uses the "startup_stm32f103x.s" file.

Three, STM32F1xx_HAL_Driver folder

  File directory: Drivers\STM32F1xx_HAL_Driver
  enter the STM32F1xx_HAL_Driver folder under the Drivers directory. There are two folders in the

  STM32F1xx_HAL_Driver folder, including inc (abbreviation of include) and src (abbreviation of source). The files here belong to the on-chip chips other than CMSIS Peripheral part. src is the driver source program of each device peripheral, and inc is the corresponding peripheral header file. The src and inc folders are the main content of ST's HAL library. Many people even directly think that ST's HAL library refers to these files, which shows their importance.

  In the library function file src and inc folder is ST's STM32 peripherals for each written, one for each peripheral .cand .hfile suffix. We collectively refer to these types of peripheral files as: stm32f1xx_hal_ppp.cor stm32f1xx_hal_ppp.hfiles. As for analog to digital conversion (ADC) peripheral, a src folder in stm32f1xx_hal_adc.cthe source file, a folder in inc stm32f1xx_hal_adc.hheader file.

stm32f1xx_it.c, stm32f1xx_hal_conf.h files

File Directory:STM32Cube_FW_F4_V1.19.0\Projects\STM32F103ZI-Nucleo\Templates

  In this directory, the official store of a template library project, when we build a complete project with libraries also need to add the files in this directory src folder stm32f1xx_it.cand folders inc and stm32f1xx_it.h, stm32f1xx_hal_conf.hthese three files.

  stm32f1xx_it.c: This file is specially used to write interrupt service functions. Before we modify, this file has defined some system exception (special interrupt) interfaces, and other ordinary interrupt service functions are added by ourselves. But how do we know how to write the interface of these interrupt service functions? Can it be customized? The answer is of course no. All of these can be found in the assembly startup file. We will introduce in detail when we learn about the interrupt and startup file stm32f1xx_hal_conf.h: This file is included in the stm32f103xx.hfile. The STM32HAL library supports all STM32F1 models of chips, but some models have more peripheral functions, so use this configuration file to increase or decrease the peripheral files of the ST library according to the chip model, and the clock source configuration is also set here.

Guess you like

Origin blog.csdn.net/qq_39400113/article/details/109463285