Hal Drivers for L4

Dependents:   BSP OneHopeOnePrayer FINAL_AUDIO_RECORD AudioDemo

Fork of STM32L4xx_HAL_Driver by Senior Design: Sound Monitor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_lptim.c Source File

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   * @version V1.1.0
00006   * @date    16-September-2015
00007   * @brief   LPTIM HAL module driver. 
00008   *          This file provides firmware functions to manage the following 
00009   *          functionalities of the Low Power Timer (LPTIM) peripheral:
00010   *           + Initialization and de-initialization functions.
00011   *           + Start/Stop operation functions in polling mode.
00012   *           + Start/Stop operation functions in interrupt mode.
00013   *           + Reading operation functions.
00014   *           + Peripheral State functions.
00015   *         
00016   @verbatim
00017   ==============================================================================
00018                      ##### How to use this driver #####
00019   ==============================================================================
00020     [..]
00021       The LPTIM HAL driver can be used as follows:
00022 
00023       (#)Initialize the LPTIM low level resources by implementing the
00024         HAL_LPTIM_MspInit():
00025          (++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE().
00026          (++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
00027              (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
00028              (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
00029              (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
00030     
00031       (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
00032          configures mainly:
00033          (++) The instance: LPTIM1 or LPTIM2.
00034          (++) Clock: the counter clock.
00035              (+++) Source   : it can be either the ULPTIM input (IN1) or one of
00036                               the internal clock; (APB, LSE, LSI or MSI).
00037              (+++) Prescaler: select the clock divider.
00038          (++)  UltraLowPowerClock : To be used only if the ULPTIM is selected
00039                as counter clock source.
00040              (+++) Polarity:   polarity of the active edge for the counter unit
00041                                if the ULPTIM input is selected.
00042              (+++) SampleTime: clock sampling time to configure the clock glitch
00043                                filter.              
00044          (++) Trigger: How the counter start.
00045              (+++) Source: trigger can be software or one of the hardware triggers.
00046              (+++) ActiveEdge : only for hardware trigger.
00047              (+++) SampleTime : trigger sampling time to configure the trigger
00048                                 glitch filter.
00049          (++) OutputPolarity : 2 opposite polarities are possible.
00050          (++) UpdateMode: specifies whether the update of the autoreload and
00051               the compare values is done immediately or after the end of current
00052               period.   
00053          (++) Input1Source: Source selected for input1 (GPIO or comparator output).
00054          (++) Input2Source: Source selected for input2 (GPIO or comparator output). 
00055               Input2 is used only for encoder feature so is used only for LPTIM1 instance.
00056     
00057       (#)Six modes are available:
00058       
00059          (++) PWM Mode: To generate a PWM signal with specified period and pulse,
00060          call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
00061          mode.
00062          
00063          (++) One Pulse Mode: To generate pulse with specified width in response
00064          to a stimulus, call HAL_LPTIM_OnePulse_Start() or
00065          HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
00066          
00067          (++) Set once Mode: In this mode, the output changes the level (from
00068          low level to high level if the output polarity is configured high, else
00069          the opposite) when a compare match occurs. To start this mode, call 
00070          HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
00071          interruption mode.
00072          
00073          (++) Encoder Mode: To use the encoder interface call
00074          HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for 
00075          interruption mode. Only available for LPTIM1 instance.
00076          
00077          (++) Time out Mode: an active edge on one selected trigger input rests
00078          the counter. The first trigger event will start the timer, any
00079          successive trigger event will reset the counter and the timer will
00080          restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or 
00081          HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
00082          
00083          (++) Counter Mode: counter can be used to count external events on
00084          the LPTIM Input1 or it can be used to count internal clock cycles.
00085          To start this mode, call HAL_LPTIM_Counter_Start() or 
00086          HAL_LPTIM_Counter_Start_IT() for interruption mode.             
00087 
00088     
00089       (#) User can stop any process by calling the corresponding API:
00090           HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
00091           already started in interruption mode.
00092          
00093       (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit().
00094 
00095   @endverbatim
00096   ******************************************************************************
00097   * @attention
00098   *
00099   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00100   *
00101   * Redistribution and use in source and binary forms, with or without modification,
00102   * are permitted provided that the following conditions are met:
00103   *   1. Redistributions of source code must retain the above copyright notice,
00104   *      this list of conditions and the following disclaimer.
00105   *   2. Redistributions in binary form must reproduce the above copyright notice,
00106   *      this list of conditions and the following disclaimer in the documentation
00107   *      and/or other materials provided with the distribution.
00108   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00109   *      may be used to endorse or promote products derived from this software
00110   *      without specific prior written permission.
00111   *
00112   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00113   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00114   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00115   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00116   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00117   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00118   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00119   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00120   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00121   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00122   *
00123   ******************************************************************************  
00124   */ 
00125 
00126 /* Includes ------------------------------------------------------------------*/
00127 #include "stm32l4xx_hal.h"
00128 
00129 /** @addtogroup STM32L4xx_HAL_Driver
00130   * @{
00131   */
00132 
00133 /** @defgroup LPTIM LPTIM
00134   * @brief LPTIM HAL module driver.
00135   * @{
00136   */
00137 
00138 #ifdef HAL_LPTIM_MODULE_ENABLED
00139 /* Private typedef -----------------------------------------------------------*/
00140 /* Private define ------------------------------------------------------------*/
00141 /* Private macro -------------------------------------------------------------*/
00142 /* Private variables ---------------------------------------------------------*/
00143 /* Private function prototypes -----------------------------------------------*/
00144 /* Exported functions --------------------------------------------------------*/
00145 
00146 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
00147   * @{
00148   */
00149 
00150 /** @defgroup LPTIM_Group1 Initialization/de-initialization functions 
00151  *  @brief    Initialization and Configuration functions. 
00152  *
00153 @verbatim    
00154   ==============================================================================
00155               ##### Initialization and de-initialization functions #####
00156   ==============================================================================
00157     [..]  This section provides functions allowing to:
00158       (+) Initialize the LPTIM according to the specified parameters in the
00159           LPTIM_InitTypeDef and initialize the associated handle.
00160       (+) DeInitialize the LPTIM peripheral.
00161       (+) Initialize the LPTIM MSP.
00162       (+) DeInitialize the LPTIM MSP. 
00163  
00164 @endverbatim
00165   * @{
00166   */
00167 
00168 /**
00169   * @brief  Initialize the LPTIM according to the specified parameters in the
00170   *         LPTIM_InitTypeDef and initialize the associated handle.
00171   * @param  hlptim: LPTIM handle
00172   * @retval HAL status
00173   */
00174 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
00175 {
00176   uint32_t tmpcfgr = 0;
00177 
00178   /* Check the LPTIM handle allocation */
00179   if(hlptim == NULL)
00180   {
00181     return HAL_ERROR;
00182   }
00183 
00184   /* Check the parameters */
00185   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00186   
00187   assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
00188   assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));  
00189   if ((hlptim->Init.Clock.Source) ==  LPTIM_CLOCKSOURCE_ULPTIM)
00190   {
00191     assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
00192     assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
00193   }  
00194   assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
00195   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00196   {
00197     assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
00198     assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
00199   }  
00200   assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));  
00201   assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
00202   assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
00203   
00204   if(hlptim->State == HAL_LPTIM_STATE_RESET)
00205   {
00206     /* Allocate lock resource and initialize it */
00207     hlptim->Lock = HAL_UNLOCKED;
00208 
00209     /* Init the low level hardware */
00210     HAL_LPTIM_MspInit(hlptim);
00211   }
00212   
00213   /* Change the LPTIM state */
00214   hlptim->State = HAL_LPTIM_STATE_BUSY;
00215   
00216   /* Get the LPTIMx CFGR value */
00217   tmpcfgr = hlptim->Instance->CFGR;
00218   
00219   if ((hlptim->Init.Clock.Source) ==  LPTIM_CLOCKSOURCE_ULPTIM)
00220   {
00221     tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
00222   }
00223   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00224   {
00225     tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
00226   }
00227     
00228   /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
00229   tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
00230                           LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE ));
00231   
00232   /* Set initialization parameters */
00233   tmpcfgr |= (hlptim->Init.Clock.Source    |
00234               hlptim->Init.Clock.Prescaler |
00235               hlptim->Init.OutputPolarity  |
00236               hlptim->Init.UpdateMode      |
00237               hlptim->Init.CounterSource);
00238   
00239   if ((hlptim->Init.Clock.Source) ==  LPTIM_CLOCKSOURCE_ULPTIM)
00240   {
00241     tmpcfgr |=  (hlptim->Init.UltraLowPowerClock.Polarity |
00242                 hlptim->Init.UltraLowPowerClock.SampleTime);
00243   } 
00244   
00245   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00246   {
00247     /* Enable External trigger and set the trigger source */
00248     tmpcfgr |= (hlptim->Init.Trigger.Source     |
00249                 hlptim->Init.Trigger.ActiveEdge |
00250                 hlptim->Init.Trigger.SampleTime);
00251   }
00252   
00253   /* Write to LPTIMx CFGR */
00254   hlptim->Instance->CFGR = tmpcfgr;
00255 
00256   /* Configure LPTIM input sources */
00257   if(hlptim->Instance == LPTIM1)
00258   {
00259     /* Check LPTIM1 Input1 and Input2 sources */
00260     assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source));
00261     assert_param(IS_LPTIM_INPUT2_SOURCE(hlptim->Instance,hlptim->Init.Input2Source));
00262     
00263     /* Configure LPTIM1 Input1 and Input2 sources */
00264     hlptim->Instance->OR = (hlptim->Init.Input1Source | hlptim->Init.Input2Source);
00265   }
00266   else
00267   {
00268     /* Check LPTIM2 Input1 source */
00269     assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source));
00270     
00271     /* Configure LPTIM2 Input1 source */
00272     hlptim->Instance->OR = hlptim->Init.Input1Source;
00273   }
00274   
00275   /* Change the LPTIM state */
00276   hlptim->State = HAL_LPTIM_STATE_READY;
00277   
00278   /* Return function status */
00279   return HAL_OK;
00280 }
00281 
00282 /**
00283   * @brief  DeInitialize the LPTIM peripheral. 
00284   * @param  hlptim: LPTIM handle
00285   * @retval HAL status
00286   */
00287 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
00288 {
00289   /* Check the LPTIM handle allocation */
00290   if(hlptim == NULL)
00291   {
00292     return HAL_ERROR;
00293   }
00294   
00295   /* Change the LPTIM state */
00296   hlptim->State = HAL_LPTIM_STATE_BUSY;
00297   
00298   /* Disable the LPTIM Peripheral Clock */
00299   __HAL_LPTIM_DISABLE(hlptim);
00300   
00301   /* DeInit the low level hardware: CLOCK, NVIC.*/
00302   HAL_LPTIM_MspDeInit(hlptim);
00303   
00304   /* Change the LPTIM state */
00305   hlptim->State = HAL_LPTIM_STATE_RESET;
00306   
00307   /* Release Lock */
00308   __HAL_UNLOCK(hlptim);
00309   
00310   /* Return function status */
00311   return HAL_OK;
00312 }
00313 
00314 /**
00315   * @brief  Initialize the LPTIM MSP.
00316   * @param  hlptim: LPTIM handle
00317   * @retval None
00318   */
00319 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
00320 {
00321   /* NOTE : This function should not be modified, when the callback is needed,
00322             the HAL_LPTIM_MspInit could be implemented in the user file
00323    */
00324 }
00325 
00326 /**
00327   * @brief  DeInitialize LPTIM MSP.
00328   * @param  hlptim: LPTIM handle
00329   * @retval None
00330   */
00331 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
00332 {
00333   /* NOTE : This function should not be modified, when the callback is needed,
00334             the HAL_LPTIM_MspDeInit could be implemented in the user file
00335    */
00336 }
00337 
00338 /**
00339   * @}
00340   */
00341 
00342 /** @defgroup LPTIM_Group2 LPTIM Start-Stop operation functions 
00343  *  @brief   Start-Stop operation functions. 
00344  *
00345 @verbatim   
00346   ==============================================================================
00347                 ##### LPTIM Start Stop operation functions #####
00348   ==============================================================================  
00349     [..]  This section provides functions allowing to:
00350       (+) Start the PWM mode.
00351       (+) Stop the PWM mode.
00352       (+) Start the One pulse mode.
00353       (+) Stop the One pulse mode.
00354       (+) Start the Set once mode.
00355       (+) Stop the Set once mode.
00356       (+) Start the Encoder mode.
00357       (+) Stop the Encoder mode.
00358       (+) Start the Timeout mode.
00359       (+) Stop the Timeout mode.      
00360       (+) Start the Counter mode.
00361       (+) Stop the Counter mode.
00362       
00363 
00364 @endverbatim
00365   * @{
00366   */
00367     
00368 /**
00369   * @brief  Start the LPTIM PWM generation.
00370   * @param  hlptim : LPTIM handle
00371   * @param  Period : Specifies the Autoreload value.
00372   *         This parameter must be a value between 0x0000 and 0xFFFF.
00373   * @param  Pulse : Specifies the compare value.
00374   *         This parameter must be a value between 0x0000 and 0xFFFF.
00375   * @retval HAL status
00376   */
00377 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00378 {
00379   /* Check the parameters */
00380   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00381   assert_param(IS_LPTIM_PERIOD(Period));
00382   assert_param(IS_LPTIM_PULSE(Pulse));
00383                
00384   /* Set the LPTIM state */
00385   hlptim->State= HAL_LPTIM_STATE_BUSY;
00386  
00387   /* Reset WAVE bit to set PWM mode */
00388   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00389   
00390   /* Enable the Peripheral */
00391   __HAL_LPTIM_ENABLE(hlptim);
00392   
00393   /* Load the period value in the autoreload register */
00394   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00395   
00396   /* Load the pulse value in the compare register */
00397   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00398   
00399   /* Start timer in continuous mode */
00400   __HAL_LPTIM_START_CONTINUOUS(hlptim);
00401     
00402   /* Change the TIM state*/
00403   hlptim->State= HAL_LPTIM_STATE_READY;
00404   
00405   /* Return function status */
00406   return HAL_OK;
00407 }
00408 
00409 /**
00410   * @brief  Stop the LPTIM PWM generation.
00411   * @param  hlptim : LPTIM handle
00412   * @retval HAL status
00413   */
00414 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
00415 {
00416   /* Check the parameters */
00417   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00418                
00419   /* Set the LPTIM state */
00420   hlptim->State= HAL_LPTIM_STATE_BUSY;
00421   
00422   /* Disable the Peripheral */
00423   __HAL_LPTIM_DISABLE(hlptim);
00424 
00425   /* Change the TIM state*/
00426   hlptim->State= HAL_LPTIM_STATE_READY;
00427   
00428   /* Return function status */
00429   return HAL_OK;
00430 }
00431 
00432 /**
00433   * @brief  Start the LPTIM PWM generation in interrupt mode.
00434   * @param  hlptim : LPTIM handle
00435   * @param  Period : Specifies the Autoreload value.
00436   *         This parameter must be a value between 0x0000 and 0xFFFF
00437   * @param  Pulse : Specifies the compare value.
00438   *         This parameter must be a value between 0x0000 and 0xFFFF
00439   * @retval HAL status
00440   */
00441 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00442 {
00443   /* Check the parameters */
00444   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00445   assert_param(IS_LPTIM_PERIOD(Period));
00446   assert_param(IS_LPTIM_PULSE(Pulse));
00447                
00448   /* Set the LPTIM state */
00449   hlptim->State= HAL_LPTIM_STATE_BUSY;
00450  
00451   /* Reset WAVE bit to set PWM mode */
00452   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00453   
00454   /* Enable Autoreload write complete interrupt */
00455   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
00456   
00457   /* Enable Compare write complete interrupt */
00458   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
00459   
00460   /* Enable Autoreload match interrupt */
00461   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
00462   
00463   /* Enable Compare match interrupt */
00464   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
00465   
00466   /* If external trigger source is used, then enable external trigger interrupt */
00467   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00468   {
00469     /* Enable external trigger interrupt */
00470     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00471   }  
00472   
00473   /* Enable the Peripheral */
00474   __HAL_LPTIM_ENABLE(hlptim);
00475   
00476   /* Load the period value in the autoreload register */
00477   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00478   
00479   /* Load the pulse value in the compare register */
00480   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00481   
00482   /* Start timer in continuous mode */
00483   __HAL_LPTIM_START_CONTINUOUS(hlptim);
00484     
00485   /* Change the TIM state*/
00486   hlptim->State= HAL_LPTIM_STATE_READY;
00487   
00488   /* Return function status */
00489   return HAL_OK;
00490 }
00491 
00492 /**
00493   * @brief  Stop the LPTIM PWM generation in interrupt mode.
00494   * @param  hlptim : LPTIM handle
00495   * @retval HAL status
00496   */
00497 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
00498 {
00499   /* Check the parameters */
00500   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00501                
00502   /* Set the LPTIM state */
00503   hlptim->State= HAL_LPTIM_STATE_BUSY;
00504   
00505   /* Disable the Peripheral */
00506   __HAL_LPTIM_DISABLE(hlptim);
00507   
00508     /* Disable Autoreload write complete interrupt */
00509   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
00510   
00511   /* Disable Compare write complete interrupt */
00512   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
00513   
00514   /* Disable Autoreload match interrupt */
00515   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
00516   
00517   /* Disable Compare match interrupt */
00518   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
00519   
00520   /* If external trigger source is used, then disable external trigger interrupt */
00521   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00522   {
00523     /* Disable external trigger interrupt */
00524     __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00525   }  
00526 
00527   /* Change the TIM state*/
00528   hlptim->State= HAL_LPTIM_STATE_READY;
00529   
00530   /* Return function status */
00531   return HAL_OK;
00532 }
00533 
00534 /**
00535   * @brief  Start the LPTIM One pulse generation.
00536   * @param  hlptim : LPTIM handle
00537   * @param  Period : Specifies the Autoreload value.
00538   *         This parameter must be a value between 0x0000 and 0xFFFF.
00539   * @param  Pulse : Specifies the compare value.
00540   *         This parameter must be a value between 0x0000 and 0xFFFF.
00541   * @retval HAL status
00542   */
00543 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00544 {
00545   /* Check the parameters */
00546   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00547   assert_param(IS_LPTIM_PERIOD(Period));
00548   assert_param(IS_LPTIM_PULSE(Pulse));
00549                
00550   /* Set the LPTIM state */
00551   hlptim->State= HAL_LPTIM_STATE_BUSY;
00552   
00553   /* Reset WAVE bit to set one pulse mode */
00554   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00555   
00556   /* Enable the Peripheral */
00557   __HAL_LPTIM_ENABLE(hlptim);
00558   
00559   /* Load the period value in the autoreload register */
00560   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00561   
00562   /* Load the pulse value in the compare register */
00563   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00564   
00565   /* Start timer in continuous mode */
00566   __HAL_LPTIM_START_SINGLE(hlptim);
00567     
00568   /* Change the TIM state*/
00569   hlptim->State= HAL_LPTIM_STATE_READY;
00570   
00571   /* Return function status */
00572   return HAL_OK;
00573 }
00574 
00575 /**
00576   * @brief  Stop the LPTIM One pulse generation.
00577   * @param  hlptim : LPTIM handle
00578   * @retval HAL status
00579   */
00580 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
00581 {
00582   /* Check the parameters */
00583   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00584                
00585   /* Set the LPTIM state */
00586   hlptim->State= HAL_LPTIM_STATE_BUSY;
00587   
00588   /* Disable the Peripheral */
00589   __HAL_LPTIM_DISABLE(hlptim);
00590 
00591   /* Change the TIM state*/
00592   hlptim->State= HAL_LPTIM_STATE_READY;
00593   
00594   /* Return function status */
00595   return HAL_OK;
00596 }
00597 
00598 /**
00599   * @brief  Start the LPTIM One pulse generation in interrupt mode.
00600   * @param  hlptim : LPTIM handle
00601   * @param  Period : Specifies the Autoreload value.
00602   *         This parameter must be a value between 0x0000 and 0xFFFF.
00603   * @param  Pulse : Specifies the compare value.
00604   *         This parameter must be a value between 0x0000 and 0xFFFF.
00605   * @retval HAL status
00606   */
00607 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00608 {
00609   /* Check the parameters */
00610   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00611   assert_param(IS_LPTIM_PERIOD(Period));
00612   assert_param(IS_LPTIM_PULSE(Pulse));
00613                
00614   /* Set the LPTIM state */
00615   hlptim->State= HAL_LPTIM_STATE_BUSY;
00616   
00617   /* Reset WAVE bit to set one pulse mode */
00618   hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
00619   
00620   /* Enable Autoreload write complete interrupt */
00621   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
00622   
00623   /* Enable Compare write complete interrupt */
00624   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
00625   
00626   /* Enable Autoreload match interrupt */
00627   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
00628   
00629   /* Enable Compare match interrupt */
00630   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
00631   
00632   /* If external trigger source is used, then enable external trigger interrupt */
00633   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00634   {
00635     /* Enable external trigger interrupt */
00636     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00637   }
00638   
00639   /* Enable the Peripheral */
00640   __HAL_LPTIM_ENABLE(hlptim);
00641   
00642   /* Load the period value in the autoreload register */
00643   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00644   
00645   /* Load the pulse value in the compare register */
00646   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00647   
00648   /* Start timer in continuous mode */
00649   __HAL_LPTIM_START_SINGLE(hlptim);
00650     
00651   /* Change the TIM state*/
00652   hlptim->State= HAL_LPTIM_STATE_READY;
00653   
00654   /* Return function status */
00655   return HAL_OK;
00656 }
00657 
00658 /**
00659   * @brief  Stop the LPTIM One pulse generation in interrupt mode.
00660   * @param  hlptim : LPTIM handle
00661   * @retval HAL status
00662   */
00663 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
00664 {
00665   /* Check the parameters */
00666   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00667                
00668   /* Set the LPTIM state */
00669   hlptim->State= HAL_LPTIM_STATE_BUSY;
00670   
00671   /* Disable the Peripheral */
00672   __HAL_LPTIM_DISABLE(hlptim);
00673   
00674   /* Disable Autoreload write complete interrupt */
00675   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
00676   
00677   /* Disable Compare write complete interrupt */
00678   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
00679   
00680   /* Disable Autoreload match interrupt */
00681   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
00682   
00683   /* Disable Compare match interrupt */
00684   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
00685   
00686   /* If external trigger source is used, then disable external trigger interrupt */
00687   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00688   {
00689     /* Disable external trigger interrupt */
00690     __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00691   }
00692   
00693   /* Change the TIM state*/
00694   hlptim->State= HAL_LPTIM_STATE_READY;
00695   
00696   /* Return function status */
00697   return HAL_OK;
00698 }
00699 
00700 /**
00701   * @brief  Start the LPTIM in Set once mode.
00702   * @param  hlptim : LPTIM handle
00703   * @param  Period : Specifies the Autoreload value.
00704   *         This parameter must be a value between 0x0000 and 0xFFFF.
00705   * @param  Pulse : Specifies the compare value.
00706   *         This parameter must be a value between 0x0000 and 0xFFFF.
00707   * @retval HAL status
00708   */
00709 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00710 {
00711   /* Check the parameters */
00712   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00713   assert_param(IS_LPTIM_PERIOD(Period));
00714   assert_param(IS_LPTIM_PULSE(Pulse));
00715                
00716   /* Set the LPTIM state */
00717   hlptim->State= HAL_LPTIM_STATE_BUSY;
00718   
00719   /* Set WAVE bit to enable the set once mode */
00720   hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
00721   
00722   /* Enable the Peripheral */
00723   __HAL_LPTIM_ENABLE(hlptim);
00724   
00725   /* Load the period value in the autoreload register */
00726   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00727   
00728   /* Load the pulse value in the compare register */
00729   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00730   
00731   /* Start timer in continuous mode */
00732   __HAL_LPTIM_START_SINGLE(hlptim);
00733     
00734   /* Change the TIM state*/
00735   hlptim->State= HAL_LPTIM_STATE_READY;
00736   
00737   /* Return function status */
00738   return HAL_OK;
00739 }
00740 
00741 /**
00742   * @brief  Stop the LPTIM Set once mode.
00743   * @param  hlptim : LPTIM handle
00744   * @retval HAL status
00745   */
00746 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
00747 {
00748   /* Check the parameters */
00749   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00750                
00751   /* Set the LPTIM state */
00752   hlptim->State= HAL_LPTIM_STATE_BUSY;
00753   
00754   /* Disable the Peripheral */
00755   __HAL_LPTIM_DISABLE(hlptim);
00756 
00757   /* Change the TIM state*/
00758   hlptim->State= HAL_LPTIM_STATE_READY;
00759   
00760   /* Return function status */
00761   return HAL_OK;
00762 }
00763 
00764 /**
00765   * @brief  Start the LPTIM Set once mode in interrupt mode.
00766   * @param  hlptim : LPTIM handle
00767   * @param  Period : Specifies the Autoreload value.
00768   *         This parameter must be a value between 0x0000 and 0xFFFF.
00769   * @param  Pulse : Specifies the compare value.
00770   *         This parameter must be a value between 0x0000 and 0xFFFF.
00771   * @retval HAL status
00772   */
00773 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
00774 {
00775   /* Check the parameters */
00776   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00777   assert_param(IS_LPTIM_PERIOD(Period));
00778   assert_param(IS_LPTIM_PULSE(Pulse));
00779                
00780   /* Set the LPTIM state */
00781   hlptim->State= HAL_LPTIM_STATE_BUSY;
00782   
00783   /* Set WAVE bit to enable the set once mode */
00784   hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
00785   
00786   /* Enable Autoreload write complete interrupt */
00787   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
00788   
00789   /* Enable Compare write complete interrupt */
00790   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
00791   
00792   /* Enable Autoreload match interrupt */
00793   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
00794   
00795   /* Enable Compare match interrupt */
00796   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
00797   
00798   /* If external trigger source is used, then enable external trigger interrupt */
00799   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00800   {
00801     /* Enable external trigger interrupt */
00802     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00803   }  
00804   
00805   /* Enable the Peripheral */
00806   __HAL_LPTIM_ENABLE(hlptim);
00807   
00808   /* Load the period value in the autoreload register */
00809   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00810   
00811   /* Load the pulse value in the compare register */
00812   __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
00813   
00814   /* Start timer in continuous mode */
00815   __HAL_LPTIM_START_SINGLE(hlptim);
00816     
00817   /* Change the TIM state*/
00818   hlptim->State= HAL_LPTIM_STATE_READY;
00819   
00820   /* Return function status */
00821   return HAL_OK;
00822 }
00823 
00824 /**
00825   * @brief  Stop the LPTIM Set once mode in interrupt mode.
00826   * @param  hlptim : LPTIM handle
00827   * @retval HAL status
00828   */
00829 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
00830 {
00831   /* Check the parameters */
00832   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00833                
00834   /* Set the LPTIM state */
00835   hlptim->State= HAL_LPTIM_STATE_BUSY;
00836   
00837   /* Disable the Peripheral */
00838   __HAL_LPTIM_DISABLE(hlptim);
00839 
00840   /* Disable Autoreload write complete interrupt */
00841   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
00842   
00843   /* Disable Compare write complete interrupt */
00844   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
00845   
00846   /* Disable Autoreload match interrupt */
00847   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
00848   
00849   /* Disable Compare match interrupt */
00850   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
00851   
00852   /* If external trigger source is used, then disable external trigger interrupt */
00853   if ((hlptim->Init.Trigger.Source) !=  LPTIM_TRIGSOURCE_SOFTWARE)
00854   {
00855     /* Disable external trigger interrupt */
00856     __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
00857   } 
00858   
00859   /* Change the TIM state*/
00860   hlptim->State= HAL_LPTIM_STATE_READY;
00861   
00862   /* Return function status */
00863   return HAL_OK;
00864 }
00865 
00866 /**
00867   * @brief  Start the Encoder interface.
00868   * @param  hlptim : LPTIM handle
00869   * @param  Period : Specifies the Autoreload value.
00870   *         This parameter must be a value between 0x0000 and 0xFFFF.
00871   * @retval HAL status
00872   */
00873 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
00874 {
00875   HAL_StatusTypeDef status = HAL_OK;
00876   uint32_t          tmpcfgr;
00877 
00878   /* Check the parameters */
00879   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00880   assert_param(IS_LPTIM_PERIOD(Period));
00881   assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
00882   assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
00883   assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
00884 
00885   /* Encoder feature is only available for LPTIM1 instance */
00886   if (hlptim->Instance == LPTIM1)
00887   {
00888     /* Set the LPTIM state */
00889     hlptim->State= HAL_LPTIM_STATE_BUSY;
00890 
00891     /* Get the LPTIMx CFGR value */
00892     tmpcfgr = hlptim->Instance->CFGR;
00893 
00894     /* Clear CKPOL bits */
00895     tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
00896 
00897     /* Set Input polarity */
00898     tmpcfgr |=  hlptim->Init.UltraLowPowerClock.Polarity;
00899 
00900     /* Write to LPTIMx CFGR */
00901     hlptim->Instance->CFGR = tmpcfgr;
00902 
00903     /* Set ENC bit to enable the encoder interface */
00904     hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
00905 
00906     /* Enable the Peripheral */
00907     __HAL_LPTIM_ENABLE(hlptim);
00908 
00909     /* Load the period value in the autoreload register */
00910     __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
00911 
00912     /* Start timer in continuous mode */
00913     __HAL_LPTIM_START_CONTINUOUS(hlptim);
00914 
00915     /* Change the TIM state*/
00916     hlptim->State= HAL_LPTIM_STATE_READY;
00917   }
00918   else
00919   {
00920     status = HAL_ERROR;
00921   }
00922 
00923   /* Return function status */
00924   return status;
00925 }
00926 
00927 /**
00928   * @brief  Stop the Encoder interface.
00929   * @param  hlptim : LPTIM handle
00930   * @retval HAL status
00931   */
00932 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
00933 {
00934   /* Check the parameters */
00935   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00936                
00937   /* Set the LPTIM state */
00938   hlptim->State= HAL_LPTIM_STATE_BUSY;
00939   
00940   /* Disable the Peripheral */
00941   __HAL_LPTIM_DISABLE(hlptim);
00942   
00943   /* Reset ENC bit to disable the encoder interface */
00944   hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
00945   
00946   /* Change the TIM state*/
00947   hlptim->State= HAL_LPTIM_STATE_READY;
00948   
00949   /* Return function status */
00950   return HAL_OK;
00951 }
00952 
00953 /**
00954   * @brief  Start the Encoder interface in interrupt mode.
00955   * @param  hlptim : LPTIM handle
00956   * @param  Period : Specifies the Autoreload value.
00957   *         This parameter must be a value between 0x0000 and 0xFFFF.
00958   * @retval HAL status
00959   */
00960 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
00961 {
00962   HAL_StatusTypeDef status = HAL_OK;
00963   uint32_t          tmpcfgr;
00964 
00965   /* Check the parameters */
00966   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
00967   assert_param(IS_LPTIM_PERIOD(Period));
00968   assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
00969   assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
00970   assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
00971 
00972   /* Encoder feature is only available for LPTIM1 instance */
00973   if (hlptim->Instance == LPTIM1)
00974   {
00975     /* Set the LPTIM state */
00976     hlptim->State= HAL_LPTIM_STATE_BUSY;
00977 
00978     /* Configure edge sensitivity for encoder mode */
00979     /* Get the LPTIMx CFGR value */
00980     tmpcfgr = hlptim->Instance->CFGR;
00981 
00982     /* Clear CKPOL bits */
00983     tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
00984 
00985     /* Set Input polarity */
00986     tmpcfgr |=  hlptim->Init.UltraLowPowerClock.Polarity;
00987 
00988     /* Write to LPTIMx CFGR */
00989     hlptim->Instance->CFGR = tmpcfgr;
00990 
00991     /* Set ENC bit to enable the encoder interface */
00992     hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
00993 
00994     /* Enable "switch to down direction" interrupt */
00995     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
00996 
00997     /* Enable "switch to up direction" interrupt */
00998     __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);  
00999 
01000     /* Enable the Peripheral */
01001     __HAL_LPTIM_ENABLE(hlptim);
01002 
01003     /* Load the period value in the autoreload register */
01004     __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01005 
01006     /* Start timer in continuous mode */
01007     __HAL_LPTIM_START_CONTINUOUS(hlptim);
01008 
01009     /* Change the TIM state*/
01010     hlptim->State= HAL_LPTIM_STATE_READY;
01011   }
01012   else
01013   {
01014     status = HAL_ERROR;
01015   }
01016 
01017   /* Return function status */
01018   return status;
01019 }
01020 
01021 /**
01022   * @brief  Stop the Encoder interface in interrupt mode.
01023   * @param  hlptim : LPTIM handle
01024   * @retval HAL status
01025   */
01026 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01027 {
01028   /* Check the parameters */
01029   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01030                
01031   /* Set the LPTIM state */
01032   hlptim->State= HAL_LPTIM_STATE_BUSY;
01033   
01034   /* Disable the Peripheral */
01035   __HAL_LPTIM_DISABLE(hlptim);
01036   
01037   /* Reset ENC bit to disable the encoder interface */
01038   hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
01039   
01040   /* Disable "switch to down direction" interrupt */
01041   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
01042   
01043   /* Disable "switch to up direction" interrupt */
01044   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP); 
01045   
01046   /* Change the TIM state*/
01047   hlptim->State= HAL_LPTIM_STATE_READY;
01048   
01049   /* Return function status */
01050   return HAL_OK;
01051 }
01052 
01053 /**
01054   * @brief  Start the Timeout function.
01055   * @note   The first trigger event will start the timer, any successive
01056   *         trigger event will reset the counter and the timer restarts.
01057   * @param  hlptim : LPTIM handle
01058   * @param  Period : Specifies the Autoreload value.
01059   *         This parameter must be a value between 0x0000 and 0xFFFF.
01060   * @param  Timeout : Specifies the TimeOut value to rest the counter.
01061   *         This parameter must be a value between 0x0000 and 0xFFFF.
01062   * @retval HAL status
01063   */
01064 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
01065 {
01066   /* Check the parameters */
01067   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01068   assert_param(IS_LPTIM_PERIOD(Period));
01069   assert_param(IS_LPTIM_PULSE(Timeout));
01070                
01071   /* Set the LPTIM state */
01072   hlptim->State= HAL_LPTIM_STATE_BUSY;
01073  
01074   /* Set TIMOUT bit to enable the timeout function */
01075   hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
01076   
01077   /* Enable the Peripheral */
01078   __HAL_LPTIM_ENABLE(hlptim);
01079   
01080   /* Load the period value in the autoreload register */
01081   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01082   
01083   /* Load the Timeout value in the compare register */
01084   __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
01085   
01086   /* Start timer in continuous mode */
01087   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01088     
01089   /* Change the TIM state*/
01090   hlptim->State= HAL_LPTIM_STATE_READY;
01091   
01092   /* Return function status */
01093   return HAL_OK;
01094 }
01095 
01096 /**
01097   * @brief  Stop the Timeout function.
01098   * @param  hlptim : LPTIM handle
01099   * @retval HAL status
01100   */
01101 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
01102 {
01103   /* Check the parameters */
01104   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01105   
01106   /* Set the LPTIM state */
01107   hlptim->State= HAL_LPTIM_STATE_BUSY;
01108   
01109   /* Disable the Peripheral */
01110   __HAL_LPTIM_DISABLE(hlptim);
01111   
01112   /* Reset TIMOUT bit to enable the timeout function */
01113   hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
01114   
01115   /* Change the TIM state*/
01116   hlptim->State= HAL_LPTIM_STATE_READY;
01117   
01118   /* Return function status */
01119   return HAL_OK;
01120 }
01121 
01122 /**
01123   * @brief  Start the Timeout function in interrupt mode.
01124   * @note   The first trigger event will start the timer, any successive
01125   *         trigger event will reset the counter and the timer restarts.
01126   * @param  hlptim : LPTIM handle
01127   * @param  Period : Specifies the Autoreload value.
01128   *         This parameter must be a value between 0x0000 and 0xFFFF.
01129   * @param  Timeout : Specifies the TimeOut value to rest the counter.
01130   *         This parameter must be a value between 0x0000 and 0xFFFF.
01131   * @retval HAL status
01132   */
01133 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
01134 {
01135   /* Check the parameters */
01136   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01137   assert_param(IS_LPTIM_PERIOD(Period));
01138   assert_param(IS_LPTIM_PULSE(Timeout));
01139                
01140   /* Set the LPTIM state */
01141   hlptim->State= HAL_LPTIM_STATE_BUSY;
01142  
01143   /* Set TIMOUT bit to enable the timeout function */
01144   hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
01145   
01146   /* Enable Compare match interrupt */
01147   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
01148   
01149   /* Enable the Peripheral */
01150   __HAL_LPTIM_ENABLE(hlptim);
01151   
01152   /* Load the period value in the autoreload register */
01153   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01154   
01155   /* Load the Timeout value in the compare register */
01156   __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
01157   
01158   /* Start timer in continuous mode */
01159   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01160     
01161   /* Change the TIM state*/
01162   hlptim->State= HAL_LPTIM_STATE_READY;
01163   
01164   /* Return function status */
01165   return HAL_OK;
01166 }
01167 
01168 /**
01169   * @brief  Stop the Timeout function in interrupt mode.
01170   * @param  hlptim : LPTIM handle
01171   * @retval HAL status
01172   */
01173 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01174 {
01175   /* Check the parameters */
01176   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01177   
01178   /* Set the LPTIM state */
01179   hlptim->State= HAL_LPTIM_STATE_BUSY;
01180   
01181   /* Disable the Peripheral */
01182   __HAL_LPTIM_DISABLE(hlptim);
01183   
01184   /* Reset TIMOUT bit to enable the timeout function */
01185   hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
01186   
01187   /* Disable Compare match interrupt */
01188   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
01189   
01190   /* Change the TIM state*/
01191   hlptim->State= HAL_LPTIM_STATE_READY;
01192   
01193   /* Return function status */
01194   return HAL_OK;
01195 }
01196 
01197 /**
01198   * @brief  Start the Counter mode.
01199   * @param  hlptim : LPTIM handle
01200   * @param  Period : Specifies the Autoreload value.
01201   *         This parameter must be a value between 0x0000 and 0xFFFF.
01202   * @retval HAL status
01203   */
01204 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
01205 {
01206   /* Check the parameters */
01207   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01208   assert_param(IS_LPTIM_PERIOD(Period));
01209                
01210   /* Set the LPTIM state */
01211   hlptim->State= HAL_LPTIM_STATE_BUSY;
01212   
01213   /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
01214   if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
01215   {
01216     /* Check if clock is prescaled */
01217     assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
01218     /* Set clock prescaler to 0 */
01219     hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
01220   }
01221 
01222   /* Enable the Peripheral */
01223   __HAL_LPTIM_ENABLE(hlptim);
01224   
01225   /* Load the period value in the autoreload register */
01226   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01227   
01228   /* Start timer in continuous mode */
01229   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01230     
01231   /* Change the TIM state*/
01232   hlptim->State= HAL_LPTIM_STATE_READY;
01233   
01234   /* Return function status */
01235   return HAL_OK;
01236 }
01237 
01238 /**
01239   * @brief  Stop the Counter mode.
01240   * @param  hlptim : LPTIM handle
01241   * @retval HAL status
01242   */
01243 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
01244 {
01245   /* Check the parameters */
01246   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01247   
01248   /* Set the LPTIM state */
01249   hlptim->State= HAL_LPTIM_STATE_BUSY;
01250   
01251   /* Disable the Peripheral */
01252   __HAL_LPTIM_DISABLE(hlptim);
01253   
01254   /* Change the TIM state*/
01255   hlptim->State= HAL_LPTIM_STATE_READY;
01256   
01257   /* Return function status */
01258   return HAL_OK;
01259 }
01260 
01261 /**
01262   * @brief  Start the Counter mode in interrupt mode.
01263   * @param  hlptim : LPTIM handle
01264   * @param  Period : Specifies the Autoreload value.
01265   *         This parameter must be a value between 0x0000 and 0xFFFF.
01266   * @retval HAL status
01267   */
01268 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
01269 {
01270   /* Check the parameters */
01271   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01272   assert_param(IS_LPTIM_PERIOD(Period));
01273                
01274   /* Set the LPTIM state */
01275   hlptim->State= HAL_LPTIM_STATE_BUSY;
01276   
01277   /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
01278   if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
01279   {
01280     /* Check if clock is prescaled */
01281     assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
01282     /* Set clock prescaler to 0 */
01283     hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
01284   }
01285   
01286   /* Enable Autoreload write complete interrupt */
01287   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
01288   
01289   /* Enable Autoreload match interrupt */
01290   __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
01291   
01292   /* Enable the Peripheral */
01293   __HAL_LPTIM_ENABLE(hlptim);
01294   
01295   /* Load the period value in the autoreload register */
01296   __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
01297   
01298   /* Start timer in continuous mode */
01299   __HAL_LPTIM_START_CONTINUOUS(hlptim);
01300     
01301   /* Change the TIM state*/
01302   hlptim->State= HAL_LPTIM_STATE_READY;
01303   
01304   /* Return function status */
01305   return HAL_OK;
01306 }
01307 
01308 /**
01309   * @brief  Stop the Counter mode in interrupt mode.
01310   * @param  hlptim : LPTIM handle
01311   * @retval HAL status
01312   */
01313 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
01314 {
01315   /* Check the parameters */
01316   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01317   
01318   /* Set the LPTIM state */
01319   hlptim->State= HAL_LPTIM_STATE_BUSY;
01320   
01321   /* Disable the Peripheral */
01322   __HAL_LPTIM_DISABLE(hlptim);
01323   
01324   /* Disable Autoreload write complete interrupt */
01325   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
01326   
01327   /* Disable Autoreload match interrupt */
01328   __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
01329   
01330   /* Change the TIM state*/
01331   hlptim->State= HAL_LPTIM_STATE_READY;
01332   
01333   /* Return function status */
01334   return HAL_OK;
01335 }
01336 
01337 /**
01338   * @}
01339   */
01340 
01341 /** @defgroup LPTIM_Group3 LPTIM Read operation functions 
01342  *  @brief  Read operation functions.
01343  *
01344 @verbatim   
01345   ==============================================================================
01346                   ##### LPTIM Read operation functions #####
01347   ==============================================================================  
01348 [..]  This section provides LPTIM Reading functions.
01349       (+) Read the counter value.
01350       (+) Read the period (Auto-reload) value.
01351       (+) Read the pulse (Compare)value.
01352 @endverbatim
01353   * @{
01354   */
01355 
01356 /**
01357   * @brief  Return the current counter value.
01358   * @param  hlptim: LPTIM handle
01359   * @retval Counter value.
01360   */
01361 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
01362 {
01363     /* Check the parameters */
01364   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01365   
01366   return (hlptim->Instance->CNT);
01367 }
01368 
01369 /**
01370   * @brief  Return the current Autoreload (Period) value.
01371   * @param  hlptim: LPTIM handle
01372   * @retval Autoreload value.
01373   */
01374 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
01375 {
01376     /* Check the parameters */
01377   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01378   
01379   return (hlptim->Instance->ARR);
01380 }
01381 
01382 /**
01383   * @brief  Return the current Compare (Pulse) value.
01384   * @param  hlptim: LPTIM handle
01385   * @retval Compare value.
01386   */
01387 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
01388 {
01389     /* Check the parameters */
01390   assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
01391   
01392   return (hlptim->Instance->CMP);
01393 }
01394 
01395 /**
01396   * @}
01397   */
01398 
01399 
01400 
01401 /** @defgroup LPTIM_Group4 LPTIM IRQ handler and callbacks
01402  *  @brief  LPTIM  IRQ handler.
01403  *
01404 @verbatim   
01405   ==============================================================================
01406                       ##### LPTIM IRQ handler and callbacks  #####
01407   ==============================================================================  
01408 [..]  This section provides LPTIM IRQ handler and callback functions called within 
01409       the IRQ handler.
01410 
01411 @endverbatim
01412   * @{
01413   */
01414 
01415 /**
01416   * @brief  Handle LPTIM interrupt request.
01417   * @param  hlptim: LPTIM handle
01418   * @retval None
01419   */
01420 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
01421 {
01422   /* Compare match interrupt */
01423   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
01424   {
01425     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) != RESET)
01426     {
01427       /* Clear Compare match flag */
01428       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
01429       
01430       /* Compare match Callback */
01431       HAL_LPTIM_CompareMatchCallback(hlptim);      
01432     }
01433   }
01434   
01435   /* Autoreload match interrupt */
01436   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
01437   {
01438     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET)
01439     {
01440       /* Clear Autoreload match flag */
01441       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
01442       
01443       /* Autoreload match Callback */
01444       HAL_LPTIM_AutoReloadMatchCallback(hlptim);      
01445     }
01446   }
01447   
01448   /* Trigger detected interrupt */
01449   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
01450   {
01451     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) != RESET)
01452     {
01453       /* Clear Trigger detected flag */
01454       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
01455       
01456       /* Trigger detected callback */
01457       HAL_LPTIM_TriggerCallback(hlptim);      
01458     }
01459   }
01460   
01461   /* Compare write interrupt */
01462   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
01463   {
01464     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) != RESET)
01465     {
01466       /* Clear Compare write flag */
01467       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
01468       
01469       /* Compare write Callback */
01470       HAL_LPTIM_CompareWriteCallback(hlptim);      
01471     }
01472   }
01473   
01474   /* Autoreload write interrupt */
01475   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
01476   {
01477     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET)
01478     {
01479       /* Clear Autoreload write flag */
01480       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
01481       
01482       /* Autoreload write Callback */
01483       HAL_LPTIM_AutoReloadWriteCallback(hlptim);      
01484     }
01485   }
01486   
01487   /* Direction counter changed from Down to Up interrupt */
01488   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
01489   {
01490     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) != RESET)
01491     {
01492       /* Clear Direction counter changed from Down to Up flag */
01493       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
01494       
01495       /* Direction counter changed from Down to Up Callback */
01496       HAL_LPTIM_DirectionUpCallback(hlptim);      
01497     }
01498   }
01499   
01500   /* Direction counter changed from Up to Down interrupt */
01501   if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
01502   {
01503     if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) != RESET)
01504     {
01505       /* Clear Direction counter changed from Up to Down flag */
01506       __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
01507       
01508       /* Direction counter changed from Up to Down Callback */
01509       HAL_LPTIM_DirectionDownCallback(hlptim);      
01510     }
01511   }
01512 }
01513 
01514 /**
01515   * @brief  Compare match callback in non-blocking mode.
01516   * @param  hlptim : LPTIM handle
01517   * @retval None
01518   */
01519 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
01520 {
01521   /* NOTE : This function should not be modified, when the callback is needed,
01522             the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
01523    */  
01524 }
01525 
01526 /**
01527   * @brief  Autoreload match callback in non-blocking mode.
01528   * @param  hlptim : LPTIM handle
01529   * @retval None
01530   */
01531 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
01532 {
01533   /* NOTE : This function should not be modified, when the callback is needed,
01534             the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
01535    */  
01536 }
01537 
01538 /**
01539   * @brief  Trigger detected callback in non-blocking mode.
01540   * @param  hlptim : LPTIM handle
01541   * @retval None
01542   */
01543 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
01544 {
01545   /* NOTE : This function should not be modified, when the callback is needed,
01546             the HAL_LPTIM_TriggerCallback could be implemented in the user file
01547    */  
01548 }
01549 
01550 /**
01551   * @brief  Compare write callback in non-blocking mode.
01552   * @param  hlptim : LPTIM handle
01553   * @retval None
01554   */
01555 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
01556 {
01557   /* NOTE : This function should not be modified, when the callback is needed,
01558             the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
01559    */  
01560 }
01561 
01562 /**
01563   * @brief  Autoreload write callback in non-blocking mode. 
01564   * @param  hlptim : LPTIM handle
01565   * @retval None
01566   */
01567 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
01568 {
01569   /* NOTE : This function should not be modified, when the callback is needed,
01570             the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
01571    */  
01572 }
01573 
01574 /**
01575   * @brief  Direction counter changed from Down to Up callback in non-blocking mode.
01576   * @param  hlptim : LPTIM handle
01577   * @retval None
01578   */
01579 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
01580 {
01581   /* NOTE : This function should not be modified, when the callback is needed,
01582             the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
01583    */  
01584 }
01585 
01586 /**
01587   * @brief  Direction counter changed from Up to Down callback in non-blocking mode.
01588   * @param  hlptim : LPTIM handle
01589   * @retval None
01590   */
01591 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
01592 {
01593   /* NOTE : This function should not be modified, when the callback is needed,
01594             the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
01595    */  
01596 }
01597 
01598 /**
01599   * @}
01600   */
01601 
01602 /** @defgroup LPTIM_Group5 Peripheral State functions 
01603  *  @brief   Peripheral State functions. 
01604  *
01605 @verbatim   
01606   ==============================================================================
01607                       ##### Peripheral State functions #####
01608   ==============================================================================  
01609     [..]
01610     This subsection permits to get in run-time the status of the peripheral.
01611 
01612 @endverbatim
01613   * @{
01614   */
01615 
01616 /**
01617   * @brief  Return the LPTIM handle state.
01618   * @param  hlptim: LPTIM handle
01619   * @retval HAL state
01620   */
01621 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
01622 {
01623   /* Return LPTIM handle state */
01624   return hlptim->State;
01625 }
01626 
01627 /**
01628   * @}
01629   */
01630 
01631 
01632 /**
01633   * @}
01634   */
01635 
01636 #endif /* HAL_LPTIM_MODULE_ENABLED */
01637 /**
01638   * @}
01639   */
01640 
01641 /**
01642   * @}
01643   */
01644 
01645 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
01646