STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
stm32f4xx_hal_lptim.c File Reference

LPTIM HAL module driver. This file provides firmware functions to manage the following functionalities of the Low Power Timer (LPTIM) peripheral: More...

#include "stm32f4xx_hal.h"
Include dependency graph for stm32f4xx_hal_lptim.c:

Go to the source code of this file.

Macros

#define TIMEOUT   1000UL /* Timeout is 1s */
 

Functions

static HAL_StatusTypeDef LPTIM_WaitForFlag (const LPTIM_HandleTypeDef *hlptim, uint32_t flag)
 LPTimer Wait for flag set.
 
HAL_StatusTypeDef HAL_LPTIM_Init (LPTIM_HandleTypeDef *hlptim)
 Initialize the LPTIM according to the specified parameters in the LPTIM_InitTypeDef and initialize the associated handle.
 
HAL_StatusTypeDef HAL_LPTIM_DeInit (LPTIM_HandleTypeDef *hlptim)
 DeInitialize the LPTIM peripheral.
 
void HAL_LPTIM_MspInit (LPTIM_HandleTypeDef *hlptim)
 Initialize the LPTIM MSP.
 
void HAL_LPTIM_MspDeInit (LPTIM_HandleTypeDef *hlptim)
 DeInitialize LPTIM MSP.
 
HAL_StatusTypeDef HAL_LPTIM_PWM_Start (LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
 Start the LPTIM PWM generation.
 
HAL_StatusTypeDef HAL_LPTIM_PWM_Stop (LPTIM_HandleTypeDef *hlptim)
 Stop the LPTIM PWM generation.
 
HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT (LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
 Start the LPTIM PWM generation in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT (LPTIM_HandleTypeDef *hlptim)
 Stop the LPTIM PWM generation in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start (LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
 Start the LPTIM One pulse generation.
 
HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop (LPTIM_HandleTypeDef *hlptim)
 Stop the LPTIM One pulse generation.
 
HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT (LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
 Start the LPTIM One pulse generation in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT (LPTIM_HandleTypeDef *hlptim)
 Stop the LPTIM One pulse generation in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start (LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
 Start the LPTIM in Set once mode.
 
HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop (LPTIM_HandleTypeDef *hlptim)
 Stop the LPTIM Set once mode.
 
HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT (LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
 Start the LPTIM Set once mode in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT (LPTIM_HandleTypeDef *hlptim)
 Stop the LPTIM Set once mode in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_Encoder_Start (LPTIM_HandleTypeDef *hlptim, uint32_t Period)
 Start the Encoder interface.
 
HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop (LPTIM_HandleTypeDef *hlptim)
 Stop the Encoder interface.
 
HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT (LPTIM_HandleTypeDef *hlptim, uint32_t Period)
 Start the Encoder interface in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT (LPTIM_HandleTypeDef *hlptim)
 Stop the Encoder interface in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start (LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
 Start the Timeout function.
 
HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop (LPTIM_HandleTypeDef *hlptim)
 Stop the Timeout function.
 
HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT (LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
 Start the Timeout function in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT (LPTIM_HandleTypeDef *hlptim)
 Stop the Timeout function in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_Counter_Start (LPTIM_HandleTypeDef *hlptim, uint32_t Period)
 Start the Counter mode.
 
HAL_StatusTypeDef HAL_LPTIM_Counter_Stop (LPTIM_HandleTypeDef *hlptim)
 Stop the Counter mode.
 
HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT (LPTIM_HandleTypeDef *hlptim, uint32_t Period)
 Start the Counter mode in interrupt mode.
 
HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT (LPTIM_HandleTypeDef *hlptim)
 Stop the Counter mode in interrupt mode.
 
uint32_t HAL_LPTIM_ReadCounter (const LPTIM_HandleTypeDef *hlptim)
 Return the current counter value.
 
uint32_t HAL_LPTIM_ReadAutoReload (const LPTIM_HandleTypeDef *hlptim)
 Return the current Autoreload (Period) value.
 
uint32_t HAL_LPTIM_ReadCompare (const LPTIM_HandleTypeDef *hlptim)
 Return the current Compare (Pulse) value.
 
void HAL_LPTIM_IRQHandler (LPTIM_HandleTypeDef *hlptim)
 Handle LPTIM interrupt request.
 
void HAL_LPTIM_CompareMatchCallback (LPTIM_HandleTypeDef *hlptim)
 Compare match callback in non-blocking mode.
 
void HAL_LPTIM_AutoReloadMatchCallback (LPTIM_HandleTypeDef *hlptim)
 Autoreload match callback in non-blocking mode.
 
void HAL_LPTIM_TriggerCallback (LPTIM_HandleTypeDef *hlptim)
 Trigger detected callback in non-blocking mode.
 
void HAL_LPTIM_CompareWriteCallback (LPTIM_HandleTypeDef *hlptim)
 Compare write callback in non-blocking mode.
 
void HAL_LPTIM_AutoReloadWriteCallback (LPTIM_HandleTypeDef *hlptim)
 Autoreload write callback in non-blocking mode.
 
void HAL_LPTIM_DirectionUpCallback (LPTIM_HandleTypeDef *hlptim)
 Direction counter changed from Down to Up callback in non-blocking mode.
 
void HAL_LPTIM_DirectionDownCallback (LPTIM_HandleTypeDef *hlptim)
 Direction counter changed from Up to Down callback in non-blocking mode.
 
HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState (const LPTIM_HandleTypeDef *hlptim)
 Return the LPTIM handle state.
 
void LPTIM_Disable (LPTIM_HandleTypeDef *hlptim)
 Disable LPTIM HW instance.
 

Detailed Description

LPTIM HAL module driver. This file provides firmware functions to manage the following functionalities of the Low Power Timer (LPTIM) peripheral:

Author
MCD Application Team
  • Initialization and de-initialization functions.
  • Start/Stop operation functions in polling mode.
  • Start/Stop operation functions in interrupt mode.
  • Reading operation functions.
  • Peripheral State functions.
Attention

Copyright (c) 2016 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

==============================================================================
                   ##### How to use this driver #####
==============================================================================
  [..]
    The LPTIM HAL driver can be used as follows:

    (#)Initialize the LPTIM low level resources by implementing the
      HAL_LPTIM_MspInit():
       (++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE().
       (++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
           (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
           (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
           (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().

    (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
       configures mainly:
       (++) The instance: LPTIM1.
       (++) Clock: the counter clock.
           (+++) Source   : it can be either the ULPTIM input (IN1) or one of
                            the internal clock; (APB, LSE or LSI).
           (+++) Prescaler: select the clock divider.
       (++)  UltraLowPowerClock : To be used only if the ULPTIM is selected
             as counter clock source.
           (+++) Polarity:   polarity of the active edge for the counter unit
                             if the ULPTIM input is selected.
           (+++) SampleTime: clock sampling time to configure the clock glitch
                             filter.
       (++) Trigger: How the counter start.
           (+++) Source: trigger can be software or one of the hardware triggers.
           (+++) ActiveEdge : only for hardware trigger.
           (+++) SampleTime : trigger sampling time to configure the trigger
                              glitch filter.
       (++) OutputPolarity : 2 opposite polarities are possible.
       (++) UpdateMode: specifies whether the update of the autoreload and
            the compare values is done immediately or after the end of current
            period.

    (#)Six modes are available:

       (++) PWM Mode: To generate a PWM signal with specified period and pulse,
       call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
       mode.

       (++) One Pulse Mode: To generate pulse with specified width in response
       to a stimulus, call HAL_LPTIM_OnePulse_Start() or
       HAL_LPTIM_OnePulse_Start_IT() for interruption mode.

       (++) Set once Mode: In this mode, the output changes the level (from
       low level to high level if the output polarity is configured high, else
       the opposite) when a compare match occurs. To start this mode, call
       HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
       interruption mode.

       (++) Encoder Mode: To use the encoder interface call
       HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
       interruption mode. Only available for LPTIM1 instance.

       (++) Time out Mode: an active edge on one selected trigger input rests
       the counter. The first trigger event will start the timer, any
       successive trigger event will reset the counter and the timer will
       restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or
       HAL_LPTIM_TimeOut_Start_IT() for interruption mode.

       (++) Counter Mode: counter can be used to count external events on
       the LPTIM Input1 or it can be used to count internal clock cycles.
       To start this mode, call HAL_LPTIM_Counter_Start() or
       HAL_LPTIM_Counter_Start_IT() for interruption mode.


    (#) User can stop any process by calling the corresponding API:
        HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
        already started in interruption mode.

    (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit().

  *** Callback registration ***
=============================================
[..]
The compilation define  USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1
allows the user to configure dynamically the driver callbacks.
[..]
Use Function HAL_LPTIM_RegisterCallback() to register a callback.
HAL_LPTIM_RegisterCallback() takes as parameters the HAL peripheral handle,
the Callback ID and a pointer to the user callback function.
[..]
Use function HAL_LPTIM_UnRegisterCallback() to reset a callback to the
default weak function.
HAL_LPTIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
and the Callback ID.
[..]
These functions allow to register/unregister following callbacks:

  (+) MspInitCallback         : LPTIM Base Msp Init Callback.
  (+) MspDeInitCallback       : LPTIM Base Msp DeInit Callback.
  (+) CompareMatchCallback    : Compare match Callback.
  (+) AutoReloadMatchCallback : Auto-reload match Callback.
  (+) TriggerCallback         : External trigger event detection Callback.
  (+) CompareWriteCallback    : Compare register write complete Callback.
  (+) AutoReloadWriteCallback : Auto-reload register write complete Callback.
  (+) DirectionUpCallback     : Up-counting direction change Callback.
  (+) DirectionDownCallback   : Down-counting direction change Callback.

[..]
By default, after the Init and when the state is HAL_LPTIM_STATE_RESET
all interrupt callbacks are set to the corresponding weak functions:
examples HAL_LPTIM_TriggerCallback(), HAL_LPTIM_CompareMatchCallback().

[..]
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_LPTIM_STATE_READY state only.
Exception done MspInit/MspDeInit that can be registered/unregistered
in HAL_LPTIM_STATE_READY or HAL_LPTIM_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 HAL_LPTIM_RegisterCallback() before calling DeInit or Init function.

[..]
When The compilation define USE_HAL_LPTIM_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.

Definition in file stm32f4xx_hal_lptim.c.