前言:本文介绍STM32 定时器中断控制的HAL 接口定义:


1 该驱动接口能实现的主要功能:

1.1 有哪些驱动

/**
  ******************************************************************************
  * @file    stm32f1xx_hal_tim.c
  * @author  MCD Application Team
  * @brief   TIM HAL module driver.
  *          This file provides firmware functions to manage the following
  *          functionalities of the Timer (TIM) peripheral:
  *           + TIM Time Base Initialization//时基
  *           + TIM Time Base Start
  *           + TIM Time Base Start Interruption
  *           + TIM Time Base Start DMA
  *           + TIM Output Compare/PWM Initialization
  *           + TIM Output Compare/PWM Channel Configuration
  *           + TIM Output Compare/PWM  Start
  *           + TIM Output Compare/PWM  Start Interruption
  *           + TIM Output Compare/PWM Start DMA
  *           + TIM Input Capture Initialization
  *           + TIM Input Capture Channel Configuration
  *           + TIM Input Capture Start
  *           + TIM Input Capture Start Interruption
  *           + TIM Input Capture Start DMA
  *           + TIM One Pulse Initialization
  *           + TIM One Pulse Channel Configuration
  *           + TIM One Pulse Start
  *           + TIM Encoder Interface Initialization
  *           + TIM Encoder Interface Start
  *           + TIM Encoder Interface Start Interruption
  *           + TIM Encoder Interface Start DMA
  *           + Commutation Event configuration with Interruption and DMA
  *           + TIM OCRef clear configuration
  *           + TIM External Clock configuration
  @verbatim

1.2 定时器的功能

==============================================================================
                      ##### TIMER Generic features #####
  ==============================================================================
  [..] The Timer features include:
       (#) 16-bit up, down, up/down auto-reload counter.
       (#) 16-bit programmable prescaler allowing dividing (also on the fly) the
           counter clock frequency either by any factor between 1 and 65536.
       (#) Up to 4 independent channels for:
           (++) Input Capture
           (++) Output Compare
           (++) PWM generation (Edge and Center-aligned Mode)
           (++) One-pulse mode output
       (#) Synchronization circuit to control the timer with external signals and to interconnect
            several timers together.
       (#) Supports incremental encoder for positioning purposes

如何使用这些驱动?

##### How to use this driver #####
  ==============================================================================
    [..]
     (#) Initialize the TIM low level resources by implementing the following functions
         depending on the selected feature:
           (++) Time Base : HAL_TIM_Base_MspInit()
           (++) Input Capture : HAL_TIM_IC_MspInit()
           (++) Output Compare : HAL_TIM_OC_MspInit()
           (++) PWM generation : HAL_TIM_PWM_MspInit()
           (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit()
           (++) Encoder mode output : HAL_TIM_Encoder_MspInit()

(#) Initialize the TIM low level resources :
        (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
        (##) TIM pins configuration
            (+++) Enable the clock for the TIM GPIOs using the following function:
             __HAL_RCC_GPIOx_CLK_ENABLE();
            (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();

(#) The external Clock can be configured, if needed (the default clock is the
         internal clock from the APBx), using the following function:
         HAL_TIM_ConfigClockSource, the clock configuration should be done before
         any start function.

(#) Configure the TIM in the desired functioning mode using one of the
       Initialization function of this driver:

       (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base
       (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an
            Output Compare signal.
       (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a
            PWM signal.
       (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
            external signal.
       (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
            in One Pulse Mode.
       (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface.

(#) Activate the TIM peripheral using one of the start functions depending from the feature used:
           (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT()
           (++) Input Capture :  HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT()
           (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT()
           (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT()
           (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT()
           (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT().

(#) The DMA Burst is managed with the two following functions:
         HAL_TIM_DMABurst_WriteStart()
         HAL_TIM_DMABurst_ReadStart()

回调

*** Callback registration ***
  =============================================

[..]
  The compilation define  USE_HAL_TIM_REGISTER_CALLBACKS when set to 1
  allows the user to configure dynamically the driver callbacks.

[..]
  Use Function @ref HAL_TIM_RegisterCallback() to register a callback.
  @ref HAL_TIM_RegisterCallback() takes as parameters the HAL peripheral handle,
  the Callback ID and a pointer to the user callback function.

[..]
  Use function @ref HAL_TIM_UnRegisterCallback() to reset a callback to the default
  weak function.
  @ref HAL_TIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
  and the Callback ID.

[..]
  These functions allow to register/unregister following callbacks:
    (+) Base_MspInitCallback              : TIM Base Msp Init Callback.
    (+) Base_MspDeInitCallback            : TIM Base Msp DeInit Callback.
    (+) IC_MspInitCallback                : TIM IC Msp Init Callback.
    (+) IC_MspDeInitCallback              : TIM IC Msp DeInit Callback.
    (+) OC_MspInitCallback                : TIM OC Msp Init Callback.
    (+) OC_MspDeInitCallback              : TIM OC Msp DeInit Callback.
    (+) PWM_MspInitCallback               : TIM PWM Msp Init Callback.
    (+) PWM_MspDeInitCallback             : TIM PWM Msp DeInit Callback.
    (+) OnePulse_MspInitCallback          : TIM One Pulse Msp Init Callback.
    (+) OnePulse_MspDeInitCallback        : TIM One Pulse Msp DeInit Callback.
    (+) Encoder_MspInitCallback           : TIM Encoder Msp Init Callback.
    (+) Encoder_MspDeInitCallback         : TIM Encoder Msp DeInit Callback.
    (+) HallSensor_MspInitCallback        : TIM Hall Sensor Msp Init Callback.
    (+) HallSensor_MspDeInitCallback      : TIM Hall Sensor Msp DeInit Callback.
    (+) PeriodElapsedCallback             : TIM Period Elapsed Callback.
    (+) PeriodElapsedHalfCpltCallback     : TIM Period Elapsed half complete Callback.
    (+) TriggerCallback                   : TIM Trigger Callback.
    (+) TriggerHalfCpltCallback           : TIM Trigger half complete Callback.
    (+) IC_CaptureCallback                : TIM Input Capture Callback.
    (+) IC_CaptureHalfCpltCallback        : TIM Input Capture half complete Callback.
    (+) OC_DelayElapsedCallback           : TIM Output Compare Delay Elapsed Callback.
    (+) PWM_PulseFinishedCallback         : TIM PWM Pulse Finished Callback.
    (+) PWM_PulseFinishedHalfCpltCallback : TIM PWM Pulse Finished half complete Callback.
    (+) ErrorCallback                     : TIM Error Callback.
    (+) CommutationCallback               : TIM Commutation Callback.
    (+) CommutationHalfCpltCallback       : TIM Commutation half complete Callback.
    (+) BreakCallback                     : TIM Break Callback.

[..]
By default, after the Init and when the state is HAL_TIM_STATE_RESET
all interrupt callbacks are set to the corresponding weak functions:
  examples @ref HAL_TIM_TriggerCallback(), @ref HAL_TIM_ErrorCallback().

默认,所有的Callback为Weak的调用,这些weak的调用是空的,需要用户重写

[..]
  Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
  functionalities in the Init / DeInit only when these callbacks are null
  (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init / DeInit
    keep and use the user MspInit / MspDeInit callbacks(registered beforehand)

初始化的先调用初始化函数,再调用初始化回调函数

[..]
    Callbacks can be registered / unregistered in HAL_TIM_STATE_READY state only.
    Exception done MspInit / MspDeInit that can be registered / unregistered
    in HAL_TIM_STATE_READY or HAL_TIM_STATE_RESET state,
    thus registered(user) MspInit / DeInit callbacks can be used during the Init / DeInit.
  In that case first register the MspInit/MspDeInit user callbacks
      using @ref HAL_TIM_RegisterCallback() before calling DeInit or Init function.

回调函数,只能在HAL_TIM_STATE_READY情况下才能注册,初始化在READY和RESET两个状态都可以注册。

初始化的话,如果同时有注册函数和初始化函数,那么会先调用回调函数。

[..]
      When The compilation define USE_HAL_TIM_REGISTER_CALLBACKS is set to 0 or
      not defined, the callback registration feature is not available and all callbacks
      are set to the corresponding weak functions.

宏定义如果是0,所有的回调函数都只调用WEAK.

@endverbatim
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */

STM32F103 - CubeMX 的使用实例详细(04.5)- STM32F103的 - 定时器设定详细解释 - 定时器相关的HAL接口函数 - 定时器的中断相关推荐

  1. STM32 - CubeMX 的使用实例详细(04.1)- STM32F103的 - 定时器设定详细解释 - PWM波的产生 - 频率占空比的设定 - 软件代码分析

    前言:本文详细条例STM32 103定时器的设定 1 定时器简介 中等容量的STM32F103xx增强型系列产品包含1个高级控制定时器.3个普通定时器,以及2个看门 狗定时器和1个系统嘀嗒定时器. 下 ...

  2. STM32F103 - CubeMX 的使用实例详细(03)- 时钟配置 - 最大72M时钟的设定

    1 STM32F103 的时钟树: 从时钟树里面,我们可以看到,最大的时钟周期可以设为72M 2 STM32F103的Cube MX设定 2.1 如果采用内部时钟, 设置最大为64M,如下: 我们发现 ...

  3. Ubuntu16.04 安装ROS Kinetic 究级详细教程

    Ubuntu16.04 安装ROS Kinetic 究级详细教程 1. "软件和更新"进行配置 1.1 Ubuntu Software 1.2 Other Software 2. ...

  4. linux版本的qq怎么安装路径,Ubuntu 16.04安装QQ国际版图文详细教程

    因工作需要,我安装了Ubuntu 16.04,但是工作上的很多事情需要QQ联系,然而在Ubuntu上的WebQQ很是不好用,于是在网上搜索了好多个Linux版本的QQ,然而不是功能不全,就是界面丑到爆 ...

  5. mysql超详细教程_MySQL8.0.23安装超详细教程

    前言 最近在做一个人脸识别的项目,需要用数据库保存学生信息与前段交互. MySQL的优点 1.mysql性能卓越,服务稳定,很少出现异常宕机. 2.mysql开放源代码且无版权制约,自主性及使用成本低 ...

  6. linux如何运行verilog,linux系统下ncverilog的详细命令linux系统下ncverilog的详细命令.doc...

    linux系统下ncverilog的详细命令linux系统下ncverilog的详细命令 ncverilog: 08.10-p002: (c) Copyright 1995-2008 Cadence ...

  7. java timer线程结束_Java线程Timer定时器用法详细总结

    定时/计划功能主要使用的就是Timer对象,它在内部还是使用多线程的方式进行处理,所以它和线程技术还是有非常大的关联. Timer类主要作用就是设置计划任务,但封装任务的类却是TimerTask类.T ...

  8. mysql连接idea详细教程_idea配置连接数据库的超详细步骤

    学习时,使用IDEA的时候,需要连接Database,连接时遇到了一些小问题,下面记录一下操作流程以及遇到的问题的解决方法. 一. 连接操作 简介:介绍如何创建连接,具体连接某个数据库的操作流程. 1 ...

  9. 定时线程的使用 java_Java线程Timer定时器用法详细总结

    定时/计划功能主要使用的就是Timer对象,它在内部还是使用多线程的方式进行处理,所以它和线程技术还是有非常大的关联. Timer类主要作用就是设置计划任务,但封装任务的类却是TimerTask类.T ...

最新文章

  1. Jenkins使用遇到的问题总结
  2. STL,ATL,WTL之间的联系和区别
  3. Python零基础学习笔记(二十二)—— set
  4. Docker php 环境搭建dockerfile
  5. date、sleep和usleep命令
  6. CCNA-第十二篇-STP+ACL(下)
  7. python 3.6.5编译安装_Linux系统安装Python3.6.5
  8. 阿里的 RocketMQ 如何让双十一峰值之下0故障
  9. B端产品经理,应从哪些方面理解业务?
  10. 深度学习(二十一)基于FCN的图像语义分割
  11. 必须掌握的Python技巧(一)
  12. 经纬创投:我们研究了200多家公司的融资条款,告诉你如何防止被“套路”
  13. 在线IDE的原理及设计思路 以Java为例
  14. 网易云课堂-数据结构
  15. 接口测试一般都需要注意哪些方面
  16. 使用Python统计股票高开后的走势
  17. 如何让word文档中的代码格式优雅
  18. [附源码]Python计算机毕业设计电脑配件仓储后台管理系统
  19. 如何在Mac上查找WiFi密码并在iPhone上共享它?
  20. keil (MDK + C51) 安装

热门文章

  1. leetcode 最长回文子串
  2. Windows/Linux服务器上Tomcat开启远程调试,使用IDEA本地调试
  3. Centos7 安装samba简单教程
  4. 【C语言】输入一个三位数,逆序输出
  5. db2 本地db 到实例_如何登录到FreeCodeCamp的本地实例
  6. react 组件引用组件_自定位React组件
  7. java调用sqlserver存储过程_Java中调用SQLServer存储过程示例
  8. 苹果电脑投屏到电视_最全小米电视投屏官方教程公布:手机、PC、APP通吃
  9. Part1 R语言的基本操作
  10. Mysql数据库——数据表的优化、外键与三范式