STM32L443xx HAL User Manual
stm32l4xx_hal_lptim.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_lptim.c
00004   * @author  MCD Application Team
00005   * @brief   LPTIM HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of the Low Power Timer (LPTIM) peripheral:
00008   *           + Initialization and de-initialization functions.
00009   *           + Start/Stop operation functions in polling mode.
00010   *           + Start/Stop operation functions in interrupt mode.
00011   *           + Reading operation functions.
00012   *           + Peripheral State functions.
00013   *
00014   ******************************************************************************
00015   * @attention
00016   *
00017   * Copyright (c) 2017 STMicroelectronics.
00018   * All rights reserved.
00019   *
00020   * This software is licensed under terms that can be found in the LICENSE file
00021   * in the root directory of this software component.
00022   * If no LICENSE file comes with this software, it is provided AS-IS.
00023   *
00024   ******************************************************************************
00025   @verbatim
00026   ==============================================================================
00027                      ##### How to use this driver #####
00028   ==============================================================================
00029     [..]
00030       The LPTIM HAL driver can be used as follows:
00031 
00032       (#)Initialize the LPTIM low level resources by implementing the
00033         HAL_LPTIM_MspInit():
00034          (++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE().
00035          (++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
00036              (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
00037              (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
00038              (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
00039 
00040       (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
00041          configures mainly:
00042          (++) The instance: LPTIM1 or LPTIM2.
00043          (++) Clock: the counter clock.
00044              (+++) Source   : it can be either the ULPTIM input (IN1) or one of
00045                               the internal clock; (APB, LSE, LSI or MSI).
00046              (+++) Prescaler: select the clock divider.
00047          (++)  UltraLowPowerClock : To be used only if the ULPTIM is selected
00048                as counter clock source.
00049              (+++) Polarity:   polarity of the active edge for the counter unit
00050                                if the ULPTIM input is selected.
00051              (+++) SampleTime: clock sampling time to configure the clock glitch
00052                                filter.
00053          (++) Trigger: How the counter start.
00054              (+++) Source: trigger can be software or one of the hardware triggers.
00055              (+++) ActiveEdge : only for hardware trigger.
00056              (+++) SampleTime : trigger sampling time to configure the trigger
00057                                 glitch filter.
00058          (++) OutputPolarity : 2 opposite polarities are possible.
00059          (++) UpdateMode: specifies whether the update of the autoreload and
00060               the compare values is done immediately or after the end of current
00061               period.
00062          (++) Input1Source: Source selected for input1 (GPIO or comparator output).
00063          (++) Input2Source: Source selected for input2 (GPIO or comparator output).
00064               Input2 is used only for encoder feature so is used only for LPTIM1 instance.
00065 
00066       (#)Six modes are available:
00067 
00068          (++) PWM Mode: To generate a PWM signal with specified period and pulse,
00069          call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
00070          mode.
00071 
00072          (++) One Pulse Mode: To generate pulse with specified width in response
00073          to a stimulus, call HAL_LPTIM_OnePulse_Start() or
00074          HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
00075 
00076          (++) Set once Mode: In this mode, the output changes the level (from
00077          low level to high level if the output polarity is configured high, else
00078          the opposite) when a compare match occurs. To start this mode, call
00079          HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
00080          interruption mode.
00081 
00082          (++) Encoder Mode: To use the encoder interface call
00083          HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
00084          interruption mode. Only available for LPTIM1 instance.
00085 
00086          (++) Time out Mode: an active edge on one selected trigger input rests
00087          the counter. The first trigger event will start the timer, any
00088          successive trigger event will reset the counter and the timer will
00089          restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or
00090          HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
00091 
00092          (++) Counter Mode: counter can be used to count external events on
00093          the LPTIM Input1 or it can be used to count internal clock cycles.
00094          To start this mode, call HAL_LPTIM_Counter_Start() or
00095          HAL_LPTIM_Counter_Start_IT() for interruption mode.
00096 
00097 
00098       (#) User can stop any process by calling the corresponding API:
00099           HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
00100           already started in interruption mode.
00101 
00102       (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit().
00103 
00104     *** Callback registration ***
00105   =============================================
00106   [..]
00107   The compilation define  USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1
00108   allows the user to configure dynamically the driver callbacks.
00109   [..]
00110   Use Function HAL_LPTIM_RegisterCallback() to register a callback.
00111   HAL_LPTIM_RegisterCallback() takes as parameters the HAL peripheral handle,
00112   the Callback ID and a pointer to the user callback function.
00113   [..]
00114   Use function HAL_LPTIM_UnRegisterCallback() to reset a callback to the
00115   default weak function.
00116   HAL_LPTIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
00117   and the Callback ID.
00118   [..]
00119   These functions allow to register/unregister following callbacks:
00120 
00121     (+) MspInitCallback         : LPTIM Base Msp Init Callback.
00122     (+) MspDeInitCallback       : LPTIM Base Msp DeInit Callback.
00123     (+) CompareMatchCallback    : Compare match Callback.
00124     (+) AutoReloadMatchCallback : Auto-reload match Callback.
00125     (+) TriggerCallback         : External trigger event detection Callback.
00126     (+) CompareWriteCallback    : Compare register write complete Callback.
00127     (+) AutoReloadWriteCallback : Auto-reload register write complete Callback.
00128     (+) DirectionUpCallback     : Up-counting direction change Callback.
00129     (+) DirectionDownCallback   : Down-counting direction change Callback.
00130 
00131   [..]
00132   By default, after the Init and when the state is HAL_LPTIM_STATE_RESET
00133   all interrupt callbacks are set to the corresponding weak functions:
00134   examples HAL_LPTIM_TriggerCallback(), HAL_LPTIM_CompareMatchCallback().
00135 
00136   [..]
00137   Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
00138   functionalities in the Init/DeInit only when these callbacks are null
00139   (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init/DeInit
00140   keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
00141 
00142   [..]
00143   Callbacks can be registered/unregistered in HAL_LPTIM_STATE_READY state only.
00144   Exception done MspInit/MspDeInit that can be registered/unregistered
00145   in HAL_LPTIM_STATE_READY or HAL_LPTIM_STATE_RESET state,
00146   thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
00147   In that case first register the MspInit/MspDeInit user callbacks
00148   using HAL_LPTIM_RegisterCallback() before calling DeInit or Init function.
00149 
00150   [..]
00151   When The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or
00152   not defined, the callback registration feature is not available and all callbacks
00153   are set to the corresponding weak functions.
00154 
00155   @endverbatim
00156   ******************************************************************************
00157   */
00158 
00159 /* Includes ------------------------------------------------------------------*/
00160 #include "stm32l4xx_hal.h"
00161 
00162 /** @addtogroup STM32L4xx_HAL_Driver
00163   * @{
00164   */
00165 
00166 /** @defgroup LPTIM LPTIM
00167   * @brief LPTIM HAL module driver.
00168   * @{
00169   */
00170 
00171 #ifdef HAL_LPTIM_MODULE_ENABLED
00172 
00173 #if defined (LPTIM1) || defined (LPTIM2)
00174 
00175 /* Private typedef -----------------------------------------------------------*/
00176 /* Private define ------------------------------------------------------------*/
00177 /** @addtogroup LPTIM_Private_Constants
00178   * @{
00179   */
00180 #define TIMEOUT                                     1000UL /* Timeout is 1s */
00181 /**
00182   * @}
00183   */
00184 
00185 /* Private macro -------------------------------------------------------------*/
00186 /** @addtogroup LPTIM_Private_Macros
00187   * @{
00188   */
00189 #if defined(LPTIM2)
00190 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT(__INSTANCE__) \
00191   (((__INSTANCE__) == LPTIM1) ? __HAL_LPTIM_LPTIM1_EXTI_ENABLE_IT() : __HAL_LPTIM_LPTIM2_EXTI_ENABLE_IT())
00192 
00193 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT(__INSTANCE__) \
00194   (((__INSTANCE__) == LPTIM1) ? __HAL_LPTIM_LPTIM1_EXTI_DISABLE_IT() : __HAL_LPTIM_LPTIM2_EXTI_DISABLE_IT())
00195 #else
00196 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT(__INSTANCE__) __HAL_LPTIM_LPTIM1_EXTI_ENABLE_IT()
00197 
00198 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT(__INSTANCE__) __HAL_LPTIM_LPTIM1_EXTI_DISABLE_IT()
00199 #endif /* LPTIM2 */
00200 /**
00201   * @}
00202   */
00203 
00204 /* Private variables ---------------------------------------------------------*/
00205 /* Private function prototypes -----------------------------------------------*/
00206 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
00207 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim);
00208 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
00209 static HAL_StatusTypeDef LPTIM_WaitForFlag(LPTIM_HandleTypeDef *hlptim, uint32_t flag);
00210 
00211 /* Exported functions --------------------------------------------------------*/
00212 
00213 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
00214   * @{
00215   */
00216 
00217 /** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions
00218   *  @brief    Initialization and Configuration functions.
00219   *
00220 @verbatim
00221   ==============================================================================
00222               ##### Initialization and de-initialization functions #####
00223   ==============================================================================
00224     [..]  This section provides functions allowing to:
00225       (+) Initialize the LPTIM according to the specified parameters in the
00226           LPTIM_InitTypeDef and initialize the associated handle.
00227       (+) DeInitialize the LPTIM peripheral.
00228       (+) Initialize the LPTIM MSP.
00229       (+) DeInitialize the LPTIM MSP.
00230 
00231 @endverbatim
00232   * @{
00233   */
00234 
00235 /**
00236   * @brief  Initialize the LPTIM according to the specified parameters in the
00237   *         LPTIM_InitTypeDef and initialize the associated handle.
00238   * @param  hlptim LPTIM handle
00239   * @retval HAL status
00240   */
00241 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
00242 {
00243   uint32_t tmpcfgr;
00244 
00245   /* Check the LPTIM handle allocation */
00246   if (hlptim == NULL)
00247   {
00248     return HAL_ERROR;
00249   }
00250 
00251   /* Check the parameters */
00252   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00253 
00254   assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
00255   assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));
00256   if ((hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_ULPTIM)
00257       || (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
00258   {
00259     assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
00260     assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
00261   }
00262   assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
00263   if (hlptim->Init.Trigger.Source != LPTIM_TRIGSOURCE_SOFTWARE)
00264   {
00265     assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
00266     assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
00267   }
00268   assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));
00269   assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
00270   assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
00271 #if defined(LPTIM_RCR_REP)
00272   assert_param(IS_LPTIM_REPETITION(hlptim->Init.RepetitionCounter));
00273 #endif
00274 
00275   if (hlptim->State == HAL_LPTIM_STATE_RESET)
00276   {
00277     /* Allocate lock resource and initialize it */
00278     hlptim->Lock = HAL_UNLOCKED;
00279 
00280 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
00281     /* Reset interrupt callbacks to legacy weak callbacks */
00282     LPTIM_ResetCallback(hlptim);
00283 
00284     if (hlptim->MspInitCallback == NULL)
00285     {
00286       hlptim->MspInitCallback = HAL_LPTIM_MspInit;
00287     }
00288 
00289     /* Init the low level hardware : GPIO, CLOCK, NVIC */
00290     hlptim->MspInitCallback(hlptim);
00291 #else
00292     /* Init the low level hardware : GPIO, CLOCK, NVIC */
00293     HAL_LPTIM_MspInit(hlptim);
00294 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
00295   }
00296 
00297   /* Change the LPTIM state */
00298   hlptim->State = HAL_LPTIM_STATE_BUSY;
00299 #if defined(LPTIM_RCR_REP)
00300 
00301   /* Enable the Peripheral */
00302   __HAL_LPTIM_ENABLE(hlptim);
00303 
00304   /* Clear flag */
00305   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_REPOK);
00306 
00307   /* Set the repetition counter */
00308   __HAL_LPTIM_REPETITIONCOUNTER_SET(hlptim, hlptim->Init.RepetitionCounter);
00309 
00310   /* Wait for the completion of the write operation to the LPTIM_RCR register */
00311   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_REPOK) == HAL_TIMEOUT)
00312   {
00313     return HAL_TIMEOUT;
00314   }
00315 
00316   /* Disable the Peripheral */
00317   __HAL_LPTIM_DISABLE(hlptim);
00318 
00319   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
00320   {
00321     return HAL_TIMEOUT;
00322   }
00323 
00324 #endif
00325 
00326   /* Get the LPTIMx CFGR value */
00327   tmpcfgr = hlptim->Instance->CFGR;
00328 
00329   if ((hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_ULPTIM)
00330       || (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
00331   {
00332     tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
00333   }
00334   if (hlptim->Init.Trigger.Source != LPTIM_TRIGSOURCE_SOFTWARE)
00335   {
00336     tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
00337   }
00338 
00339   /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
00340   tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
00341                           LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE));
00342 
00343   /* Set initialization parameters */
00344   tmpcfgr |= (hlptim->Init.Clock.Source    |
00345               hlptim->Init.Clock.Prescaler |
00346               hlptim->Init.OutputPolarity  |
00347               hlptim->Init.UpdateMode      |
00348               hlptim->Init.CounterSource);
00349 
00350   /* Glitch filters for internal triggers and  external inputs are configured
00351    * only if an internal clock source is provided to the LPTIM
00352    */
00353   if (hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC)
00354   {
00355     tmpcfgr |= (hlptim->Init.Trigger.SampleTime |
00356                 hlptim->Init.UltraLowPowerClock.SampleTime);
00357   }
00358 
00359   /* Configure LPTIM external clock polarity and digital filter */
00360   if ((hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_ULPTIM)
00361       || (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
00362   {
00363     tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
00364                 hlptim->Init.UltraLowPowerClock.SampleTime);
00365   }
00366 
00367   /* Configure LPTIM external trigger */
00368   if (hlptim->Init.Trigger.Source != LPTIM_TRIGSOURCE_SOFTWARE)
00369   {
00370     /* Enable External trigger and set the trigger source */
00371     tmpcfgr |= (hlptim->Init.Trigger.Source     |
00372                 hlptim->Init.Trigger.ActiveEdge |
00373                 hlptim->Init.Trigger.SampleTime);
00374   }
00375 
00376   /* Write to LPTIMx CFGR */
00377   hlptim->Instance->CFGR = tmpcfgr;
00378 
00379   /* Configure LPTIM input sources */
00380   if (hlptim->Instance == LPTIM1)
00381   {
00382     /* Check LPTIM Input1 and Input2 sources */
00383     assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance, hlptim->Init.Input1Source));
00384     assert_param(IS_LPTIM_INPUT2_SOURCE(hlptim->Instance, hlptim->Init.Input2Source));
00385 
00386     /* Configure LPTIM Input1 and Input2 sources */
00387     hlptim->Instance->OR = (hlptim->Init.Input1Source | hlptim->Init.Input2Source);
00388   }
00389   else
00390   {
00391     /* Check LPTIM2 Input1 source */
00392     assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance, hlptim->Init.Input1Source));
00393 
00394     /* Configure LPTIM2 Input1 source */
00395     hlptim->Instance->OR = hlptim->Init.Input1Source;
00396   }
00397 
00398   /* Change the LPTIM state */
00399   hlptim->State = HAL_LPTIM_STATE_READY;
00400 
00401   /* Return function status */
00402   return HAL_OK;
00403 }
00404 
00405 /**
00406   * @brief  DeInitialize the LPTIM peripheral.
00407   * @param  hlptim LPTIM handle
00408   * @retval HAL status
00409   */
00410 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
00411 {
00412   /* Check the LPTIM handle allocation */
00413   if (hlptim == NULL)
00414   {
00415     return HAL_ERROR;
00416   }
00417 
00418   /* Change the LPTIM state */
00419   hlptim->State = HAL_LPTIM_STATE_BUSY;
00420 
00421   /* Disable the LPTIM Peripheral Clock */
00422   __HAL_LPTIM_DISABLE(hlptim);
00423 
00424   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
00425   {
00426     return HAL_TIMEOUT;
00427   }
00428 
00429 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
00430   if (hlptim->MspDeInitCallback == NULL)
00431   {
00432     hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
00433   }
00434 
00435   /* DeInit the low level hardware: CLOCK, NVIC.*/
00436   hlptim->MspDeInitCallback(hlptim);
00437 #else
00438   /* DeInit the low level hardware: CLOCK, NVIC.*/
00439   HAL_LPTIM_MspDeInit(hlptim);
00440 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
00441 
00442   /* Change the LPTIM state */
00443   hlptim->State = HAL_LPTIM_STATE_RESET;
00444 
00445   /* Release Lock */
00446   __HAL_UNLOCK(hlptim);
00447 
00448   /* Return function status */
00449   return HAL_OK;
00450 }
00451 
00452 /**
00453   * @brief  Initialize the LPTIM MSP.
00454   * @param  hlptim LPTIM handle
00455   * @retval None
00456   */
00457 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
00458 {
00459   /* Prevent unused argument(s) compilation warning */
00460   UNUSED(hlptim);
00461 
00462   /* NOTE : This function should not be modified, when the callback is needed,
00463             the HAL_LPTIM_MspInit could be implemented in the user file
00464    */
00465 }
00466 
00467 /**
00468   * @brief  DeInitialize LPTIM MSP.
00469   * @param  hlptim LPTIM handle
00470   * @retval None
00471   */
00472 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
00473 {
00474   /* Prevent unused argument(s) compilation warning */
00475   UNUSED(hlptim);
00476 
00477   /* NOTE : This function should not be modified, when the callback is needed,
00478             the HAL_LPTIM_MspDeInit could be implemented in the user file
00479    */
00480 }
00481 
00482 /**
00483   * @}
00484   */
00485 
00486 /** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions
00487   *  @brief   Start-Stop operation functions.
00488   *
00489 @verbatim
00490   ==============================================================================
00491                 ##### LPTIM Start Stop operation functions #####
00492   ==============================================================================
00493     [..]  This section provides functions allowing to:
00494       (+) Start the PWM mode.
00495       (+) Stop the PWM mode.
00496       (+) Start the One pulse mode.
00497       (+) Stop the One pulse mode.
00498       (+) Start the Set once mode.
00499       (+) Stop the Set once mode.
00500       (+) Start the Encoder mode.
00501       (+) Stop the Encoder mode.
00502       (+) Start the Timeout mode.
00503       (+) Stop the Timeout mode.
00504       (+) Start the Counter mode.
00505       (+) Stop the Counter mode.
00506 
00507 
00508 @endverbatim
00509   * @{
00510   */
00511 
00512 /**
00513   * @brief  Start the LPTIM PWM generation.
00514   * @param  hlptim LPTIM handle
00515   * @param  Period Specifies the Autoreload value.
00516   *         This parameter must be a value between 0x0000 and 0xFFFF.
00517   * @param  Pulse Specifies the compare value.
00518   *         This parameter must be a value between 0x0000 and 0xFFFF.
00519   * @retval HAL status
00520   */
00521 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00522 {
00523   /* Check the parameters */
00524   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00525   assert_param(IS_LPTIM_PERIOD(Period));
00526   assert_param(IS_LPTIM_PULSE(Pulse));
00527 
00528   /* Set the LPTIM state */
00529   hlptim->State = HAL_LPTIM_STATE_BUSY;
00530 
00531   /* Reset WAVE bit to set PWM mode */
00532   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00533 
00534   /* Enable the Peripheral */
00535   __HAL_LPTIM_ENABLE(hlptim);
00536 
00537   /* Clear flag */
00538   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
00539 
00540   /* Load the period value in the autoreload register */
00541   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00542 
00543   /* Wait for the completion of the write operation to the LPTIM_ARR register */
00544   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
00545   {
00546     return HAL_TIMEOUT;
00547   }
00548 
00549   /* Clear flag */
00550   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
00551 
00552   /* Load the pulse value in the compare register */
00553   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00554 
00555   /* Wait for the completion of the write operation to the LPTIM_CMP register */
00556   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
00557   {
00558     return HAL_TIMEOUT;
00559   }
00560 
00561   /* Start timer in continuous mode */
00562   __HAL_LPTIM_START_CONTINUOUS(hlptim);
00563 
00564   /* Change the TIM state*/
00565   hlptim->State = HAL_LPTIM_STATE_READY;
00566 
00567   /* Return function status */
00568   return HAL_OK;
00569 }
00570 
00571 /**
00572   * @brief  Stop the LPTIM PWM generation.
00573   * @param  hlptim LPTIM handle
00574   * @retval HAL status
00575   */
00576 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
00577 {
00578   /* Check the parameters */
00579   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00580 
00581   /* Set the LPTIM state */
00582   hlptim->State = HAL_LPTIM_STATE_BUSY;
00583 
00584   /* Disable the Peripheral */
00585   __HAL_LPTIM_DISABLE(hlptim);
00586 
00587   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
00588   {
00589     return HAL_TIMEOUT;
00590   }
00591 
00592   /* Change the LPTIM state*/
00593   hlptim->State = HAL_LPTIM_STATE_READY;
00594 
00595   /* Return function status */
00596   return HAL_OK;
00597 }
00598 
00599 /**
00600   * @brief  Start the LPTIM PWM generation in interrupt mode.
00601   * @param  hlptim LPTIM handle
00602   * @param  Period Specifies the Autoreload value.
00603   *         This parameter must be a value between 0x0000 and 0xFFFF
00604   * @param  Pulse Specifies the compare value.
00605   *         This parameter must be a value between 0x0000 and 0xFFFF
00606   * @retval HAL status
00607   */
00608 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00609 {
00610   /* Check the parameters */
00611   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00612   assert_param(IS_LPTIM_PERIOD(Period));
00613   assert_param(IS_LPTIM_PULSE(Pulse));
00614 
00615   /* Set the LPTIM state */
00616   hlptim->State = HAL_LPTIM_STATE_BUSY;
00617 
00618   /* Reset WAVE bit to set PWM mode */
00619   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00620 
00621   /* Enable the Peripheral */
00622   __HAL_LPTIM_ENABLE(hlptim);
00623 
00624   /* Clear flag */
00625   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
00626 
00627   /* Load the period value in the autoreload register */
00628   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00629 
00630   /* Wait for the completion of the write operation to the LPTIM_ARR register */
00631   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
00632   {
00633     return HAL_TIMEOUT;
00634   }
00635 
00636   /* Clear flag */
00637   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
00638 
00639   /* Load the pulse value in the compare register */
00640   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00641 
00642   /* Wait for the completion of the write operation to the LPTIM_CMP register */
00643   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
00644   {
00645     return HAL_TIMEOUT;
00646   }
00647 
00648   /* Disable the Peripheral */
00649   __HAL_LPTIM_DISABLE(hlptim);
00650 
00651   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
00652   {
00653     return HAL_TIMEOUT;
00654   }
00655 
00656   /* Enable Autoreload write complete interrupt */
00657   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
00658 
00659   /* Enable Compare write complete interrupt */
00660   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
00661 
00662   /* Enable Autoreload match interrupt */
00663   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
00664 
00665   /* Enable Compare match interrupt */
00666   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
00667 
00668   /* If external trigger source is used, then enable external trigger interrupt */
00669   if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
00670   {
00671     /* Enable external trigger interrupt */
00672     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00673   }
00674 #if defined(LPTIM_RCR_REP)
00675 
00676   /* Enable Rep Update Ok interrupt */
00677   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_REPOK);
00678 
00679   /* Enable Update Event interrupt */
00680   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UPDATE);
00681 #endif
00682 
00683   /* Enable the Peripheral */
00684   __HAL_LPTIM_ENABLE(hlptim);
00685 
00686   /* Start timer in continuous mode */
00687   __HAL_LPTIM_START_CONTINUOUS(hlptim);
00688 
00689   /* Change the TIM state*/
00690   hlptim->State = HAL_LPTIM_STATE_READY;
00691 
00692   /* Return function status */
00693   return HAL_OK;
00694 }
00695 
00696 /**
00697   * @brief  Stop the LPTIM PWM generation in interrupt mode.
00698   * @param  hlptim LPTIM handle
00699   * @retval HAL status
00700   */
00701 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
00702 {
00703   /* Check the parameters */
00704   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00705 
00706   /* Set the LPTIM state */
00707   hlptim->State = HAL_LPTIM_STATE_BUSY;
00708 
00709   /* Disable the Peripheral */
00710   __HAL_LPTIM_DISABLE(hlptim);
00711 
00712   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
00713   {
00714     return HAL_TIMEOUT;
00715   }
00716 
00717   /* Disable Autoreload write complete interrupt */
00718   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
00719 
00720   /* Disable Compare write complete interrupt */
00721   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
00722 
00723   /* Disable Autoreload match interrupt */
00724   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
00725 
00726   /* Disable Compare match interrupt */
00727   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
00728 
00729   /* If external trigger source is used, then disable external trigger interrupt */
00730   if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
00731   {
00732     /* Disable external trigger interrupt */
00733     __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00734   }
00735 #if defined(LPTIM_RCR_REP)
00736 
00737   /* Enable Rep Update Ok interrupt */
00738   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_REPOK);
00739 
00740   /* Enable Update Event interrupt */
00741   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UPDATE);
00742 #endif
00743 
00744   /* Change the LPTIM state*/
00745   hlptim->State = HAL_LPTIM_STATE_READY;
00746 
00747   /* Return function status */
00748   return HAL_OK;
00749 }
00750 
00751 /**
00752   * @brief  Start the LPTIM One pulse generation.
00753   * @param  hlptim LPTIM handle
00754   * @param  Period Specifies the Autoreload value.
00755   *         This parameter must be a value between 0x0000 and 0xFFFF.
00756   * @param  Pulse Specifies the compare value.
00757   *         This parameter must be a value between 0x0000 and 0xFFFF.
00758   * @retval HAL status
00759   */
00760 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00761 {
00762   /* Check the parameters */
00763   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00764   assert_param(IS_LPTIM_PERIOD(Period));
00765   assert_param(IS_LPTIM_PULSE(Pulse));
00766 
00767   /* Set the LPTIM state */
00768   hlptim->State = HAL_LPTIM_STATE_BUSY;
00769 
00770   /* Reset WAVE bit to set one pulse mode */
00771   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00772 
00773   /* Enable the Peripheral */
00774   __HAL_LPTIM_ENABLE(hlptim);
00775 
00776   /* Clear flag */
00777   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
00778 
00779   /* Load the period value in the autoreload register */
00780   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00781 
00782   /* Wait for the completion of the write operation to the LPTIM_ARR register */
00783   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
00784   {
00785     return HAL_TIMEOUT;
00786   }
00787 
00788   /* Clear flag */
00789   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
00790 
00791   /* Load the pulse value in the compare register */
00792   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00793 
00794   /* Wait for the completion of the write operation to the LPTIM_CMP register */
00795   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
00796   {
00797     return HAL_TIMEOUT;
00798   }
00799 
00800   /* Start timer in single (one shot) mode */
00801   __HAL_LPTIM_START_SINGLE(hlptim);
00802 
00803   /* Change the TIM state*/
00804   hlptim->State = HAL_LPTIM_STATE_READY;
00805 
00806   /* Return function status */
00807   return HAL_OK;
00808 }
00809 
00810 /**
00811   * @brief  Stop the LPTIM One pulse generation.
00812   * @param  hlptim LPTIM handle
00813   * @retval HAL status
00814   */
00815 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
00816 {
00817   /* Check the parameters */
00818   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00819 
00820   /* Set the LPTIM state */
00821   hlptim->State = HAL_LPTIM_STATE_BUSY;
00822 
00823   /* Disable the Peripheral */
00824   __HAL_LPTIM_DISABLE(hlptim);
00825 
00826   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
00827   {
00828     return HAL_TIMEOUT;
00829   }
00830 
00831   /* Change the LPTIM state*/
00832   hlptim->State = HAL_LPTIM_STATE_READY;
00833 
00834   /* Return function status */
00835   return HAL_OK;
00836 }
00837 
00838 /**
00839   * @brief  Start the LPTIM One pulse generation in interrupt mode.
00840   * @param  hlptim LPTIM handle
00841   * @param  Period Specifies the Autoreload value.
00842   *         This parameter must be a value between 0x0000 and 0xFFFF.
00843   * @param  Pulse Specifies the compare value.
00844   *         This parameter must be a value between 0x0000 and 0xFFFF.
00845   * @retval HAL status
00846   */
00847 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00848 {
00849   /* Check the parameters */
00850   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00851   assert_param(IS_LPTIM_PERIOD(Period));
00852   assert_param(IS_LPTIM_PULSE(Pulse));
00853 
00854   /* Set the LPTIM state */
00855   hlptim->State = HAL_LPTIM_STATE_BUSY;
00856 
00857   /* Reset WAVE bit to set one pulse mode */
00858   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00859 
00860   /* Enable the Peripheral */
00861   __HAL_LPTIM_ENABLE(hlptim);
00862 
00863   /* Clear flag */
00864   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
00865 
00866   /* Load the period value in the autoreload register */
00867   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00868 
00869   /* Wait for the completion of the write operation to the LPTIM_ARR register */
00870   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
00871   {
00872     return HAL_TIMEOUT;
00873   }
00874 
00875   /* Clear flag */
00876   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
00877 
00878   /* Load the pulse value in the compare register */
00879   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00880 
00881   /* Wait for the completion of the write operation to the LPTIM_CMP register */
00882   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
00883   {
00884     return HAL_TIMEOUT;
00885   }
00886 
00887   /* Disable the Peripheral */
00888   __HAL_LPTIM_DISABLE(hlptim);
00889 
00890   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
00891   {
00892     return HAL_TIMEOUT;
00893   }
00894 
00895   /* Enable Autoreload write complete interrupt */
00896   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
00897 
00898   /* Enable Compare write complete interrupt */
00899   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
00900 
00901   /* Enable Autoreload match interrupt */
00902   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
00903 
00904   /* Enable Compare match interrupt */
00905   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
00906 
00907   /* If external trigger source is used, then enable external trigger interrupt */
00908   if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
00909   {
00910     /* Enable external trigger interrupt */
00911     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00912   }
00913 #if defined(LPTIM_RCR_REP)
00914 
00915   /* Enable Rep Update Ok interrupt */
00916   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_REPOK);
00917 
00918   /* Enable Update Event interrupt */
00919   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UPDATE);
00920 #endif
00921 
00922   /* Enable the Peripheral */
00923   __HAL_LPTIM_ENABLE(hlptim);
00924 
00925   /* Start timer in single (one shot) mode */
00926   __HAL_LPTIM_START_SINGLE(hlptim);
00927 
00928   /* Change the TIM state*/
00929   hlptim->State = HAL_LPTIM_STATE_READY;
00930 
00931   /* Return function status */
00932   return HAL_OK;
00933 }
00934 
00935 /**
00936   * @brief  Stop the LPTIM One pulse generation in interrupt mode.
00937   * @param  hlptim LPTIM handle
00938   * @retval HAL status
00939   */
00940 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
00941 {
00942   /* Check the parameters */
00943   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00944 
00945   /* Set the LPTIM state */
00946   hlptim->State = HAL_LPTIM_STATE_BUSY;
00947 
00948   /* Disable the Peripheral */
00949   __HAL_LPTIM_DISABLE(hlptim);
00950 
00951   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
00952   {
00953     return HAL_TIMEOUT;
00954   }
00955 
00956   /* Disable Autoreload write complete interrupt */
00957   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
00958 
00959   /* Disable Compare write complete interrupt */
00960   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
00961 
00962   /* Disable Autoreload match interrupt */
00963   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
00964 
00965   /* Disable Compare match interrupt */
00966   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
00967 
00968   /* If external trigger source is used, then disable external trigger interrupt */
00969   if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
00970   {
00971     /* Disable external trigger interrupt */
00972     __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00973   }
00974 #if defined(LPTIM_RCR_REP)
00975 
00976   /* Enable Rep Update Ok interrupt */
00977   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_REPOK);
00978 
00979   /* Enable Update Event interrupt */
00980   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UPDATE);
00981 #endif
00982 
00983   /* Change the LPTIM state*/
00984   hlptim->State = HAL_LPTIM_STATE_READY;
00985 
00986   /* Return function status */
00987   return HAL_OK;
00988 }
00989 
00990 /**
00991   * @brief  Start the LPTIM in Set once mode.
00992   * @param  hlptim LPTIM handle
00993   * @param  Period Specifies the Autoreload value.
00994   *         This parameter must be a value between 0x0000 and 0xFFFF.
00995   * @param  Pulse Specifies the compare value.
00996   *         This parameter must be a value between 0x0000 and 0xFFFF.
00997   * @retval HAL status
00998   */
00999 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
01000 {
01001   /* Check the parameters */
01002   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01003   assert_param(IS_LPTIM_PERIOD(Period));
01004   assert_param(IS_LPTIM_PULSE(Pulse));
01005 
01006   /* Set the LPTIM state */
01007   hlptim->State = HAL_LPTIM_STATE_BUSY;
01008 
01009   /* Set WAVE bit to enable the set once mode */
01010   hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
01011 
01012   /* Enable the Peripheral */
01013   __HAL_LPTIM_ENABLE(hlptim);
01014 
01015   /* Clear flag */
01016   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01017 
01018   /* Load the period value in the autoreload register */
01019   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01020 
01021   /* Wait for the completion of the write operation to the LPTIM_ARR register */
01022   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
01023   {
01024     return HAL_TIMEOUT;
01025   }
01026 
01027   /* Clear flag */
01028   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
01029 
01030   /* Load the pulse value in the compare register */
01031   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
01032 
01033   /* Wait for the completion of the write operation to the LPTIM_CMP register */
01034   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
01035   {
01036     return HAL_TIMEOUT;
01037   }
01038 
01039   /* Start timer in single (one shot) mode */
01040   __HAL_LPTIM_START_SINGLE(hlptim);
01041 
01042   /* Change the TIM state*/
01043   hlptim->State = HAL_LPTIM_STATE_READY;
01044 
01045   /* Return function status */
01046   return HAL_OK;
01047 }
01048 
01049 /**
01050   * @brief  Stop the LPTIM Set once mode.
01051   * @param  hlptim LPTIM handle
01052   * @retval HAL status
01053   */
01054 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
01055 {
01056   /* Check the parameters */
01057   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01058 
01059   /* Set the LPTIM state */
01060   hlptim->State = HAL_LPTIM_STATE_BUSY;
01061 
01062   /* Disable the Peripheral */
01063   __HAL_LPTIM_DISABLE(hlptim);
01064 
01065   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01066   {
01067     return HAL_TIMEOUT;
01068   }
01069 
01070   /* Change the LPTIM state*/
01071   hlptim->State = HAL_LPTIM_STATE_READY;
01072 
01073   /* Return function status */
01074   return HAL_OK;
01075 }
01076 
01077 /**
01078   * @brief  Start the LPTIM Set once mode in interrupt mode.
01079   * @param  hlptim LPTIM handle
01080   * @param  Period Specifies the Autoreload value.
01081   *         This parameter must be a value between 0x0000 and 0xFFFF.
01082   * @param  Pulse Specifies the compare value.
01083   *         This parameter must be a value between 0x0000 and 0xFFFF.
01084   * @retval HAL status
01085   */
01086 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
01087 {
01088   /* Check the parameters */
01089   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01090   assert_param(IS_LPTIM_PERIOD(Period));
01091   assert_param(IS_LPTIM_PULSE(Pulse));
01092 
01093   /* Set the LPTIM state */
01094   hlptim->State = HAL_LPTIM_STATE_BUSY;
01095 
01096   /* Set WAVE bit to enable the set once mode */
01097   hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
01098 
01099   /* Enable the Peripheral */
01100   __HAL_LPTIM_ENABLE(hlptim);
01101 
01102   /* Clear flag */
01103   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01104 
01105   /* Load the period value in the autoreload register */
01106   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01107 
01108   /* Wait for the completion of the write operation to the LPTIM_ARR register */
01109   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
01110   {
01111     return HAL_TIMEOUT;
01112   }
01113 
01114   /* Clear flag */
01115   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
01116 
01117   /* Load the pulse value in the compare register */
01118   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
01119 
01120   /* Wait for the completion of the write operation to the LPTIM_CMP register */
01121   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
01122   {
01123     return HAL_TIMEOUT;
01124   }
01125 
01126   /* Disable the Peripheral */
01127   __HAL_LPTIM_DISABLE(hlptim);
01128 
01129   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01130   {
01131     return HAL_TIMEOUT;
01132   }
01133 
01134   /* Enable Autoreload write complete interrupt */
01135   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
01136 
01137   /* Enable Compare write complete interrupt */
01138   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
01139 
01140   /* Enable Autoreload match interrupt */
01141   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
01142 
01143   /* Enable Compare match interrupt */
01144   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
01145 
01146   /* If external trigger source is used, then enable external trigger interrupt */
01147   if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
01148   {
01149     /* Enable external trigger interrupt */
01150     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
01151   }
01152 
01153   /* Enable the Peripheral */
01154   __HAL_LPTIM_ENABLE(hlptim);
01155 
01156   /* Start timer in single (one shot) mode */
01157   __HAL_LPTIM_START_SINGLE(hlptim);
01158 
01159   /* Change the TIM state*/
01160   hlptim->State = HAL_LPTIM_STATE_READY;
01161 
01162   /* Return function status */
01163   return HAL_OK;
01164 }
01165 
01166 /**
01167   * @brief  Stop the LPTIM Set once mode in interrupt mode.
01168   * @param  hlptim LPTIM handle
01169   * @retval HAL status
01170   */
01171 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01172 {
01173   /* Check the parameters */
01174   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01175 
01176   /* Set the LPTIM state */
01177   hlptim->State = HAL_LPTIM_STATE_BUSY;
01178 
01179   /* Disable the Peripheral */
01180   __HAL_LPTIM_DISABLE(hlptim);
01181 
01182   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01183   {
01184     return HAL_TIMEOUT;
01185   }
01186 
01187   /* Disable Autoreload write complete interrupt */
01188   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
01189 
01190   /* Disable Compare write complete interrupt */
01191   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
01192 
01193   /* Disable Autoreload match interrupt */
01194   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
01195 
01196   /* Disable Compare match interrupt */
01197   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
01198 
01199   /* If external trigger source is used, then disable external trigger interrupt */
01200   if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
01201   {
01202     /* Disable external trigger interrupt */
01203     __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
01204   }
01205 
01206   /* Change the LPTIM state*/
01207   hlptim->State = HAL_LPTIM_STATE_READY;
01208 
01209   /* Return function status */
01210   return HAL_OK;
01211 }
01212 
01213 /**
01214   * @brief  Start the Encoder interface.
01215   * @param  hlptim LPTIM handle
01216   * @param  Period Specifies the Autoreload value.
01217   *         This parameter must be a value between 0x0000 and 0xFFFF.
01218   * @retval HAL status
01219   */
01220 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
01221 {
01222   uint32_t          tmpcfgr;
01223 
01224   /* Check the parameters */
01225   assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance));
01226   assert_param(IS_LPTIM_PERIOD(Period));
01227   assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
01228   assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
01229   assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
01230 
01231   /* Set the LPTIM state */
01232   hlptim->State = HAL_LPTIM_STATE_BUSY;
01233 
01234   /* Get the LPTIMx CFGR value */
01235   tmpcfgr = hlptim->Instance->CFGR;
01236 
01237   /* Clear CKPOL bits */
01238   tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
01239 
01240   /* Set Input polarity */
01241   tmpcfgr |=  hlptim->Init.UltraLowPowerClock.Polarity;
01242 
01243   /* Write to LPTIMx CFGR */
01244   hlptim->Instance->CFGR = tmpcfgr;
01245 
01246   /* Set ENC bit to enable the encoder interface */
01247   hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
01248 
01249   /* Enable the Peripheral */
01250   __HAL_LPTIM_ENABLE(hlptim);
01251 
01252   /* Clear flag */
01253   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01254 
01255   /* Load the period value in the autoreload register */
01256   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01257 
01258   /* Wait for the completion of the write operation to the LPTIM_ARR register */
01259   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
01260   {
01261     return HAL_TIMEOUT;
01262   }
01263 
01264   /* Start timer in continuous mode */
01265   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01266 
01267   /* Change the TIM state*/
01268   hlptim->State = HAL_LPTIM_STATE_READY;
01269 
01270   /* Return function status */
01271   return HAL_OK;
01272 }
01273 
01274 /**
01275   * @brief  Stop the Encoder interface.
01276   * @param  hlptim LPTIM handle
01277   * @retval HAL status
01278   */
01279 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
01280 {
01281   /* Check the parameters */
01282   assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance));
01283 
01284   /* Set the LPTIM state */
01285   hlptim->State = HAL_LPTIM_STATE_BUSY;
01286 
01287   /* Disable the Peripheral */
01288   __HAL_LPTIM_DISABLE(hlptim);
01289 
01290   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01291   {
01292     return HAL_TIMEOUT;
01293   }
01294 
01295   /* Reset ENC bit to disable the encoder interface */
01296   hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
01297 
01298   /* Change the TIM state*/
01299   hlptim->State = HAL_LPTIM_STATE_READY;
01300 
01301   /* Return function status */
01302   return HAL_OK;
01303 }
01304 
01305 /**
01306   * @brief  Start the Encoder interface in interrupt mode.
01307   * @param  hlptim LPTIM handle
01308   * @param  Period Specifies the Autoreload value.
01309   *         This parameter must be a value between 0x0000 and 0xFFFF.
01310   * @retval HAL status
01311   */
01312 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
01313 {
01314   uint32_t          tmpcfgr;
01315 
01316   /* Check the parameters */
01317   assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance));
01318   assert_param(IS_LPTIM_PERIOD(Period));
01319   assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
01320   assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
01321   assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
01322 
01323   /* Set the LPTIM state */
01324   hlptim->State = HAL_LPTIM_STATE_BUSY;
01325 
01326   /* Configure edge sensitivity for encoder mode */
01327   /* Get the LPTIMx CFGR value */
01328   tmpcfgr = hlptim->Instance->CFGR;
01329 
01330   /* Clear CKPOL bits */
01331   tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
01332 
01333   /* Set Input polarity */
01334   tmpcfgr |=  hlptim->Init.UltraLowPowerClock.Polarity;
01335 
01336   /* Write to LPTIMx CFGR */
01337   hlptim->Instance->CFGR = tmpcfgr;
01338 
01339   /* Set ENC bit to enable the encoder interface */
01340   hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
01341 
01342   /* Enable the Peripheral */
01343   __HAL_LPTIM_ENABLE(hlptim);
01344 
01345   /* Clear flag */
01346   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01347 
01348   /* Load the period value in the autoreload register */
01349   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01350 
01351   /* Wait for the completion of the write operation to the LPTIM_ARR register */
01352   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
01353   {
01354     return HAL_TIMEOUT;
01355   }
01356 
01357   /* Disable the Peripheral */
01358   __HAL_LPTIM_DISABLE(hlptim);
01359 
01360   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01361   {
01362     return HAL_TIMEOUT;
01363   }
01364 
01365   /* Enable "switch to down direction" interrupt */
01366   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
01367 
01368   /* Enable "switch to up direction" interrupt */
01369   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
01370 
01371   /* Enable the Peripheral */
01372   __HAL_LPTIM_ENABLE(hlptim);
01373 
01374   /* Start timer in continuous mode */
01375   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01376 
01377   /* Change the TIM state*/
01378   hlptim->State = HAL_LPTIM_STATE_READY;
01379 
01380   /* Return function status */
01381   return HAL_OK;
01382 }
01383 
01384 /**
01385   * @brief  Stop the Encoder interface in interrupt mode.
01386   * @param  hlptim LPTIM handle
01387   * @retval HAL status
01388   */
01389 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01390 {
01391   /* Check the parameters */
01392   assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance));
01393 
01394   /* Set the LPTIM state */
01395   hlptim->State = HAL_LPTIM_STATE_BUSY;
01396 
01397   /* Disable the Peripheral */
01398   __HAL_LPTIM_DISABLE(hlptim);
01399 
01400   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01401   {
01402     return HAL_TIMEOUT;
01403   }
01404 
01405   /* Reset ENC bit to disable the encoder interface */
01406   hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
01407 
01408   /* Disable "switch to down direction" interrupt */
01409   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
01410 
01411   /* Disable "switch to up direction" interrupt */
01412   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
01413 
01414   /* Change the TIM state*/
01415   hlptim->State = HAL_LPTIM_STATE_READY;
01416 
01417   /* Return function status */
01418   return HAL_OK;
01419 }
01420 
01421 /**
01422   * @brief  Start the Timeout function.
01423   * @note   The first trigger event will start the timer, any successive
01424   *         trigger event will reset the counter and the timer restarts.
01425   * @param  hlptim LPTIM handle
01426   * @param  Period Specifies the Autoreload value.
01427   *         This parameter must be a value between 0x0000 and 0xFFFF.
01428   * @param  Timeout Specifies the TimeOut value to reset the counter.
01429   *         This parameter must be a value between 0x0000 and 0xFFFF.
01430   * @retval HAL status
01431   */
01432 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
01433 {
01434   /* Check the parameters */
01435   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01436   assert_param(IS_LPTIM_PERIOD(Period));
01437   assert_param(IS_LPTIM_PULSE(Timeout));
01438 
01439   /* Set the LPTIM state */
01440   hlptim->State = HAL_LPTIM_STATE_BUSY;
01441 
01442   /* Set TIMOUT bit to enable the timeout function */
01443   hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
01444 
01445   /* Enable the Peripheral */
01446   __HAL_LPTIM_ENABLE(hlptim);
01447 
01448   /* Clear flag */
01449   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01450 
01451   /* Load the period value in the autoreload register */
01452   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01453 
01454   /* Wait for the completion of the write operation to the LPTIM_ARR register */
01455   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
01456   {
01457     return HAL_TIMEOUT;
01458   }
01459 
01460   /* Clear flag */
01461   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
01462 
01463   /* Load the Timeout value in the compare register */
01464   __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
01465 
01466   /* Wait for the completion of the write operation to the LPTIM_CMP register */
01467   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
01468   {
01469     return HAL_TIMEOUT;
01470   }
01471 
01472   /* Start timer in continuous mode */
01473   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01474 
01475   /* Change the TIM state*/
01476   hlptim->State = HAL_LPTIM_STATE_READY;
01477 
01478   /* Return function status */
01479   return HAL_OK;
01480 }
01481 
01482 /**
01483   * @brief  Stop the Timeout function.
01484   * @param  hlptim LPTIM handle
01485   * @retval HAL status
01486   */
01487 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
01488 {
01489   /* Check the parameters */
01490   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01491 
01492   /* Set the LPTIM state */
01493   hlptim->State = HAL_LPTIM_STATE_BUSY;
01494 
01495   /* Disable the Peripheral */
01496   __HAL_LPTIM_DISABLE(hlptim);
01497 
01498   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01499   {
01500     return HAL_TIMEOUT;
01501   }
01502 
01503   /* Reset TIMOUT bit to enable the timeout function */
01504   hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
01505 
01506   /* Change the TIM state*/
01507   hlptim->State = HAL_LPTIM_STATE_READY;
01508 
01509   /* Return function status */
01510   return HAL_OK;
01511 }
01512 
01513 /**
01514   * @brief  Start the Timeout function in interrupt mode.
01515   * @note   The first trigger event will start the timer, any successive
01516   *         trigger event will reset the counter and the timer restarts.
01517   * @param  hlptim LPTIM handle
01518   * @param  Period Specifies the Autoreload value.
01519   *         This parameter must be a value between 0x0000 and 0xFFFF.
01520   * @param  Timeout Specifies the TimeOut value to reset the counter.
01521   *         This parameter must be a value between 0x0000 and 0xFFFF.
01522   * @retval HAL status
01523   */
01524 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
01525 {
01526   /* Check the parameters */
01527   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01528   assert_param(IS_LPTIM_PERIOD(Period));
01529   assert_param(IS_LPTIM_PULSE(Timeout));
01530 
01531   /* Set the LPTIM state */
01532   hlptim->State = HAL_LPTIM_STATE_BUSY;
01533 
01534   /* Enable EXTI Line interrupt on the LPTIM Wake-up Timer */
01535   __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT(hlptim->Instance);
01536 
01537   /* Set TIMOUT bit to enable the timeout function */
01538   hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
01539 
01540   /* Enable the Peripheral */
01541   __HAL_LPTIM_ENABLE(hlptim);
01542 
01543   /* Clear flag */
01544   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01545 
01546   /* Load the period value in the autoreload register */
01547   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01548 
01549   /* Wait for the completion of the write operation to the LPTIM_ARR register */
01550   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
01551   {
01552     return HAL_TIMEOUT;
01553   }
01554 
01555   /* Clear flag */
01556   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
01557 
01558   /* Load the Timeout value in the compare register */
01559   __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
01560 
01561   /* Wait for the completion of the write operation to the LPTIM_CMP register */
01562   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
01563   {
01564     return HAL_TIMEOUT;
01565   }
01566 
01567   /* Disable the Peripheral */
01568   __HAL_LPTIM_DISABLE(hlptim);
01569 
01570   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01571   {
01572     return HAL_TIMEOUT;
01573   }
01574 
01575   /* Enable Compare match interrupt */
01576   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
01577 
01578   /* Enable the Peripheral */
01579   __HAL_LPTIM_ENABLE(hlptim);
01580 
01581   /* Start timer in continuous mode */
01582   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01583 
01584   /* Change the TIM state*/
01585   hlptim->State = HAL_LPTIM_STATE_READY;
01586 
01587   /* Return function status */
01588   return HAL_OK;
01589 }
01590 
01591 /**
01592   * @brief  Stop the Timeout function in interrupt mode.
01593   * @param  hlptim LPTIM handle
01594   * @retval HAL status
01595   */
01596 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01597 {
01598   /* Check the parameters */
01599   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01600 
01601   /* Set the LPTIM state */
01602   hlptim->State = HAL_LPTIM_STATE_BUSY;
01603 
01604   /* Disable EXTI Line interrupt on the LPTIM Wake-up Timer */
01605   __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT(hlptim->Instance);
01606 
01607   /* Disable the Peripheral */
01608   __HAL_LPTIM_DISABLE(hlptim);
01609 
01610   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01611   {
01612     return HAL_TIMEOUT;
01613   }
01614 
01615   /* Reset TIMOUT bit to enable the timeout function */
01616   hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
01617 
01618   /* Disable Compare match interrupt */
01619   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
01620 
01621   /* Change the TIM state*/
01622   hlptim->State = HAL_LPTIM_STATE_READY;
01623 
01624   /* Return function status */
01625   return HAL_OK;
01626 }
01627 
01628 /**
01629   * @brief  Start the Counter mode.
01630   * @param  hlptim LPTIM handle
01631   * @param  Period Specifies the Autoreload value.
01632   *         This parameter must be a value between 0x0000 and 0xFFFF.
01633   * @retval HAL status
01634   */
01635 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
01636 {
01637   /* Check the parameters */
01638   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01639   assert_param(IS_LPTIM_PERIOD(Period));
01640 
01641   /* Set the LPTIM state */
01642   hlptim->State = HAL_LPTIM_STATE_BUSY;
01643 
01644   /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
01645   if ((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM)
01646       && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
01647   {
01648     /* Check if clock is prescaled */
01649     assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
01650     /* Set clock prescaler to 0 */
01651     hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
01652   }
01653 
01654   /* Enable the Peripheral */
01655   __HAL_LPTIM_ENABLE(hlptim);
01656 
01657   /* Clear flag */
01658   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01659 
01660   /* Load the period value in the autoreload register */
01661   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01662 
01663   /* Wait for the completion of the write operation to the LPTIM_ARR register */
01664   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
01665   {
01666     return HAL_TIMEOUT;
01667   }
01668 
01669   /* Start timer in continuous mode */
01670   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01671 
01672   /* Change the TIM state*/
01673   hlptim->State = HAL_LPTIM_STATE_READY;
01674 
01675   /* Return function status */
01676   return HAL_OK;
01677 }
01678 
01679 /**
01680   * @brief  Stop the Counter mode.
01681   * @param  hlptim LPTIM handle
01682   * @retval HAL status
01683   */
01684 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
01685 {
01686   /* Check the parameters */
01687   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01688 
01689   /* Set the LPTIM state */
01690   hlptim->State = HAL_LPTIM_STATE_BUSY;
01691 
01692   /* Disable the Peripheral */
01693   __HAL_LPTIM_DISABLE(hlptim);
01694 
01695   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01696   {
01697     return HAL_TIMEOUT;
01698   }
01699 
01700   /* Change the TIM state*/
01701   hlptim->State = HAL_LPTIM_STATE_READY;
01702 
01703   /* Return function status */
01704   return HAL_OK;
01705 }
01706 
01707 /**
01708   * @brief  Start the Counter mode in interrupt mode.
01709   * @param  hlptim LPTIM handle
01710   * @param  Period Specifies the Autoreload value.
01711   *         This parameter must be a value between 0x0000 and 0xFFFF.
01712   * @retval HAL status
01713   */
01714 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
01715 {
01716   /* Check the parameters */
01717   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01718   assert_param(IS_LPTIM_PERIOD(Period));
01719 
01720   /* Set the LPTIM state */
01721   hlptim->State = HAL_LPTIM_STATE_BUSY;
01722 
01723   /* Enable EXTI Line interrupt on the LPTIM Wake-up Timer */
01724   __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT(hlptim->Instance);
01725 
01726   /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
01727   if ((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM)
01728       && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
01729   {
01730     /* Check if clock is prescaled */
01731     assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
01732     /* Set clock prescaler to 0 */
01733     hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
01734   }
01735 
01736   /* Enable the Peripheral */
01737   __HAL_LPTIM_ENABLE(hlptim);
01738 
01739   /* Clear flag */
01740   __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01741 
01742   /* Load the period value in the autoreload register */
01743   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01744 
01745   /* Wait for the completion of the write operation to the LPTIM_ARR register */
01746   if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
01747   {
01748     return HAL_TIMEOUT;
01749   }
01750 
01751   /* Disable the Peripheral */
01752   __HAL_LPTIM_DISABLE(hlptim);
01753 
01754   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01755   {
01756     return HAL_TIMEOUT;
01757   }
01758 
01759   /* Enable Autoreload write complete interrupt */
01760   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
01761 
01762   /* Enable Autoreload match interrupt */
01763   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
01764 
01765 #if defined(LPTIM_RCR_REP)
01766   /* Enable Rep Update Ok interrupt */
01767   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_REPOK);
01768 
01769   /* Enable Update Event interrupt */
01770   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UPDATE);
01771 
01772 #endif
01773   /* Enable the Peripheral */
01774   __HAL_LPTIM_ENABLE(hlptim);
01775 
01776   /* Start timer in continuous mode */
01777   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01778 
01779   /* Change the TIM state*/
01780   hlptim->State = HAL_LPTIM_STATE_READY;
01781 
01782   /* Return function status */
01783   return HAL_OK;
01784 }
01785 
01786 /**
01787   * @brief  Stop the Counter mode in interrupt mode.
01788   * @param  hlptim LPTIM handle
01789   * @retval HAL status
01790   */
01791 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01792 {
01793   /* Check the parameters */
01794   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01795 
01796   /* Set the LPTIM state */
01797   hlptim->State = HAL_LPTIM_STATE_BUSY;
01798 
01799   /* Disable EXTI Line interrupt on the LPTIM Wake-up Timer */
01800   __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT(hlptim->Instance);
01801 
01802   /* Disable the Peripheral */
01803   __HAL_LPTIM_DISABLE(hlptim);
01804 
01805   if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
01806   {
01807     return HAL_TIMEOUT;
01808   }
01809 
01810   /* Disable Autoreload write complete interrupt */
01811   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
01812 
01813   /* Disable Autoreload match interrupt */
01814   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
01815 #if defined(LPTIM_RCR_REP)
01816 
01817   /* Disable Rep Update Ok interrupt */
01818   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_REPOK);
01819 
01820   /* Disable Update Event interrupt */
01821   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UPDATE);
01822 #endif
01823   /* Change the TIM state*/
01824   hlptim->State = HAL_LPTIM_STATE_READY;
01825 
01826   /* Return function status */
01827   return HAL_OK;
01828 }
01829 
01830 /**
01831   * @}
01832   */
01833 
01834 /** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions
01835   *  @brief  Read operation functions.
01836   *
01837 @verbatim
01838   ==============================================================================
01839                   ##### LPTIM Read operation functions #####
01840   ==============================================================================
01841 [..]  This section provides LPTIM Reading functions.
01842       (+) Read the counter value.
01843       (+) Read the period (Auto-reload) value.
01844       (+) Read the pulse (Compare)value.
01845 @endverbatim
01846   * @{
01847   */
01848 
01849 /**
01850   * @brief  Return the current counter value.
01851   * @param  hlptim LPTIM handle
01852   * @retval Counter value.
01853   */
01854 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
01855 {
01856   /* Check the parameters */
01857   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01858 
01859   return (hlptim->Instance->CNT);
01860 }
01861 
01862 /**
01863   * @brief  Return the current Autoreload (Period) value.
01864   * @param  hlptim LPTIM handle
01865   * @retval Autoreload value.
01866   */
01867 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
01868 {
01869   /* Check the parameters */
01870   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01871 
01872   return (hlptim->Instance->ARR);
01873 }
01874 
01875 /**
01876   * @brief  Return the current Compare (Pulse) value.
01877   * @param  hlptim LPTIM handle
01878   * @retval Compare value.
01879   */
01880 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
01881 {
01882   /* Check the parameters */
01883   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01884 
01885   return (hlptim->Instance->CMP);
01886 }
01887 
01888 /**
01889   * @}
01890   */
01891 
01892 /** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks
01893   *  @brief  LPTIM  IRQ handler.
01894   *
01895 @verbatim
01896   ==============================================================================
01897                       ##### LPTIM IRQ handler and callbacks  #####
01898   ==============================================================================
01899 [..]  This section provides LPTIM IRQ handler and callback functions called within
01900       the IRQ handler:
01901    (+) LPTIM interrupt request handler
01902    (+) Compare match Callback
01903    (+) Auto-reload match Callback
01904    (+) External trigger event detection Callback
01905    (+) Compare register write complete Callback
01906    (+) Auto-reload register write complete Callback
01907    (+) Up-counting direction change Callback
01908    (+) Down-counting direction change Callback
01909 
01910 @endverbatim
01911   * @{
01912   */
01913 
01914 /**
01915   * @brief  Handle LPTIM interrupt request.
01916   * @param  hlptim LPTIM handle
01917   * @retval None
01918   */
01919 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
01920 {
01921   /* Compare match interrupt */
01922   if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
01923   {
01924     if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) != RESET)
01925     {
01926       /* Clear Compare match flag */
01927       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
01928 
01929       /* Compare match Callback */
01930 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
01931       hlptim->CompareMatchCallback(hlptim);
01932 #else
01933       HAL_LPTIM_CompareMatchCallback(hlptim);
01934 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
01935     }
01936   }
01937 
01938   /* Autoreload match interrupt */
01939   if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
01940   {
01941     if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET)
01942     {
01943       /* Clear Autoreload match flag */
01944       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
01945 
01946       /* Autoreload match Callback */
01947 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
01948       hlptim->AutoReloadMatchCallback(hlptim);
01949 #else
01950       HAL_LPTIM_AutoReloadMatchCallback(hlptim);
01951 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
01952     }
01953   }
01954 
01955   /* Trigger detected interrupt */
01956   if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
01957   {
01958     if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) != RESET)
01959     {
01960       /* Clear Trigger detected flag */
01961       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
01962 
01963       /* Trigger detected callback */
01964 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
01965       hlptim->TriggerCallback(hlptim);
01966 #else
01967       HAL_LPTIM_TriggerCallback(hlptim);
01968 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
01969     }
01970   }
01971 
01972   /* Compare write interrupt */
01973   if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
01974   {
01975     if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) != RESET)
01976     {
01977       /* Clear Compare write flag */
01978       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
01979 
01980       /* Compare write Callback */
01981 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
01982       hlptim->CompareWriteCallback(hlptim);
01983 #else
01984       HAL_LPTIM_CompareWriteCallback(hlptim);
01985 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
01986     }
01987   }
01988 
01989   /* Autoreload write interrupt */
01990   if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
01991   {
01992     if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET)
01993     {
01994       /* Clear Autoreload write flag */
01995       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01996 
01997       /* Autoreload write Callback */
01998 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
01999       hlptim->AutoReloadWriteCallback(hlptim);
02000 #else
02001       HAL_LPTIM_AutoReloadWriteCallback(hlptim);
02002 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
02003     }
02004   }
02005 
02006   /* Direction counter changed from Down to Up interrupt */
02007   if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
02008   {
02009     if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) != RESET)
02010     {
02011       /* Clear Direction counter changed from Down to Up flag */
02012       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
02013 
02014       /* Direction counter changed from Down to Up Callback */
02015 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
02016       hlptim->DirectionUpCallback(hlptim);
02017 #else
02018       HAL_LPTIM_DirectionUpCallback(hlptim);
02019 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
02020     }
02021   }
02022 
02023   /* Direction counter changed from Up to Down interrupt */
02024   if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
02025   {
02026     if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) != RESET)
02027     {
02028       /* Clear Direction counter changed from Up to Down flag */
02029       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
02030 
02031       /* Direction counter changed from Up to Down Callback */
02032 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
02033       hlptim->DirectionDownCallback(hlptim);
02034 #else
02035       HAL_LPTIM_DirectionDownCallback(hlptim);
02036 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
02037     }
02038   }
02039 #if defined(LPTIM_RCR_REP)
02040 
02041   /* Repetition counter underflowed (or contains zero) and the LPTIM counter
02042      overflowed */
02043   if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UPDATE) != RESET)
02044   {
02045     if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UPDATE) != RESET)
02046     {
02047       /* Clear update event flag */
02048       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UPDATE);
02049 
02050       /* Update event Callback */
02051 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
02052       hlptim->UpdateEventCallback(hlptim);
02053 #else
02054       HAL_LPTIM_UpdateEventCallback(hlptim);
02055 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
02056     }
02057   }
02058 
02059   /* Successful APB bus write to repetition counter register */
02060   if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_REPOK) != RESET)
02061   {
02062     if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_REPOK) != RESET)
02063     {
02064       /* Clear successful APB bus write to repetition counter flag */
02065       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_REPOK);
02066 
02067       /* Successful APB bus write to repetition counter Callback */
02068 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
02069       hlptim->RepCounterWriteCallback(hlptim);
02070 #else
02071       HAL_LPTIM_RepCounterWriteCallback(hlptim);
02072 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
02073     }
02074   }
02075 #endif
02076 }
02077 
02078 /**
02079   * @brief  Compare match callback in non-blocking mode.
02080   * @param  hlptim LPTIM handle
02081   * @retval None
02082   */
02083 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
02084 {
02085   /* Prevent unused argument(s) compilation warning */
02086   UNUSED(hlptim);
02087 
02088   /* NOTE : This function should not be modified, when the callback is needed,
02089             the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
02090    */
02091 }
02092 
02093 /**
02094   * @brief  Autoreload match callback in non-blocking mode.
02095   * @param  hlptim LPTIM handle
02096   * @retval None
02097   */
02098 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
02099 {
02100   /* Prevent unused argument(s) compilation warning */
02101   UNUSED(hlptim);
02102 
02103   /* NOTE : This function should not be modified, when the callback is needed,
02104             the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
02105    */
02106 }
02107 
02108 /**
02109   * @brief  Trigger detected callback in non-blocking mode.
02110   * @param  hlptim LPTIM handle
02111   * @retval None
02112   */
02113 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
02114 {
02115   /* Prevent unused argument(s) compilation warning */
02116   UNUSED(hlptim);
02117 
02118   /* NOTE : This function should not be modified, when the callback is needed,
02119             the HAL_LPTIM_TriggerCallback could be implemented in the user file
02120    */
02121 }
02122 
02123 /**
02124   * @brief  Compare write callback in non-blocking mode.
02125   * @param  hlptim LPTIM handle
02126   * @retval None
02127   */
02128 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
02129 {
02130   /* Prevent unused argument(s) compilation warning */
02131   UNUSED(hlptim);
02132 
02133   /* NOTE : This function should not be modified, when the callback is needed,
02134             the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
02135    */
02136 }
02137 
02138 /**
02139   * @brief  Autoreload write callback in non-blocking mode.
02140   * @param  hlptim LPTIM handle
02141   * @retval None
02142   */
02143 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
02144 {
02145   /* Prevent unused argument(s) compilation warning */
02146   UNUSED(hlptim);
02147 
02148   /* NOTE : This function should not be modified, when the callback is needed,
02149             the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
02150    */
02151 }
02152 
02153 /**
02154   * @brief  Direction counter changed from Down to Up callback in non-blocking mode.
02155   * @param  hlptim LPTIM handle
02156   * @retval None
02157   */
02158 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
02159 {
02160   /* Prevent unused argument(s) compilation warning */
02161   UNUSED(hlptim);
02162 
02163   /* NOTE : This function should not be modified, when the callback is needed,
02164             the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
02165    */
02166 }
02167 
02168 /**
02169   * @brief  Direction counter changed from Up to Down callback in non-blocking mode.
02170   * @param  hlptim LPTIM handle
02171   * @retval None
02172   */
02173 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
02174 {
02175   /* Prevent unused argument(s) compilation warning */
02176   UNUSED(hlptim);
02177 
02178   /* NOTE : This function should not be modified, when the callback is needed,
02179             the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
02180    */
02181 }
02182 #if defined(LPTIM_RCR_REP)
02183 
02184 /**
02185   * @brief Repetition counter underflowed (or contains zero) and LPTIM counter overflowed callback in non-blocking mode.
02186   * @param  hlptim LPTIM handle
02187   * @retval None
02188   */
02189 __weak void HAL_LPTIM_UpdateEventCallback(LPTIM_HandleTypeDef *hlptim)
02190 {
02191   /* Prevent unused argument(s) compilation warning */
02192   UNUSED(hlptim);
02193 
02194   /* NOTE : This function should not be modified, when the callback is needed,
02195             the HAL_LPTIM_UpdateEventCallback could be implemented in the user file
02196    */
02197 }
02198 
02199 /**
02200   * @brief  Successful APB bus write to repetition counter register callback in non-blocking mode.
02201   * @param  hlptim LPTIM handle
02202   * @retval None
02203   */
02204 __weak void HAL_LPTIM_RepCounterWriteCallback(LPTIM_HandleTypeDef *hlptim)
02205 {
02206   /* Prevent unused argument(s) compilation warning */
02207   UNUSED(hlptim);
02208 
02209   /* NOTE : This function should not be modified, when the callback is needed,
02210             the HAL_LPTIM_RepCounterWriteCallback could be implemented in the user file
02211    */
02212 }
02213 #endif
02214 
02215 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
02216 /**
02217   * @brief  Register a User LPTIM callback to be used instead of the weak predefined callback
02218   * @param hlptim LPTIM handle
02219   * @param CallbackID ID of the callback to be registered
02220   *        This parameter can be one of the following values:
02221   *          @arg @ref HAL_LPTIM_MSPINIT_CB_ID          LPTIM Base Msp Init Callback ID
02222   *          @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID        LPTIM Base Msp DeInit Callback ID
02223   *          @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID    Compare match Callback ID
02224   *          @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
02225   *          @arg @ref HAL_LPTIM_TRIGGER_CB_ID          External trigger event detection Callback ID
02226   *          @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID    Compare register write complete Callback ID
02227   *          @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
02228   *          @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID     Up-counting direction change Callback ID
02229   *          @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID   Down-counting direction change Callback ID
02230   *          @arg @ref HAL_LPTIM_UPDATE_EVENT_CB_ID      Update event detection Callback ID (when available)
02231   *          @arg @ref HAL_LPTIM_REP_COUNTER_WRITE_CB_ID Repetition counter register write complete Callback ID (when available)
02232   * @param pCallback pointer to the callback function
02233   * @retval status
02234   */
02235 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef        *hlptim,
02236                                              HAL_LPTIM_CallbackIDTypeDef CallbackID,
02237                                              pLPTIM_CallbackTypeDef      pCallback)
02238 {
02239   HAL_StatusTypeDef status = HAL_OK;
02240 
02241   if (pCallback == NULL)
02242   {
02243     return HAL_ERROR;
02244   }
02245 
02246   /* Process locked */
02247   __HAL_LOCK(hlptim);
02248 
02249   if (hlptim->State == HAL_LPTIM_STATE_READY)
02250   {
02251     switch (CallbackID)
02252     {
02253       case HAL_LPTIM_MSPINIT_CB_ID :
02254         hlptim->MspInitCallback = pCallback;
02255         break;
02256 
02257       case HAL_LPTIM_MSPDEINIT_CB_ID :
02258         hlptim->MspDeInitCallback = pCallback;
02259         break;
02260 
02261       case HAL_LPTIM_COMPARE_MATCH_CB_ID :
02262         hlptim->CompareMatchCallback = pCallback;
02263         break;
02264 
02265       case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
02266         hlptim->AutoReloadMatchCallback = pCallback;
02267         break;
02268 
02269       case HAL_LPTIM_TRIGGER_CB_ID :
02270         hlptim->TriggerCallback = pCallback;
02271         break;
02272 
02273       case HAL_LPTIM_COMPARE_WRITE_CB_ID :
02274         hlptim->CompareWriteCallback = pCallback;
02275         break;
02276 
02277       case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID :
02278         hlptim->AutoReloadWriteCallback = pCallback;
02279         break;
02280 
02281       case HAL_LPTIM_DIRECTION_UP_CB_ID :
02282         hlptim->DirectionUpCallback = pCallback;
02283         break;
02284 
02285       case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
02286         hlptim->DirectionDownCallback = pCallback;
02287         break;
02288 #if defined(LPTIM_RCR_REP)
02289 
02290       case HAL_LPTIM_UPDATE_EVENT_CB_ID :
02291         hlptim->UpdateEventCallback = pCallback;
02292         break;
02293 
02294       case HAL_LPTIM_REP_COUNTER_WRITE_CB_ID :
02295         hlptim->RepCounterWriteCallback = pCallback;
02296         break;
02297 #endif
02298 
02299       default :
02300         /* Return error status */
02301         status =  HAL_ERROR;
02302         break;
02303     }
02304   }
02305   else if (hlptim->State == HAL_LPTIM_STATE_RESET)
02306   {
02307     switch (CallbackID)
02308     {
02309       case HAL_LPTIM_MSPINIT_CB_ID :
02310         hlptim->MspInitCallback = pCallback;
02311         break;
02312 
02313       case HAL_LPTIM_MSPDEINIT_CB_ID :
02314         hlptim->MspDeInitCallback = pCallback;
02315         break;
02316 
02317       default :
02318         /* Return error status */
02319         status =  HAL_ERROR;
02320         break;
02321     }
02322   }
02323   else
02324   {
02325     /* Return error status */
02326     status =  HAL_ERROR;
02327   }
02328 
02329   /* Release Lock */
02330   __HAL_UNLOCK(hlptim);
02331 
02332   return status;
02333 }
02334 
02335 /**
02336   * @brief  Unregister a LPTIM callback
02337   *         LLPTIM callback is redirected to the weak predefined callback
02338   * @param hlptim LPTIM handle
02339   * @param CallbackID ID of the callback to be unregistered
02340   *        This parameter can be one of the following values:
02341   *          @arg @ref HAL_LPTIM_MSPINIT_CB_ID          LPTIM Base Msp Init Callback ID
02342   *          @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID        LPTIM Base Msp DeInit Callback ID
02343   *          @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID    Compare match Callback ID
02344   *          @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
02345   *          @arg @ref HAL_LPTIM_TRIGGER_CB_ID          External trigger event detection Callback ID
02346   *          @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID    Compare register write complete Callback ID
02347   *          @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
02348   *          @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID     Up-counting direction change Callback ID
02349   *          @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID   Down-counting direction change Callback ID
02350   *          @arg @ref HAL_LPTIM_UPDATE_EVENT_CB_ID      Update event detection Callback ID (when available)
02351   *          @arg @ref HAL_LPTIM_REP_COUNTER_WRITE_CB_ID Repetition counter register write complete Callback ID (when available)
02352   * @retval status
02353   */
02354 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef        *hlptim,
02355                                                HAL_LPTIM_CallbackIDTypeDef CallbackID)
02356 {
02357   HAL_StatusTypeDef status = HAL_OK;
02358 
02359   /* Process locked */
02360   __HAL_LOCK(hlptim);
02361 
02362   if (hlptim->State == HAL_LPTIM_STATE_READY)
02363   {
02364     switch (CallbackID)
02365     {
02366       case HAL_LPTIM_MSPINIT_CB_ID :
02367         /* Legacy weak MspInit Callback */
02368         hlptim->MspInitCallback = HAL_LPTIM_MspInit;
02369         break;
02370 
02371       case HAL_LPTIM_MSPDEINIT_CB_ID :
02372         /* Legacy weak Msp DeInit Callback */
02373         hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
02374         break;
02375 
02376       case HAL_LPTIM_COMPARE_MATCH_CB_ID :
02377         /* Legacy weak Compare match Callback */
02378         hlptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback;
02379         break;
02380 
02381       case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
02382         /* Legacy weak Auto-reload match Callback */
02383         hlptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback;
02384         break;
02385 
02386       case HAL_LPTIM_TRIGGER_CB_ID :
02387         /* Legacy weak External trigger event detection Callback */
02388         hlptim->TriggerCallback = HAL_LPTIM_TriggerCallback;
02389         break;
02390 
02391       case HAL_LPTIM_COMPARE_WRITE_CB_ID :
02392         /* Legacy weak Compare register write complete Callback */
02393         hlptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback;
02394         break;
02395 
02396       case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID :
02397         /* Legacy weak Auto-reload register write complete Callback */
02398         hlptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback;
02399         break;
02400 
02401       case HAL_LPTIM_DIRECTION_UP_CB_ID :
02402         /* Legacy weak Up-counting direction change Callback */
02403         hlptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback;
02404         break;
02405 
02406       case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
02407         /* Legacy weak Down-counting direction change Callback */
02408         hlptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback;
02409         break;
02410 #if defined(LPTIM_RCR_REP)
02411 
02412       case HAL_LPTIM_UPDATE_EVENT_CB_ID :
02413         /* Legacy weak Update event detection Callback */
02414         hlptim->UpdateEventCallback = HAL_LPTIM_UpdateEventCallback;
02415         break;
02416 
02417       case HAL_LPTIM_REP_COUNTER_WRITE_CB_ID :
02418         /* Legacy weak Repetition counter register write complete Callback */
02419         hlptim->RepCounterWriteCallback = HAL_LPTIM_RepCounterWriteCallback;
02420         break;
02421 #endif
02422 
02423       default :
02424         /* Return error status */
02425         status =  HAL_ERROR;
02426         break;
02427     }
02428   }
02429   else if (hlptim->State == HAL_LPTIM_STATE_RESET)
02430   {
02431     switch (CallbackID)
02432     {
02433       case HAL_LPTIM_MSPINIT_CB_ID :
02434         /* Legacy weak MspInit Callback */
02435         hlptim->MspInitCallback = HAL_LPTIM_MspInit;
02436         break;
02437 
02438       case HAL_LPTIM_MSPDEINIT_CB_ID :
02439         /* Legacy weak Msp DeInit Callback */
02440         hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
02441         break;
02442 
02443       default :
02444         /* Return error status */
02445         status =  HAL_ERROR;
02446         break;
02447     }
02448   }
02449   else
02450   {
02451     /* Return error status */
02452     status =  HAL_ERROR;
02453   }
02454 
02455   /* Release Lock */
02456   __HAL_UNLOCK(hlptim);
02457 
02458   return status;
02459 }
02460 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
02461 
02462 /**
02463   * @}
02464   */
02465 
02466 /** @defgroup LPTIM_Group5 Peripheral State functions
02467   *  @brief   Peripheral State functions.
02468   *
02469 @verbatim
02470   ==============================================================================
02471                       ##### Peripheral State functions #####
02472   ==============================================================================
02473     [..]
02474     This subsection permits to get in run-time the status of the peripheral.
02475 
02476 @endverbatim
02477   * @{
02478   */
02479 
02480 /**
02481   * @brief  Return the LPTIM handle state.
02482   * @param  hlptim LPTIM handle
02483   * @retval HAL state
02484   */
02485 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
02486 {
02487   /* Return LPTIM handle state */
02488   return hlptim->State;
02489 }
02490 
02491 /**
02492   * @}
02493   */
02494 
02495 
02496 /**
02497   * @}
02498   */
02499 
02500 /* Private functions ---------------------------------------------------------*/
02501 
02502 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
02503   * @{
02504   */
02505 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
02506 /**
02507   * @brief  Reset interrupt callbacks to the legacy weak callbacks.
02508   * @param  lptim pointer to a LPTIM_HandleTypeDef structure that contains
02509   *                the configuration information for LPTIM module.
02510   * @retval None
02511   */
02512 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim)
02513 {
02514   /* Reset the LPTIM callback to the legacy weak callbacks */
02515   lptim->CompareMatchCallback    = HAL_LPTIM_CompareMatchCallback;
02516   lptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback;
02517   lptim->TriggerCallback         = HAL_LPTIM_TriggerCallback;
02518   lptim->CompareWriteCallback    = HAL_LPTIM_CompareWriteCallback;
02519   lptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback;
02520   lptim->DirectionUpCallback     = HAL_LPTIM_DirectionUpCallback;
02521   lptim->DirectionDownCallback   = HAL_LPTIM_DirectionDownCallback;
02522 #if defined(LPTIM_RCR_REP)
02523   lptim->UpdateEventCallback = HAL_LPTIM_UpdateEventCallback;
02524   lptim->RepCounterWriteCallback = HAL_LPTIM_RepCounterWriteCallback;
02525 #endif
02526 }
02527 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
02528 
02529 /**
02530   * @brief  LPTimer Wait for flag set
02531   * @param  hlptim pointer to a LPTIM_HandleTypeDef structure that contains
02532   *                the configuration information for LPTIM module.
02533   * @param  flag   The lptim flag
02534   * @retval HAL status
02535   */
02536 static HAL_StatusTypeDef LPTIM_WaitForFlag(LPTIM_HandleTypeDef *hlptim, uint32_t flag)
02537 {
02538   HAL_StatusTypeDef result = HAL_OK;
02539   uint32_t count = TIMEOUT * (SystemCoreClock / 20UL / 1000UL);
02540   do
02541   {
02542     count--;
02543     if (count == 0UL)
02544     {
02545       result = HAL_TIMEOUT;
02546     }
02547   } while ((!(__HAL_LPTIM_GET_FLAG((hlptim), (flag)))) && (count != 0UL));
02548 
02549   return result;
02550 }
02551 
02552 /**
02553   * @brief  Disable LPTIM HW instance.
02554   * @param  hlptim pointer to a LPTIM_HandleTypeDef structure that contains
02555   *                the configuration information for LPTIM module.
02556   * @note   The following sequence is required to solve LPTIM disable HW limitation.
02557   *         Please check Errata Sheet ES0335 for more details under "MCU may remain
02558   *         stuck in LPTIM interrupt when entering Stop mode" section.
02559   * @retval None
02560   */
02561 void LPTIM_Disable(LPTIM_HandleTypeDef *hlptim)
02562 {
02563   uint32_t tmpclksource = 0;
02564   uint32_t tmpIER;
02565   uint32_t tmpCFGR;
02566   uint32_t tmpCMP;
02567   uint32_t tmpARR;
02568   uint32_t primask_bit;
02569   uint32_t tmpOR;
02570 #if defined(LPTIM_RCR_REP)
02571   uint32_t tmpRCR;
02572 #endif
02573 
02574   /* Enter critical section */
02575   primask_bit = __get_PRIMASK();
02576   __set_PRIMASK(1) ;
02577 
02578   /*********** Save LPTIM Config ***********/
02579   /* Save LPTIM source clock */
02580   switch ((uint32_t)hlptim->Instance)
02581   {
02582     case LPTIM1_BASE:
02583       tmpclksource = __HAL_RCC_GET_LPTIM1_SOURCE();
02584       break;
02585 #if defined(LPTIM2)
02586     case LPTIM2_BASE:
02587       tmpclksource = __HAL_RCC_GET_LPTIM2_SOURCE();
02588       break;
02589 #endif /* LPTIM2 */
02590     default:
02591       break;
02592   }
02593 
02594   /* Save LPTIM configuration registers */
02595   tmpIER = hlptim->Instance->IER;
02596   tmpCFGR = hlptim->Instance->CFGR;
02597   tmpCMP = hlptim->Instance->CMP;
02598   tmpARR = hlptim->Instance->ARR;
02599   tmpOR = hlptim->Instance->OR;
02600 #if defined(LPTIM_RCR_REP)
02601   tmpRCR = hlptim->Instance->RCR;
02602 #endif
02603 
02604   /*********** Reset LPTIM ***********/
02605   switch ((uint32_t)hlptim->Instance)
02606   {
02607     case LPTIM1_BASE:
02608       __HAL_RCC_LPTIM1_FORCE_RESET();
02609       __HAL_RCC_LPTIM1_RELEASE_RESET();
02610       break;
02611 #if defined(LPTIM2)
02612     case LPTIM2_BASE:
02613       __HAL_RCC_LPTIM2_FORCE_RESET();
02614       __HAL_RCC_LPTIM2_RELEASE_RESET();
02615       break;
02616 #endif /* LPTIM2 */
02617     default:
02618       break;
02619   }
02620 
02621   /*********** Restore LPTIM Config ***********/
02622 #if defined(LPTIM_RCR_REP)
02623   if ((tmpCMP != 0UL) || (tmpARR != 0UL) || (tmpRCR != 0UL))
02624 #else
02625   if ((tmpCMP != 0UL) || (tmpARR != 0UL))
02626 #endif
02627   {
02628     /* Force LPTIM source kernel clock from APB */
02629     switch ((uint32_t)hlptim->Instance)
02630     {
02631       case LPTIM1_BASE:
02632         __HAL_RCC_LPTIM1_CONFIG(RCC_LPTIM1CLKSOURCE_PCLK1);
02633         break;
02634 #if defined(LPTIM2)
02635       case LPTIM2_BASE:
02636         __HAL_RCC_LPTIM2_CONFIG(RCC_LPTIM2CLKSOURCE_PCLK1);
02637         break;
02638 #endif /* LPTIM2 */
02639       default:
02640         break;
02641     }
02642 
02643     if (tmpCMP != 0UL)
02644     {
02645       /* Restore CMP register (LPTIM should be enabled first) */
02646       hlptim->Instance->CR |= LPTIM_CR_ENABLE;
02647       hlptim->Instance->CMP = tmpCMP;
02648 
02649       /* Wait for the completion of the write operation to the LPTIM_CMP register */
02650       if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
02651       {
02652         hlptim->State = HAL_LPTIM_STATE_TIMEOUT;
02653       }
02654       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
02655     }
02656 
02657     if (tmpARR != 0UL)
02658     {
02659       /* Restore ARR register (LPTIM should be enabled first) */
02660       hlptim->Instance->CR |= LPTIM_CR_ENABLE;
02661       hlptim->Instance->ARR = tmpARR;
02662 
02663       /* Wait for the completion of the write operation to the LPTIM_ARR register */
02664       if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
02665       {
02666         hlptim->State = HAL_LPTIM_STATE_TIMEOUT;
02667       }
02668 
02669       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
02670     }
02671 #if defined(LPTIM_RCR_REP)
02672 
02673     if (tmpRCR != 0UL)
02674     {
02675       /* Restore RCR register (LPTIM should be enabled first) */
02676       hlptim->Instance->CR |= LPTIM_CR_ENABLE;
02677       hlptim->Instance->RCR = tmpRCR;
02678 
02679       /* Wait for the completion of the write operation to the LPTIM_RCR register */
02680       if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_REPOK) == HAL_TIMEOUT)
02681       {
02682         hlptim->State = HAL_LPTIM_STATE_TIMEOUT;
02683       }
02684       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_REPOK);
02685     }
02686 #endif
02687 
02688     /* Restore LPTIM source kernel clock */
02689     switch ((uint32_t)hlptim->Instance)
02690     {
02691       case LPTIM1_BASE:
02692         __HAL_RCC_LPTIM1_CONFIG(tmpclksource);
02693         break;
02694 #if defined(LPTIM2)
02695       case LPTIM2_BASE:
02696         __HAL_RCC_LPTIM2_CONFIG(tmpclksource);
02697         break;
02698 #endif /* LPTIM2 */
02699       default:
02700         break;
02701     }
02702   }
02703 
02704   /* Restore configuration registers (LPTIM should be disabled first) */
02705   hlptim->Instance->CR &= ~(LPTIM_CR_ENABLE);
02706   hlptim->Instance->IER = tmpIER;
02707   hlptim->Instance->CFGR = tmpCFGR;
02708   hlptim->Instance->OR = tmpOR;
02709 
02710   /* Exit critical section: restore previous priority mask */
02711   __set_PRIMASK(primask_bit);
02712 }
02713 /**
02714   * @}
02715   */
02716 #endif /* LPTIM1 || LPTIM2 */
02717 
02718 #endif /* HAL_LPTIM_MODULE_ENABLED */
02719 /**
02720   * @}
02721   */
02722 
02723 /**
02724   * @}
02725   */