打印
[应用相关]

【转】Description of STM32F1xx HAL drivers 重点记录

[复制链接]
1976|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
HAL库的特性:


APIs are RTOS compliant:
  Fully reentrant APIs
  Systematic usage of timeouts in polling mode.
HAL的APIs完全适用于实时系统,在轮询模式中的超出设定


user-callback functions mechanism:
Peripheral Init/DeInit HAL APIs can call user-callback functions to perform
peripheral system level Initialization/De-Initialization (clock, GPIOs, interrupt,
DMA)
  Peripherals interrupt events
  Error events.


设立回调函数,在外设初始化,中断事件,错误事件都会有user-callback functions。


Object locking mechanism: safe hardware access to prevent multiple spurious
accesses to shared resources.
事件锁定机制,防止多程序共用单一资源。


Timeout used for all blocking processes: the timeout can be a simple counter or a
timebase.
超时设定,防止进程被阻塞。


PPP_IRQHandler() routine must call HAL_PPP_IRQHandler()
外设中断函数可由用户编写,里面一般会包含HAL库外设中断,全在stm32f1xx_it.c/.h文件中。


HAL_Init()是CUBE生成的,其中包含HAL_MspInit(),用户可用于底层初始化设定。


HAL data structures
Each HAL driver can contain the following data structures:
  Peripheral handle structures
  Initialization and configuration structures
  Specific process structures.
HAL包含三种数据结构:
处理结构  PPP_HandleTypeDef *handle  这结构包括了后面的初始化与配置结构
初始化与配置结构,
特别进程结构。


PPP_HandleTypeDef *handle is the main structure that is implemented in the HAL
drivers. It handles the peripheral/module configuration and registers and embeds all the
structures and variables needed to follow the peripheral device flow.
The peripheral handle is used for the following purposes:
  Multi instance support: each peripheral/module instance has its own handle. As a
result instance resources are independent.
  Peripheral process intercommunication: the handle is used to manage shared data
resources between the process routines.
Example: global pointers, DMA handles, state machine.
  Storage : this handle is used also to manage global variables within a given HAL
driver.






The multi-instance feature implies that all the APIs used in the application are
re-entrant and avoid using global variables because subroutines can fail to be re-
entrant if they rely on a global variable to remain unchanged but that variable is
modified when the subroutine is recursively invoked.

重入程序避免使用这些全局变量??


The HAL APIs are classified into threecategories:

Generic APIs:

Extension APIs:

         Familyspecific APIs:

         Devicepart number specific APIs.

应用程序界面分三类,一为普通应用程序,二为扩展程序,其中包括相关特别程序与特别型号的程序。


  The PPP prefix refers to the peripheralfunctional mode and not to the peripheral itself.

For example, if the USART, PPP can beUSART, IRDA, UART or SMARTCARD

depending on the peripheral mode.

PPP代表外设名字

  The constants used in one file are definedwithin this file. A constant used in several

files is defined in a header file. Allconstants are written in uppercase, except for

peripheral driver function parameters.

除了函数的参量,所有常量都大写。

  typedef variable names should be suffixed with _TypeDef.

typedef变量全有_TypeDef.作为后缀

  Registers are considered as constants. Inmost cases, their name is in uppercase and

uses the same acronyms as in the STM32F1xxreference manuals.

  Peripheral registers are declared in thePPP_TypeDef structure (e.g. ADC_TypeDef)

in stm32f1xxx.h header file. stm32f1xxx.hcorresponds to stm32f100xb.h,

stm32f100xe.h, stm32f101x6.h,stm32f101xb.h, stm32f101xe.h, stm32f101xg.h,

stm32f102x6.h, stm32f102xb.h,stm32f103x6.h, stm32f103xb.h, stm32f103xe.h,

stm32f103xg.h, stm32f105xc.h andstm32f107xc.h.

寄存器被认为常量,缩写大写并且在其对应芯片的总头文件中。

  Peripheral function names are prefixed byHAL_, then the corresponding peripheral

acronym in uppercase followed by anunderscore. The first letter of each word is in

uppercase (e.g. HAL_UART_Transmit()). Onlyone underscore is allowed in a function

name to separate the peripheral acronymfrom the rest of the function name.

  The structure containing the PPP peripheralinitialization parameters are named

PPP_InitTypeDef (e.g. ADC_InitTypeDef).

  The structure containing the Specific configuration parameters for the PPP peripheral

are named PPP_xxxxConfTypeDef (e.g.ADC_ChannelConfTypeDef).

  Peripheral handle structures are namedPPP_HandleTypedef (e.g

DMA_HandleTypeDef)

  The functions used to initialize the PPPperipheral according to parameters specified

in PPP_InitTypeDef are named[url=]HAL_PPP_Init[/url] (e.g. HAL_TIM_Init()).

用于初始化的结构变量都被写成HAL_PPP_Init

  The functions used to reset the PPPperipheral registers to their default values are

named PPP_DeInit, e.g. TIM_DeInit.

  The MODE suffix refers to the process mode,which can be polling, interrupt or DMA.

As an example, when the DMA is used inaddition to the native resources, the function

should be called: HAL_PPP_Function_DMA ().

三种模式都有其对应的函数名。

  The Feature prefix should refer to the newfeature.

Example: HAL_ADC_Start() refers to theinjection mode



NVIC and SYSTICK are two ARM Cortex corefeatures. The APIs related to these

features are located in the[url=]stm32f1xx_hal_cortex.c file[/url].

NVIC and SYSTICK是ARM Cortexcore核有特性,故其放到了stm32f1xx_hal_cortex.c file中

The user callback functions are defined asempty functions with “weak” attribute. They

have to be defined in the user code.

回调函数是被定义为弱指引的空函数,需要用户自己编写。


There are three types of user callbacksfunctions:

  Peripheral system level initialization/de-Initialization callbacks: HAL_PPP_MspInit()

and HAL_PPP_MspDeInit

  Process complete callbacks :HAL_PPP_ProcessCpltCallback

  Error callback: HAL_PPP_ErrorCallback.

有三类回调函数,初始化时的回调,进程完成后的回调,错误回调


The initialization and de-initializationfunctions allow initializing a peripheral and configuring

the low-level resources, mainly clocks,GPIO, alternate functions (AF) and possibly DMA

and interrupts. The [url=]HAL_DeInit()f[/url]unctionrestores the peripheral default state, frees the

low-level resources and removes any directdependency with the hardware.

HAL_DeInit()是用于复位外设,恢复成系统默认设置。



文件的包含关系




The functions implemented in the HAL driverare shown in green, the functions

called from interrupt handlers in dottedlines, and the msp functions implemented

in the user application in red. Non-dottedlines represent the interactions between

the user application functions.

应用函数为绿色,红框为msp函数,虚线为中断呼叫,实线为函数的交互。


发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

66

主题

168

帖子

2

粉丝