2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_lptim.c
\r
4 * @author MCD Application Team
\r
6 * @date 24-March-2015
\r
7 * @brief LPTIM HAL module driver.
\r
9 * This file provides firmware functions to manage the following
\r
10 * functionalities of the Low Power Timer (LPTIM) peripheral:
\r
11 * + Initialization and de-initialization functions.
\r
12 * + Start/Stop operation functions in polling mode.
\r
13 * + Start/Stop operation functions in interrupt mode.
\r
14 * + Reading operation functions.
\r
15 * + Peripheral State functions.
\r
18 ==============================================================================
\r
19 ##### How to use this driver #####
\r
20 ==============================================================================
\r
22 The LPTIM HAL driver can be used as follows:
\r
24 (#)Initialize the LPTIM low level resources by implementing the
\r
25 HAL_LPTIM_MspInit():
\r
26 (##) Enable the LPTIM interface clock using __LPTIMx_CLK_ENABLE().
\r
27 (##) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
\r
28 (+) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
\r
29 (+) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
\r
30 (+) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
\r
32 (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
\r
34 (##) The instance: LPTIM1.
\r
35 (##) Clock: the counter clock.
\r
36 - Source : it can be either the ULPTIM input (IN1) or one of
\r
37 the internal clock; (APB, LSE, LSI or MSI).
\r
38 - Prescaler: select the clock divider.
\r
39 (##) UltraLowPowerClock : To be used only if the ULPTIM is selected
\r
40 as counter clock source.
\r
41 - Polarity: polarity of the active edge for the counter unit
\r
42 if the ULPTIM input is selected.
\r
43 - SampleTime: clock sampling time to configure the clock glitch
\r
45 (##) Trigger: How the counter start.
\r
46 - Source: trigger can be software or one of the hardware triggers.
\r
47 - ActiveEdge : only for hardware trigger.
\r
48 - SampleTime : trigger sampling time to configure the trigger
\r
50 (##) OutputPolarity : 2 opposite polarities are possibles.
\r
51 (##) UpdateMode: specifies whether the update of the autoreload and
\r
52 the compare values is done immediately or after the end of current
\r
55 (#)Six modes are available:
\r
57 (##) PWM Mode: To generate a PWM signal with specified period and pulse,
\r
58 call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
\r
61 (##) One Pulse Mode: To generate pulse with specified width in response
\r
62 to a stimulus, call HAL_LPTIM_OnePulse_Start() or
\r
63 HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
\r
65 (##) Set once Mode: In this mode, the output changes the level (from
\r
66 low level to high level if the output polarity is configured high, else
\r
67 the opposite) when a compare match occurs. To start this mode, call
\r
68 HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
\r
71 (##) Encoder Mode: To use the encoder interface call
\r
72 HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
\r
75 (##) Time out Mode: an active edge on one selected trigger input rests
\r
76 the counter. The first trigger event will start the timer, any
\r
77 successive trigger event will reset the counter and the timer will
\r
78 restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or
\r
79 HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
\r
81 (##) Counter Mode: counter can be used to count external events on
\r
82 the LPTIM Input1 or it can be used to count internal clock cycles.
\r
83 To start this mode, call HAL_LPTIM_Counter_Start() or
\r
84 HAL_LPTIM_Counter_Start_IT() for interruption mode.
\r
87 (#) User can stop any process by calling the corresponding API:
\r
88 HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
\r
89 already started in interruption mode.
\r
91 (#)Call HAL_LPTIM_DeInit() to deinitialize the LPTIM peripheral.
\r
94 ******************************************************************************
\r
97 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
99 * Redistribution and use in source and binary forms, with or without modification,
\r
100 * are permitted provided that the following conditions are met:
\r
101 * 1. Redistributions of source code must retain the above copyright notice,
\r
102 * this list of conditions and the following disclaimer.
\r
103 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
104 * this list of conditions and the following disclaimer in the documentation
\r
105 * and/or other materials provided with the distribution.
\r
106 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
107 * may be used to endorse or promote products derived from this software
\r
108 * without specific prior written permission.
\r
110 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
111 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
113 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
114 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
115 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
116 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
117 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
118 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
119 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
121 ******************************************************************************
\r
124 /* Includes ------------------------------------------------------------------*/
\r
125 #include "stm32f7xx_hal.h"
\r
127 /** @addtogroup STM32F7xx_HAL_Driver
\r
131 /** @defgroup LPTIM LPTIM
\r
132 * @brief LPTIM HAL module driver.
\r
136 #ifdef HAL_LPTIM_MODULE_ENABLED
\r
137 /* Private types -------------------------------------------------------------*/
\r
138 /** @defgroup LPTIM_Private_Types LPTIM Private Types
\r
146 /* Private defines -----------------------------------------------------------*/
\r
147 /** @defgroup LPTIM_Private_Defines LPTIM Private Defines
\r
155 /* Private variables ---------------------------------------------------------*/
\r
156 /** @addtogroup LPTIM_Private_Variables LPTIM Private Variables
\r
164 /* Private constants ---------------------------------------------------------*/
\r
165 /** @addtogroup LPTIM_Private_Constants LPTIM Private Constants
\r
173 /* Private macros ------------------------------------------------------------*/
\r
174 /** @addtogroup LPTIM_Private_Macros LPTIM Private Macros
\r
182 /* Private function prototypes -----------------------------------------------*/
\r
183 /** @addtogroup LPTIM_Private_Functions_Prototypes LPTIM Private Functions Prototypes
\r
191 /* Private functions ---------------------------------------------------------*/
\r
192 /** @addtogroup LPTIM_Private_Functions LPTIM Private Functions
\r
200 /* Exported functions ---------------------------------------------------------*/
\r
201 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
\r
205 /** @defgroup LPTIM_Group1 Initialization/de-initialization functions
\r
206 * @brief Initialization and Configuration functions.
\r
209 ==============================================================================
\r
210 ##### Initialization and de-initialization functions #####
\r
211 ==============================================================================
\r
212 [..] This section provides functions allowing to:
\r
213 (+) Initialize the LPTIM according to the specified parameters in the
\r
214 LPTIM_InitTypeDef and creates the associated handle.
\r
215 (+) DeInitialize the LPTIM peripheral.
\r
216 (+) Initialize the LPTIM MSP.
\r
217 (+) DeInitialize LPTIM MSP.
\r
224 * @brief Initializes the LPTIM according to the specified parameters in the
\r
225 * LPTIM_InitTypeDef and creates the associated handle.
\r
226 * @param hlptim: LPTIM handle
\r
227 * @retval HAL status
\r
229 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
\r
231 uint32_t tmpcfgr = 0;
\r
233 /* Check the LPTIM handle allocation */
\r
239 /* Check the parameters */
\r
240 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
242 assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
\r
243 assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));
\r
244 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
\r
246 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
\r
247 assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
\r
249 assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
\r
250 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
252 assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
\r
253 assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
\r
255 assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));
\r
256 assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
\r
257 assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
\r
259 if(hlptim->State == HAL_LPTIM_STATE_RESET)
\r
261 /* Init the low level hardware */
\r
262 HAL_LPTIM_MspInit(hlptim);
\r
265 /* Change the LPTIM state */
\r
266 hlptim->State = HAL_LPTIM_STATE_BUSY;
\r
268 /* Get the LPTIMx CFGR value */
\r
269 tmpcfgr = hlptim->Instance->CFGR;
\r
271 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
\r
273 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
\r
275 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
277 tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
\r
280 /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
\r
281 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
\r
282 LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE ));
\r
284 /* Set initialization parameters */
\r
285 tmpcfgr |= (hlptim->Init.Clock.Source |
\r
286 hlptim->Init.Clock.Prescaler |
\r
287 hlptim->Init.OutputPolarity |
\r
288 hlptim->Init.UpdateMode |
\r
289 hlptim->Init.CounterSource);
\r
291 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
\r
293 tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
\r
294 hlptim->Init.UltraLowPowerClock.SampleTime);
\r
297 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
299 /* Enable External trigger and set the trigger source */
\r
300 tmpcfgr |= (hlptim->Init.Trigger.Source |
\r
301 hlptim->Init.Trigger.ActiveEdge |
\r
302 hlptim->Init.Trigger.SampleTime);
\r
305 /* Write to LPTIMx CFGR */
\r
306 hlptim->Instance->CFGR = tmpcfgr;
\r
308 /* Change the LPTIM state */
\r
309 hlptim->State = HAL_LPTIM_STATE_READY;
\r
311 /* Return function status */
\r
316 * @brief DeInitializes the LPTIM peripheral.
\r
317 * @param hlptim: LPTIM handle
\r
318 * @retval HAL status
\r
320 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
\r
322 /* Check the LPTIM handle allocation */
\r
328 /* Change the LPTIM state */
\r
329 hlptim->State = HAL_LPTIM_STATE_BUSY;
\r
331 /* Disable the LPTIM Peripheral Clock */
\r
332 __HAL_LPTIM_DISABLE(hlptim);
\r
334 /* DeInit the low level hardware: CLOCK, NVIC.*/
\r
335 HAL_LPTIM_MspDeInit(hlptim);
\r
337 /* Change the LPTIM state */
\r
338 hlptim->State = HAL_LPTIM_STATE_RESET;
\r
341 __HAL_UNLOCK(hlptim);
\r
343 /* Return function status */
\r
348 * @brief Initializes the LPTIM MSP.
\r
349 * @param hlptim: LPTIM handle
\r
352 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
\r
354 /* NOTE : This function Should not be modified, when the callback is needed,
\r
355 the HAL_LPTIM_MspInit could be implemented in the user file
\r
360 * @brief DeInitializes LPTIM MSP.
\r
361 * @param hlptim: LPTIM handle
\r
364 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
\r
366 /* NOTE : This function Should not be modified, when the callback is needed,
\r
367 the HAL_LPTIM_MspDeInit could be implemented in the user file
\r
375 /** @defgroup LPTIM_Group2 LPTIM Start-Stop operation functions
\r
376 * @brief Start-Stop operation functions.
\r
379 ==============================================================================
\r
380 ##### LPTIM Start Stop operation functions #####
\r
381 ==============================================================================
\r
382 [..] This section provides functions allowing to:
\r
383 (+) Start the PWM mode.
\r
384 (+) Stop the PWM mode.
\r
385 (+) Start the One pulse mode.
\r
386 (+) Stop the One pulse mode.
\r
387 (+) Start the Set once mode.
\r
388 (+) Stop the Set once mode.
\r
389 (+) Start the Encoder mode.
\r
390 (+) Stop the Encoder mode.
\r
391 (+) Start the Timeout mode.
\r
392 (+) Stop the Timeout mode.
\r
393 (+) Start the Counter mode.
\r
394 (+) Stop the Counter mode.
\r
402 * @brief Starts the LPTIM PWM generation.
\r
403 * @param hlptim : LPTIM handle
\r
404 * @param Period : Specifies the Autoreload value.
\r
405 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
406 * @param Pulse : Specifies the compare value.
\r
407 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
408 * @retval HAL status
\r
410 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
412 /* Check the parameters */
\r
413 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
414 assert_param(IS_LPTIM_PERIOD(Period));
\r
415 assert_param(IS_LPTIM_PULSE(Pulse));
\r
417 /* Set the LPTIM state */
\r
418 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
420 /* Reset WAVE bit to set PWM mode */
\r
421 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
\r
423 /* Enable the Peripheral */
\r
424 __HAL_LPTIM_ENABLE(hlptim);
\r
426 /* Load the period value in the autoreload register */
\r
427 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
429 /* Load the pulse value in the compare register */
\r
430 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
432 /* Start timer in continuous mode */
\r
433 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
435 /* Change the TIM state*/
\r
436 hlptim->State= HAL_LPTIM_STATE_READY;
\r
438 /* Return function status */
\r
443 * @brief Stops the LPTIM PWM generation.
\r
444 * @param hlptim : LPTIM handle
\r
445 * @retval HAL status
\r
447 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
\r
449 /* Check the parameters */
\r
450 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
452 /* Set the LPTIM state */
\r
453 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
455 /* Disable the Peripheral */
\r
456 __HAL_LPTIM_DISABLE(hlptim);
\r
458 /* Change the TIM state*/
\r
459 hlptim->State= HAL_LPTIM_STATE_READY;
\r
461 /* Return function status */
\r
466 * @brief Starts the LPTIM PWM generation in interrupt mode.
\r
467 * @param hlptim : LPTIM handle
\r
468 * @param Period : Specifies the Autoreload value.
\r
469 * This parameter must be a value between 0x0000 and 0xFFFF
\r
470 * @param Pulse : Specifies the compare value.
\r
471 * This parameter must be a value between 0x0000 and 0xFFFF
\r
472 * @retval HAL status
\r
474 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
476 /* Check the parameters */
\r
477 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
478 assert_param(IS_LPTIM_PERIOD(Period));
\r
479 assert_param(IS_LPTIM_PULSE(Pulse));
\r
481 /* Set the LPTIM state */
\r
482 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
484 /* Reset WAVE bit to set PWM mode */
\r
485 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
\r
487 /* Enable Autoreload write complete interrupt */
\r
488 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
490 /* Enable Compare write complete interrupt */
\r
491 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
493 /* Enable Autoreload match interrupt */
\r
494 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
496 /* Enable Compare match interrupt */
\r
497 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
499 /* If external trigger source is used, then enable external trigger interrupt */
\r
500 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
502 /* Enable external trigger interrupt */
\r
503 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
506 /* Enable the Peripheral */
\r
507 __HAL_LPTIM_ENABLE(hlptim);
\r
509 /* Load the period value in the autoreload register */
\r
510 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
512 /* Load the pulse value in the compare register */
\r
513 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
515 /* Start timer in continuous mode */
\r
516 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
518 /* Change the TIM state*/
\r
519 hlptim->State= HAL_LPTIM_STATE_READY;
\r
521 /* Return function status */
\r
526 * @brief Stops the LPTIM PWM generation in interrupt mode.
\r
527 * @param hlptim : LPTIM handle
\r
528 * @retval HAL status
\r
530 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
532 /* Check the parameters */
\r
533 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
535 /* Set the LPTIM state */
\r
536 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
538 /* Disable the Peripheral */
\r
539 __HAL_LPTIM_DISABLE(hlptim);
\r
541 /* Disable Autoreload write complete interrupt */
\r
542 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
544 /* Disable Compare write complete interrupt */
\r
545 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
547 /* Disable Autoreload match interrupt */
\r
548 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
550 /* Disable Compare match interrupt */
\r
551 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
553 /* If external trigger source is used, then disable external trigger interrupt */
\r
554 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
556 /* Disable external trigger interrupt */
\r
557 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
560 /* Change the TIM state*/
\r
561 hlptim->State= HAL_LPTIM_STATE_READY;
\r
563 /* Return function status */
\r
568 * @brief Starts the LPTIM One pulse generation.
\r
569 * @param hlptim : LPTIM handle
\r
570 * @param Period : Specifies the Autoreload value.
\r
571 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
572 * @param Pulse : Specifies the compare value.
\r
573 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
574 * @retval HAL status
\r
576 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
578 /* Check the parameters */
\r
579 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
580 assert_param(IS_LPTIM_PERIOD(Period));
\r
581 assert_param(IS_LPTIM_PULSE(Pulse));
\r
583 /* Set the LPTIM state */
\r
584 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
586 /* Reset WAVE bit to set one pulse mode */
\r
587 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
\r
589 /* Enable the Peripheral */
\r
590 __HAL_LPTIM_ENABLE(hlptim);
\r
592 /* Load the period value in the autoreload register */
\r
593 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
595 /* Load the pulse value in the compare register */
\r
596 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
598 /* Start timer in continuous mode */
\r
599 __HAL_LPTIM_START_SINGLE(hlptim);
\r
601 /* Change the TIM state*/
\r
602 hlptim->State= HAL_LPTIM_STATE_READY;
\r
604 /* Return function status */
\r
609 * @brief Stops the LPTIM One pulse generation.
\r
610 * @param hlptim : LPTIM handle
\r
611 * @retval HAL status
\r
613 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
\r
615 /* Check the parameters */
\r
616 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
618 /* Set the LPTIM state */
\r
619 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
621 /* Disable the Peripheral */
\r
622 __HAL_LPTIM_DISABLE(hlptim);
\r
624 /* Change the TIM state*/
\r
625 hlptim->State= HAL_LPTIM_STATE_READY;
\r
627 /* Return function status */
\r
632 * @brief Starts the LPTIM One pulse generation in interrupt mode.
\r
633 * @param hlptim : LPTIM handle
\r
634 * @param Period : Specifies the Autoreload value.
\r
635 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
636 * @param Pulse : Specifies the compare value.
\r
637 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
638 * @retval HAL status
\r
640 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
642 /* Check the parameters */
\r
643 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
644 assert_param(IS_LPTIM_PERIOD(Period));
\r
645 assert_param(IS_LPTIM_PULSE(Pulse));
\r
647 /* Set the LPTIM state */
\r
648 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
650 /* Reset WAVE bit to set one pulse mode */
\r
651 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
\r
653 /* Enable Autoreload write complete interrupt */
\r
654 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
656 /* Enable Compare write complete interrupt */
\r
657 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
659 /* Enable Autoreload match interrupt */
\r
660 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
662 /* Enable Compare match interrupt */
\r
663 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
665 /* If external trigger source is used, then enable external trigger interrupt */
\r
666 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
668 /* Enable external trigger interrupt */
\r
669 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
672 /* Enable the Peripheral */
\r
673 __HAL_LPTIM_ENABLE(hlptim);
\r
675 /* Load the period value in the autoreload register */
\r
676 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
678 /* Load the pulse value in the compare register */
\r
679 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
681 /* Start timer in continuous mode */
\r
682 __HAL_LPTIM_START_SINGLE(hlptim);
\r
684 /* Change the TIM state*/
\r
685 hlptim->State= HAL_LPTIM_STATE_READY;
\r
687 /* Return function status */
\r
692 * @brief Stops the LPTIM One pulse generation in interrupt mode.
\r
693 * @param hlptim : LPTIM handle
\r
694 * @retval HAL status
\r
696 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
698 /* Check the parameters */
\r
699 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
701 /* Set the LPTIM state */
\r
702 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
704 /* Disable the Peripheral */
\r
705 __HAL_LPTIM_DISABLE(hlptim);
\r
707 /* Disable Autoreload write complete interrupt */
\r
708 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
710 /* Disable Compare write complete interrupt */
\r
711 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
713 /* Disable Autoreload match interrupt */
\r
714 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
716 /* Disable Compare match interrupt */
\r
717 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
719 /* If external trigger source is used, then disable external trigger interrupt */
\r
720 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
722 /* Disable external trigger interrupt */
\r
723 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
726 /* Change the TIM state*/
\r
727 hlptim->State= HAL_LPTIM_STATE_READY;
\r
729 /* Return function status */
\r
734 * @brief Starts the LPTIM in Set once mode.
\r
735 * @param hlptim : LPTIM handle
\r
736 * @param Period : Specifies the Autoreload value.
\r
737 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
738 * @param Pulse : Specifies the compare value.
\r
739 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
740 * @retval HAL status
\r
742 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
744 /* Check the parameters */
\r
745 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
746 assert_param(IS_LPTIM_PERIOD(Period));
\r
747 assert_param(IS_LPTIM_PULSE(Pulse));
\r
749 /* Set the LPTIM state */
\r
750 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
752 /* Set WAVE bit to enable the set once mode */
\r
753 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
\r
755 /* Enable the Peripheral */
\r
756 __HAL_LPTIM_ENABLE(hlptim);
\r
758 /* Load the period value in the autoreload register */
\r
759 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
761 /* Load the pulse value in the compare register */
\r
762 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
764 /* Start timer in continuous mode */
\r
765 __HAL_LPTIM_START_SINGLE(hlptim);
\r
767 /* Change the TIM state*/
\r
768 hlptim->State= HAL_LPTIM_STATE_READY;
\r
770 /* Return function status */
\r
775 * @brief Stops the LPTIM Set once mode.
\r
776 * @param hlptim : LPTIM handle
\r
777 * @retval HAL status
\r
779 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
\r
781 /* Check the parameters */
\r
782 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
784 /* Set the LPTIM state */
\r
785 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
787 /* Disable the Peripheral */
\r
788 __HAL_LPTIM_DISABLE(hlptim);
\r
790 /* Change the TIM state*/
\r
791 hlptim->State= HAL_LPTIM_STATE_READY;
\r
793 /* Return function status */
\r
798 * @brief Starts the LPTIM Set once mode in interrupt mode.
\r
799 * @param hlptim : LPTIM handle
\r
800 * @param Period : Specifies the Autoreload value.
\r
801 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
802 * @param Pulse : Specifies the compare value.
\r
803 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
804 * @retval HAL status
\r
806 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
808 /* Check the parameters */
\r
809 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
810 assert_param(IS_LPTIM_PERIOD(Period));
\r
811 assert_param(IS_LPTIM_PULSE(Pulse));
\r
813 /* Set the LPTIM state */
\r
814 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
816 /* Set WAVE bit to enable the set once mode */
\r
817 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
\r
819 /* Enable Autoreload write complete interrupt */
\r
820 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
822 /* Enable Compare write complete interrupt */
\r
823 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
825 /* Enable Autoreload match interrupt */
\r
826 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
828 /* Enable Compare match interrupt */
\r
829 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
831 /* If external trigger source is used, then enable external trigger interrupt */
\r
832 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
834 /* Enable external trigger interrupt */
\r
835 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
838 /* Enable the Peripheral */
\r
839 __HAL_LPTIM_ENABLE(hlptim);
\r
841 /* Load the period value in the autoreload register */
\r
842 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
844 /* Load the pulse value in the compare register */
\r
845 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
847 /* Start timer in continuous mode */
\r
848 __HAL_LPTIM_START_SINGLE(hlptim);
\r
850 /* Change the TIM state*/
\r
851 hlptim->State= HAL_LPTIM_STATE_READY;
\r
853 /* Return function status */
\r
858 * @brief Stops the LPTIM Set once mode in interrupt mode.
\r
859 * @param hlptim : LPTIM handle
\r
860 * @retval HAL status
\r
862 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
864 /* Check the parameters */
\r
865 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
867 /* Set the LPTIM state */
\r
868 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
870 /* Disable the Peripheral */
\r
871 __HAL_LPTIM_DISABLE(hlptim);
\r
873 /* Disable Autoreload write complete interrupt */
\r
874 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
876 /* Disable Compare write complete interrupt */
\r
877 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
879 /* Disable Autoreload match interrupt */
\r
880 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
882 /* Disable Compare match interrupt */
\r
883 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
885 /* If external trigger source is used, then disable external trigger interrupt */
\r
886 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
888 /* Disable external trigger interrupt */
\r
889 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
892 /* Change the TIM state*/
\r
893 hlptim->State= HAL_LPTIM_STATE_READY;
\r
895 /* Return function status */
\r
900 * @brief Starts the Encoder interface.
\r
901 * @param hlptim : LPTIM handle
\r
902 * @param Period : Specifies the Autoreload value.
\r
903 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
904 * @retval HAL status
\r
906 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
\r
908 uint32_t tmpcfgr = 0;
\r
910 /* Check the parameters */
\r
911 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
912 assert_param(IS_LPTIM_PERIOD(Period));
\r
913 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
\r
914 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
\r
915 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
\r
917 /* Set the LPTIM state */
\r
918 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
920 /* Get the LPTIMx CFGR value */
\r
921 tmpcfgr = hlptim->Instance->CFGR;
\r
923 /* Clear CKPOL bits */
\r
924 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
\r
926 /* Set Input polarity */
\r
927 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
\r
929 /* Write to LPTIMx CFGR */
\r
930 hlptim->Instance->CFGR = tmpcfgr;
\r
932 /* Set ENC bit to enable the encoder interface */
\r
933 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
\r
935 /* Enable the Peripheral */
\r
936 __HAL_LPTIM_ENABLE(hlptim);
\r
938 /* Load the period value in the autoreload register */
\r
939 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
941 /* Start timer in continuous mode */
\r
942 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
944 /* Change the TIM state*/
\r
945 hlptim->State= HAL_LPTIM_STATE_READY;
\r
947 /* Return function status */
\r
952 * @brief Stops the Encoder interface.
\r
953 * @param hlptim : LPTIM handle
\r
954 * @retval HAL status
\r
956 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
\r
958 /* Check the parameters */
\r
959 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
961 /* Set the LPTIM state */
\r
962 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
964 /* Disable the Peripheral */
\r
965 __HAL_LPTIM_DISABLE(hlptim);
\r
967 /* Reset ENC bit to disable the encoder interface */
\r
968 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
\r
970 /* Change the TIM state*/
\r
971 hlptim->State= HAL_LPTIM_STATE_READY;
\r
973 /* Return function status */
\r
978 * @brief Starts the Encoder interface in interrupt mode.
\r
979 * @param hlptim : LPTIM handle
\r
980 * @param Period : Specifies the Autoreload value.
\r
981 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
982 * @retval HAL status
\r
984 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
\r
986 uint32_t tmpcfgr = 0;
\r
988 /* Check the parameters */
\r
989 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
990 assert_param(IS_LPTIM_PERIOD(Period));
\r
991 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
\r
992 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
\r
993 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
\r
995 /* Set the LPTIM state */
\r
996 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
998 /* Configure edge sensitivity for encoder mode */
\r
999 /* Get the LPTIMx CFGR value */
\r
1000 tmpcfgr = hlptim->Instance->CFGR;
\r
1002 /* Clear CKPOL bits */
\r
1003 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
\r
1005 /* Set Input polarity */
\r
1006 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
\r
1008 /* Write to LPTIMx CFGR */
\r
1009 hlptim->Instance->CFGR = tmpcfgr;
\r
1011 /* Set ENC bit to enable the encoder interface */
\r
1012 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
\r
1014 /* Enable "switch to down direction" interrupt */
\r
1015 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
\r
1017 /* Enable "switch to up direction" interrupt */
\r
1018 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
\r
1020 /* Enable the Peripheral */
\r
1021 __HAL_LPTIM_ENABLE(hlptim);
\r
1023 /* Load the period value in the autoreload register */
\r
1024 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1026 /* Start timer in continuous mode */
\r
1027 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1029 /* Change the TIM state*/
\r
1030 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1032 /* Return function status */
\r
1037 * @brief Stops the Encoder interface in interrupt mode.
\r
1038 * @param hlptim : LPTIM handle
\r
1039 * @retval HAL status
\r
1041 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
1043 /* Check the parameters */
\r
1044 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1046 /* Set the LPTIM state */
\r
1047 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1049 /* Disable the Peripheral */
\r
1050 __HAL_LPTIM_DISABLE(hlptim);
\r
1052 /* Reset ENC bit to disable the encoder interface */
\r
1053 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
\r
1055 /* Disable "switch to down direction" interrupt */
\r
1056 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
\r
1058 /* Disable "switch to up direction" interrupt */
\r
1059 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
\r
1061 /* Change the TIM state*/
\r
1062 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1064 /* Return function status */
\r
1069 * @brief Starts the Timeout function. The first trigger event will start the
\r
1070 * timer, any successive trigger event will reset the counter and
\r
1071 * the timer restarts.
\r
1072 * @param hlptim : LPTIM handle
\r
1073 * @param Period : Specifies the Autoreload value.
\r
1074 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1075 * @param Timeout : Specifies the TimeOut value to rest the counter.
\r
1076 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1077 * @retval HAL status
\r
1079 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
\r
1081 /* Check the parameters */
\r
1082 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1083 assert_param(IS_LPTIM_PERIOD(Period));
\r
1084 assert_param(IS_LPTIM_PULSE(Timeout));
\r
1086 /* Set the LPTIM state */
\r
1087 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1089 /* Set TIMOUT bit to enable the timeout function */
\r
1090 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
\r
1092 /* Enable the Peripheral */
\r
1093 __HAL_LPTIM_ENABLE(hlptim);
\r
1095 /* Load the period value in the autoreload register */
\r
1096 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1098 /* Load the Timeout value in the compare register */
\r
1099 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
\r
1101 /* Start timer in continuous mode */
\r
1102 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1104 /* Change the TIM state*/
\r
1105 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1107 /* Return function status */
\r
1112 * @brief Stops the Timeout function.
\r
1113 * @param hlptim : LPTIM handle
\r
1114 * @retval HAL status
\r
1116 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
\r
1118 /* Check the parameters */
\r
1119 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1121 /* Set the LPTIM state */
\r
1122 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1124 /* Disable the Peripheral */
\r
1125 __HAL_LPTIM_DISABLE(hlptim);
\r
1127 /* Reset TIMOUT bit to enable the timeout function */
\r
1128 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
\r
1130 /* Change the TIM state*/
\r
1131 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1133 /* Return function status */
\r
1138 * @brief Starts the Timeout function in interrupt mode. The first trigger
\r
1139 * event will start the timer, any successive trigger event will reset
\r
1140 * the counter and the timer restarts.
\r
1141 * @param hlptim : LPTIM handle
\r
1142 * @param Period : Specifies the Autoreload value.
\r
1143 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1144 * @param Timeout : Specifies the TimeOut value to rest the counter.
\r
1145 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1146 * @retval HAL status
\r
1148 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
\r
1150 /* Check the parameters */
\r
1151 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1152 assert_param(IS_LPTIM_PERIOD(Period));
\r
1153 assert_param(IS_LPTIM_PULSE(Timeout));
\r
1155 /* Set the LPTIM state */
\r
1156 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1158 /* Set TIMOUT bit to enable the timeout function */
\r
1159 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
\r
1161 /* Enable Compare match interrupt */
\r
1162 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
1164 /* Enable the Peripheral */
\r
1165 __HAL_LPTIM_ENABLE(hlptim);
\r
1167 /* Load the period value in the autoreload register */
\r
1168 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1170 /* Load the Timeout value in the compare register */
\r
1171 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
\r
1173 /* Start timer in continuous mode */
\r
1174 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1176 /* Change the TIM state*/
\r
1177 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1179 /* Return function status */
\r
1184 * @brief Stops the Timeout function in interrupt mode.
\r
1185 * @param hlptim : LPTIM handle
\r
1186 * @retval HAL status
\r
1188 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
1190 /* Check the parameters */
\r
1191 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1193 /* Set the LPTIM state */
\r
1194 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1196 /* Disable the Peripheral */
\r
1197 __HAL_LPTIM_DISABLE(hlptim);
\r
1199 /* Reset TIMOUT bit to enable the timeout function */
\r
1200 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
\r
1202 /* Disable Compare match interrupt */
\r
1203 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
1205 /* Change the TIM state*/
\r
1206 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1208 /* Return function status */
\r
1213 * @brief Starts the Counter mode.
\r
1214 * @param hlptim : LPTIM handle
\r
1215 * @param Period : Specifies the Autoreload value.
\r
1216 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1217 * @retval HAL status
\r
1219 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
\r
1221 /* Check the parameters */
\r
1222 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1223 assert_param(IS_LPTIM_PERIOD(Period));
\r
1225 /* Set the LPTIM state */
\r
1226 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1228 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
\r
1229 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
\r
1231 /* Check if clock is prescaled */
\r
1232 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
\r
1233 /* Set clock prescaler to 0 */
\r
1234 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
\r
1237 /* Enable the Peripheral */
\r
1238 __HAL_LPTIM_ENABLE(hlptim);
\r
1240 /* Load the period value in the autoreload register */
\r
1241 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1243 /* Start timer in continuous mode */
\r
1244 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1246 /* Change the TIM state*/
\r
1247 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1249 /* Return function status */
\r
1254 * @brief Stops the Counter mode.
\r
1255 * @param hlptim : LPTIM handle
\r
1256 * @retval HAL status
\r
1258 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
\r
1260 /* Check the parameters */
\r
1261 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1263 /* Set the LPTIM state */
\r
1264 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1266 /* Disable the Peripheral */
\r
1267 __HAL_LPTIM_DISABLE(hlptim);
\r
1269 /* Change the TIM state*/
\r
1270 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1272 /* Return function status */
\r
1277 * @brief Starts the Counter mode in interrupt mode.
\r
1278 * @param hlptim : LPTIM handle
\r
1279 * @param Period : Specifies the Autoreload value.
\r
1280 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1281 * @retval HAL status
\r
1283 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
\r
1285 /* Check the parameters */
\r
1286 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1287 assert_param(IS_LPTIM_PERIOD(Period));
\r
1289 /* Set the LPTIM state */
\r
1290 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1292 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
\r
1293 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
\r
1295 /* Check if clock is prescaled */
\r
1296 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
\r
1297 /* Set clock prescaler to 0 */
\r
1298 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
\r
1301 /* Enable Autoreload write complete interrupt */
\r
1302 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
1304 /* Enable Autoreload match interrupt */
\r
1305 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
1307 /* Enable the Peripheral */
\r
1308 __HAL_LPTIM_ENABLE(hlptim);
\r
1310 /* Load the period value in the autoreload register */
\r
1311 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1313 /* Start timer in continuous mode */
\r
1314 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1316 /* Change the TIM state*/
\r
1317 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1319 /* Return function status */
\r
1324 * @brief Stops the Counter mode in interrupt mode.
\r
1325 * @param hlptim : LPTIM handle
\r
1326 * @retval HAL status
\r
1328 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
1330 /* Check the parameters */
\r
1331 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1333 /* Set the LPTIM state */
\r
1334 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1336 /* Disable the Peripheral */
\r
1337 __HAL_LPTIM_DISABLE(hlptim);
\r
1339 /* Disable Autoreload write complete interrupt */
\r
1340 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
1342 /* Disable Autoreload match interrupt */
\r
1343 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
1345 /* Change the TIM state*/
\r
1346 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1348 /* Return function status */
\r
1356 /** @defgroup LPTIM_Group3 LPTIM Read operation functions
\r
1357 * @brief Read operation functions.
\r
1360 ==============================================================================
\r
1361 ##### LPTIM Read operation functions #####
\r
1362 ==============================================================================
\r
1363 [..] This section provides LPTIM Reading functions.
\r
1364 (+) Read the counter value.
\r
1365 (+) Read the period (Auto-reload) value.
\r
1366 (+) Read the pulse (Compare)value.
\r
1372 * @brief This function returns the current counter value.
\r
1373 * @param hlptim: LPTIM handle
\r
1374 * @retval Counter value.
\r
1376 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
\r
1378 /* Check the parameters */
\r
1379 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1381 return (hlptim->Instance->CNT);
\r
1385 * @brief This function return the current Autoreload (Period) value.
\r
1386 * @param hlptim: LPTIM handle
\r
1387 * @retval Autoreload value.
\r
1389 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
\r
1391 /* Check the parameters */
\r
1392 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1394 return (hlptim->Instance->ARR);
\r
1398 * @brief This function return the current Compare (Pulse) value.
\r
1399 * @param hlptim: LPTIM handle
\r
1400 * @retval Compare value.
\r
1402 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
\r
1404 /* Check the parameters */
\r
1405 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1407 return (hlptim->Instance->CMP);
\r
1416 /** @defgroup LPTIM_Group4 LPTIM IRQ handler
\r
1417 * @brief LPTIM IRQ handler.
\r
1420 ==============================================================================
\r
1421 ##### LPTIM IRQ handler #####
\r
1422 ==============================================================================
\r
1423 [..] This section provides LPTIM IRQ handler function.
\r
1430 * @brief This function handles LPTIM interrupt request.
\r
1431 * @param hlptim: LPTIM handle
\r
1434 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
\r
1436 /* Compare match interrupt */
\r
1437 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
\r
1439 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) !=RESET)
\r
1441 /* Clear Compare match flag */
\r
1442 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
\r
1443 /* Compare match Callback */
\r
1444 HAL_LPTIM_CompareMatchCallback(hlptim);
\r
1448 /* Autoreload match interrupt */
\r
1449 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
\r
1451 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) !=RESET)
\r
1453 /* Clear Autoreload match flag */
\r
1454 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
\r
1455 /* Autoreload match Callback */
\r
1456 HAL_LPTIM_AutoReloadMatchCallback(hlptim);
\r
1460 /* Trigger detected interrupt */
\r
1461 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
\r
1463 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) !=RESET)
\r
1465 /* Clear Trigger detected flag */
\r
1466 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
\r
1467 /* Trigger detected callback */
\r
1468 HAL_LPTIM_TriggerCallback(hlptim);
\r
1472 /* Compare write interrupt */
\r
1473 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
\r
1475 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_FLAG_CMPM) !=RESET)
\r
1477 /* Clear Compare write flag */
\r
1478 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
\r
1479 /* Compare write Callback */
\r
1480 HAL_LPTIM_CompareWriteCallback(hlptim);
\r
1484 /* Autoreload write interrupt */
\r
1485 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
\r
1487 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) !=RESET)
\r
1489 /* Clear Autoreload write flag */
\r
1490 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
\r
1491 /* Autoreload write Callback */
\r
1492 HAL_LPTIM_AutoReloadWriteCallback(hlptim);
\r
1496 /* Direction counter changed from Down to Up interrupt */
\r
1497 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
\r
1499 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) !=RESET)
\r
1501 /* Clear Direction counter changed from Down to Up flag */
\r
1502 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
\r
1503 /* Direction counter changed from Down to Up Callback */
\r
1504 HAL_LPTIM_DirectionUpCallback(hlptim);
\r
1508 /* Direction counter changed from Up to Down interrupt */
\r
1509 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
\r
1511 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) !=RESET)
\r
1513 /* Clear Direction counter changed from Up to Down flag */
\r
1514 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
\r
1515 /* Direction counter changed from Up to Down Callback */
\r
1516 HAL_LPTIM_DirectionDownCallback(hlptim);
\r
1522 * @brief Compare match callback in non blocking mode
\r
1523 * @param hlptim : LPTIM handle
\r
1526 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
\r
1528 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1529 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
\r
1534 * @brief Autoreload match callback in non blocking mode
\r
1535 * @param hlptim : LPTIM handle
\r
1538 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
\r
1540 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1541 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
\r
1546 * @brief Trigger detected callback in non blocking mode
\r
1547 * @param hlptim : LPTIM handle
\r
1550 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
\r
1552 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1553 the HAL_LPTIM_TriggerCallback could be implemented in the user file
\r
1558 * @brief Compare write callback in non blocking mode
\r
1559 * @param hlptim : LPTIM handle
\r
1562 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
\r
1564 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1565 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
\r
1570 * @brief Autoreload write callback in non blocking mode
\r
1571 * @param hlptim : LPTIM handle
\r
1574 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
\r
1576 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1577 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
\r
1582 * @brief Direction counter changed from Down to Up callback in non blocking mode
\r
1583 * @param hlptim : LPTIM handle
\r
1586 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
\r
1588 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1589 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
\r
1594 * @brief Direction counter changed from Up to Down callback in non blocking mode
\r
1595 * @param hlptim : LPTIM handle
\r
1598 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
\r
1600 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1601 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
\r
1609 /** @defgroup LPTIM_Group5 Peripheral State functions
\r
1610 * @brief Peripheral State functions.
\r
1613 ==============================================================================
\r
1614 ##### Peripheral State functions #####
\r
1615 ==============================================================================
\r
1617 This subsection permits to get in run-time the status of the peripheral.
\r
1624 * @brief Returns the LPTIM state.
\r
1625 * @param hlptim: LPTIM handle
\r
1626 * @retval HAL state
\r
1628 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
\r
1630 return hlptim->State;
\r
1642 #endif /* HAL_LPTIM_MODULE_ENABLED */
\r
1651 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r