2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_lptim.c
\r
4 * @author MCD Application Team
\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 /* Allocate lock resource and initialize it */
\r
262 hlptim->Lock = HAL_UNLOCKED;
\r
263 /* Init the low level hardware */
\r
264 HAL_LPTIM_MspInit(hlptim);
\r
267 /* Change the LPTIM state */
\r
268 hlptim->State = HAL_LPTIM_STATE_BUSY;
\r
270 /* Get the LPTIMx CFGR value */
\r
271 tmpcfgr = hlptim->Instance->CFGR;
\r
273 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
\r
275 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
\r
277 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
279 tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
\r
282 /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
\r
283 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
\r
284 LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE ));
\r
286 /* Set initialization parameters */
\r
287 tmpcfgr |= (hlptim->Init.Clock.Source |
\r
288 hlptim->Init.Clock.Prescaler |
\r
289 hlptim->Init.OutputPolarity |
\r
290 hlptim->Init.UpdateMode |
\r
291 hlptim->Init.CounterSource);
\r
293 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
\r
295 tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
\r
296 hlptim->Init.UltraLowPowerClock.SampleTime);
\r
299 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
301 /* Enable External trigger and set the trigger source */
\r
302 tmpcfgr |= (hlptim->Init.Trigger.Source |
\r
303 hlptim->Init.Trigger.ActiveEdge |
\r
304 hlptim->Init.Trigger.SampleTime);
\r
307 /* Write to LPTIMx CFGR */
\r
308 hlptim->Instance->CFGR = tmpcfgr;
\r
310 /* Change the LPTIM state */
\r
311 hlptim->State = HAL_LPTIM_STATE_READY;
\r
313 /* Return function status */
\r
318 * @brief DeInitializes the LPTIM peripheral.
\r
319 * @param hlptim: LPTIM handle
\r
320 * @retval HAL status
\r
322 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
\r
324 /* Check the LPTIM handle allocation */
\r
330 /* Change the LPTIM state */
\r
331 hlptim->State = HAL_LPTIM_STATE_BUSY;
\r
333 /* Disable the LPTIM Peripheral Clock */
\r
334 __HAL_LPTIM_DISABLE(hlptim);
\r
336 /* DeInit the low level hardware: CLOCK, NVIC.*/
\r
337 HAL_LPTIM_MspDeInit(hlptim);
\r
339 /* Change the LPTIM state */
\r
340 hlptim->State = HAL_LPTIM_STATE_RESET;
\r
343 __HAL_UNLOCK(hlptim);
\r
345 /* Return function status */
\r
350 * @brief Initializes the LPTIM MSP.
\r
351 * @param hlptim: LPTIM handle
\r
354 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
\r
356 /* NOTE : This function Should not be modified, when the callback is needed,
\r
357 the HAL_LPTIM_MspInit could be implemented in the user file
\r
362 * @brief DeInitializes LPTIM MSP.
\r
363 * @param hlptim: LPTIM handle
\r
366 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
\r
368 /* NOTE : This function Should not be modified, when the callback is needed,
\r
369 the HAL_LPTIM_MspDeInit could be implemented in the user file
\r
377 /** @defgroup LPTIM_Group2 LPTIM Start-Stop operation functions
\r
378 * @brief Start-Stop operation functions.
\r
381 ==============================================================================
\r
382 ##### LPTIM Start Stop operation functions #####
\r
383 ==============================================================================
\r
384 [..] This section provides functions allowing to:
\r
385 (+) Start the PWM mode.
\r
386 (+) Stop the PWM mode.
\r
387 (+) Start the One pulse mode.
\r
388 (+) Stop the One pulse mode.
\r
389 (+) Start the Set once mode.
\r
390 (+) Stop the Set once mode.
\r
391 (+) Start the Encoder mode.
\r
392 (+) Stop the Encoder mode.
\r
393 (+) Start the Timeout mode.
\r
394 (+) Stop the Timeout mode.
\r
395 (+) Start the Counter mode.
\r
396 (+) Stop the Counter mode.
\r
404 * @brief Starts the LPTIM PWM generation.
\r
405 * @param hlptim : LPTIM handle
\r
406 * @param Period : Specifies the Autoreload value.
\r
407 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
408 * @param Pulse : Specifies the compare value.
\r
409 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
410 * @retval HAL status
\r
412 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
414 /* Check the parameters */
\r
415 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
416 assert_param(IS_LPTIM_PERIOD(Period));
\r
417 assert_param(IS_LPTIM_PULSE(Pulse));
\r
419 /* Set the LPTIM state */
\r
420 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
422 /* Reset WAVE bit to set PWM mode */
\r
423 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
\r
425 /* Enable the Peripheral */
\r
426 __HAL_LPTIM_ENABLE(hlptim);
\r
428 /* Load the period value in the autoreload register */
\r
429 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
431 /* Load the pulse value in the compare register */
\r
432 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
434 /* Start timer in continuous mode */
\r
435 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
437 /* Change the TIM state*/
\r
438 hlptim->State= HAL_LPTIM_STATE_READY;
\r
440 /* Return function status */
\r
445 * @brief Stops the LPTIM PWM generation.
\r
446 * @param hlptim : LPTIM handle
\r
447 * @retval HAL status
\r
449 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
\r
451 /* Check the parameters */
\r
452 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
454 /* Set the LPTIM state */
\r
455 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
457 /* Disable the Peripheral */
\r
458 __HAL_LPTIM_DISABLE(hlptim);
\r
460 /* Change the TIM state*/
\r
461 hlptim->State= HAL_LPTIM_STATE_READY;
\r
463 /* Return function status */
\r
468 * @brief Starts the LPTIM PWM generation in interrupt mode.
\r
469 * @param hlptim : LPTIM handle
\r
470 * @param Period : Specifies the Autoreload value.
\r
471 * This parameter must be a value between 0x0000 and 0xFFFF
\r
472 * @param Pulse : Specifies the compare value.
\r
473 * This parameter must be a value between 0x0000 and 0xFFFF
\r
474 * @retval HAL status
\r
476 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
478 /* Check the parameters */
\r
479 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
480 assert_param(IS_LPTIM_PERIOD(Period));
\r
481 assert_param(IS_LPTIM_PULSE(Pulse));
\r
483 /* Set the LPTIM state */
\r
484 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
486 /* Reset WAVE bit to set PWM mode */
\r
487 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
\r
489 /* Enable Autoreload write complete interrupt */
\r
490 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
492 /* Enable Compare write complete interrupt */
\r
493 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
495 /* Enable Autoreload match interrupt */
\r
496 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
498 /* Enable Compare match interrupt */
\r
499 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
501 /* If external trigger source is used, then enable external trigger interrupt */
\r
502 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
504 /* Enable external trigger interrupt */
\r
505 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
508 /* Enable the Peripheral */
\r
509 __HAL_LPTIM_ENABLE(hlptim);
\r
511 /* Load the period value in the autoreload register */
\r
512 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
514 /* Load the pulse value in the compare register */
\r
515 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
517 /* Start timer in continuous mode */
\r
518 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
520 /* Change the TIM state*/
\r
521 hlptim->State= HAL_LPTIM_STATE_READY;
\r
523 /* Return function status */
\r
528 * @brief Stops the LPTIM PWM generation in interrupt mode.
\r
529 * @param hlptim : LPTIM handle
\r
530 * @retval HAL status
\r
532 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
534 /* Check the parameters */
\r
535 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
537 /* Set the LPTIM state */
\r
538 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
540 /* Disable the Peripheral */
\r
541 __HAL_LPTIM_DISABLE(hlptim);
\r
543 /* Disable Autoreload write complete interrupt */
\r
544 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
546 /* Disable Compare write complete interrupt */
\r
547 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
549 /* Disable Autoreload match interrupt */
\r
550 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
552 /* Disable Compare match interrupt */
\r
553 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
555 /* If external trigger source is used, then disable external trigger interrupt */
\r
556 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
558 /* Disable external trigger interrupt */
\r
559 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
562 /* Change the TIM state*/
\r
563 hlptim->State= HAL_LPTIM_STATE_READY;
\r
565 /* Return function status */
\r
570 * @brief Starts the LPTIM One pulse generation.
\r
571 * @param hlptim : LPTIM handle
\r
572 * @param Period : Specifies the Autoreload value.
\r
573 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
574 * @param Pulse : Specifies the compare value.
\r
575 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
576 * @retval HAL status
\r
578 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
580 /* Check the parameters */
\r
581 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
582 assert_param(IS_LPTIM_PERIOD(Period));
\r
583 assert_param(IS_LPTIM_PULSE(Pulse));
\r
585 /* Set the LPTIM state */
\r
586 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
588 /* Reset WAVE bit to set one pulse mode */
\r
589 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
\r
591 /* Enable the Peripheral */
\r
592 __HAL_LPTIM_ENABLE(hlptim);
\r
594 /* Load the period value in the autoreload register */
\r
595 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
597 /* Load the pulse value in the compare register */
\r
598 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
600 /* Start timer in continuous mode */
\r
601 __HAL_LPTIM_START_SINGLE(hlptim);
\r
603 /* Change the TIM state*/
\r
604 hlptim->State= HAL_LPTIM_STATE_READY;
\r
606 /* Return function status */
\r
611 * @brief Stops the LPTIM One pulse generation.
\r
612 * @param hlptim : LPTIM handle
\r
613 * @retval HAL status
\r
615 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
\r
617 /* Check the parameters */
\r
618 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
620 /* Set the LPTIM state */
\r
621 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
623 /* Disable the Peripheral */
\r
624 __HAL_LPTIM_DISABLE(hlptim);
\r
626 /* Change the TIM state*/
\r
627 hlptim->State= HAL_LPTIM_STATE_READY;
\r
629 /* Return function status */
\r
634 * @brief Starts the LPTIM One pulse generation in interrupt mode.
\r
635 * @param hlptim : LPTIM handle
\r
636 * @param Period : Specifies the Autoreload value.
\r
637 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
638 * @param Pulse : Specifies the compare value.
\r
639 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
640 * @retval HAL status
\r
642 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
644 /* Check the parameters */
\r
645 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
646 assert_param(IS_LPTIM_PERIOD(Period));
\r
647 assert_param(IS_LPTIM_PULSE(Pulse));
\r
649 /* Set the LPTIM state */
\r
650 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
652 /* Reset WAVE bit to set one pulse mode */
\r
653 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
\r
655 /* Enable Autoreload write complete interrupt */
\r
656 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
658 /* Enable Compare write complete interrupt */
\r
659 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
661 /* Enable Autoreload match interrupt */
\r
662 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
664 /* Enable Compare match interrupt */
\r
665 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
667 /* If external trigger source is used, then enable external trigger interrupt */
\r
668 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
670 /* Enable external trigger interrupt */
\r
671 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
674 /* Enable the Peripheral */
\r
675 __HAL_LPTIM_ENABLE(hlptim);
\r
677 /* Load the period value in the autoreload register */
\r
678 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
680 /* Load the pulse value in the compare register */
\r
681 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
683 /* Start timer in continuous mode */
\r
684 __HAL_LPTIM_START_SINGLE(hlptim);
\r
686 /* Change the TIM state*/
\r
687 hlptim->State= HAL_LPTIM_STATE_READY;
\r
689 /* Return function status */
\r
694 * @brief Stops the LPTIM One pulse generation in interrupt mode.
\r
695 * @param hlptim : LPTIM handle
\r
696 * @retval HAL status
\r
698 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
700 /* Check the parameters */
\r
701 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
703 /* Set the LPTIM state */
\r
704 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
706 /* Disable the Peripheral */
\r
707 __HAL_LPTIM_DISABLE(hlptim);
\r
709 /* Disable Autoreload write complete interrupt */
\r
710 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
712 /* Disable Compare write complete interrupt */
\r
713 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
715 /* Disable Autoreload match interrupt */
\r
716 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
718 /* Disable Compare match interrupt */
\r
719 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
721 /* If external trigger source is used, then disable external trigger interrupt */
\r
722 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
724 /* Disable external trigger interrupt */
\r
725 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
728 /* Change the TIM state*/
\r
729 hlptim->State= HAL_LPTIM_STATE_READY;
\r
731 /* Return function status */
\r
736 * @brief Starts the LPTIM in Set once mode.
\r
737 * @param hlptim : LPTIM handle
\r
738 * @param Period : Specifies the Autoreload value.
\r
739 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
740 * @param Pulse : Specifies the compare value.
\r
741 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
742 * @retval HAL status
\r
744 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
746 /* Check the parameters */
\r
747 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
748 assert_param(IS_LPTIM_PERIOD(Period));
\r
749 assert_param(IS_LPTIM_PULSE(Pulse));
\r
751 /* Set the LPTIM state */
\r
752 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
754 /* Set WAVE bit to enable the set once mode */
\r
755 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
\r
757 /* Enable the Peripheral */
\r
758 __HAL_LPTIM_ENABLE(hlptim);
\r
760 /* Load the period value in the autoreload register */
\r
761 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
763 /* Load the pulse value in the compare register */
\r
764 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
766 /* Start timer in continuous mode */
\r
767 __HAL_LPTIM_START_SINGLE(hlptim);
\r
769 /* Change the TIM state*/
\r
770 hlptim->State= HAL_LPTIM_STATE_READY;
\r
772 /* Return function status */
\r
777 * @brief Stops the LPTIM Set once mode.
\r
778 * @param hlptim : LPTIM handle
\r
779 * @retval HAL status
\r
781 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
\r
783 /* Check the parameters */
\r
784 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
786 /* Set the LPTIM state */
\r
787 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
789 /* Disable the Peripheral */
\r
790 __HAL_LPTIM_DISABLE(hlptim);
\r
792 /* Change the TIM state*/
\r
793 hlptim->State= HAL_LPTIM_STATE_READY;
\r
795 /* Return function status */
\r
800 * @brief Starts the LPTIM Set once mode in interrupt mode.
\r
801 * @param hlptim : LPTIM handle
\r
802 * @param Period : Specifies the Autoreload value.
\r
803 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
804 * @param Pulse : Specifies the compare value.
\r
805 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
806 * @retval HAL status
\r
808 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
\r
810 /* Check the parameters */
\r
811 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
812 assert_param(IS_LPTIM_PERIOD(Period));
\r
813 assert_param(IS_LPTIM_PULSE(Pulse));
\r
815 /* Set the LPTIM state */
\r
816 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
818 /* Set WAVE bit to enable the set once mode */
\r
819 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
\r
821 /* Enable Autoreload write complete interrupt */
\r
822 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
824 /* Enable Compare write complete interrupt */
\r
825 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
827 /* Enable Autoreload match interrupt */
\r
828 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
830 /* Enable Compare match interrupt */
\r
831 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
833 /* If external trigger source is used, then enable external trigger interrupt */
\r
834 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
836 /* Enable external trigger interrupt */
\r
837 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
840 /* Enable the Peripheral */
\r
841 __HAL_LPTIM_ENABLE(hlptim);
\r
843 /* Load the period value in the autoreload register */
\r
844 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
846 /* Load the pulse value in the compare register */
\r
847 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
\r
849 /* Start timer in continuous mode */
\r
850 __HAL_LPTIM_START_SINGLE(hlptim);
\r
852 /* Change the TIM state*/
\r
853 hlptim->State= HAL_LPTIM_STATE_READY;
\r
855 /* Return function status */
\r
860 * @brief Stops the LPTIM Set once mode in interrupt mode.
\r
861 * @param hlptim : LPTIM handle
\r
862 * @retval HAL status
\r
864 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
866 /* Check the parameters */
\r
867 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
869 /* Set the LPTIM state */
\r
870 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
872 /* Disable the Peripheral */
\r
873 __HAL_LPTIM_DISABLE(hlptim);
\r
875 /* Disable Autoreload write complete interrupt */
\r
876 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
878 /* Disable Compare write complete interrupt */
\r
879 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
\r
881 /* Disable Autoreload match interrupt */
\r
882 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
884 /* Disable Compare match interrupt */
\r
885 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
887 /* If external trigger source is used, then disable external trigger interrupt */
\r
888 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
\r
890 /* Disable external trigger interrupt */
\r
891 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
\r
894 /* Change the TIM state*/
\r
895 hlptim->State= HAL_LPTIM_STATE_READY;
\r
897 /* Return function status */
\r
902 * @brief Starts the Encoder interface.
\r
903 * @param hlptim : LPTIM handle
\r
904 * @param Period : Specifies the Autoreload value.
\r
905 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
906 * @retval HAL status
\r
908 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
\r
910 uint32_t tmpcfgr = 0;
\r
912 /* Check the parameters */
\r
913 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
914 assert_param(IS_LPTIM_PERIOD(Period));
\r
915 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
\r
916 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
\r
917 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
\r
919 /* Set the LPTIM state */
\r
920 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
922 /* Get the LPTIMx CFGR value */
\r
923 tmpcfgr = hlptim->Instance->CFGR;
\r
925 /* Clear CKPOL bits */
\r
926 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
\r
928 /* Set Input polarity */
\r
929 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
\r
931 /* Write to LPTIMx CFGR */
\r
932 hlptim->Instance->CFGR = tmpcfgr;
\r
934 /* Set ENC bit to enable the encoder interface */
\r
935 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
\r
937 /* Enable the Peripheral */
\r
938 __HAL_LPTIM_ENABLE(hlptim);
\r
940 /* Load the period value in the autoreload register */
\r
941 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
943 /* Start timer in continuous mode */
\r
944 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
946 /* Change the TIM state*/
\r
947 hlptim->State= HAL_LPTIM_STATE_READY;
\r
949 /* Return function status */
\r
954 * @brief Stops the Encoder interface.
\r
955 * @param hlptim : LPTIM handle
\r
956 * @retval HAL status
\r
958 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
\r
960 /* Check the parameters */
\r
961 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
963 /* Set the LPTIM state */
\r
964 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
966 /* Disable the Peripheral */
\r
967 __HAL_LPTIM_DISABLE(hlptim);
\r
969 /* Reset ENC bit to disable the encoder interface */
\r
970 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
\r
972 /* Change the TIM state*/
\r
973 hlptim->State= HAL_LPTIM_STATE_READY;
\r
975 /* Return function status */
\r
980 * @brief Starts the Encoder interface in interrupt mode.
\r
981 * @param hlptim : LPTIM handle
\r
982 * @param Period : Specifies the Autoreload value.
\r
983 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
984 * @retval HAL status
\r
986 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
\r
988 uint32_t tmpcfgr = 0;
\r
990 /* Check the parameters */
\r
991 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
992 assert_param(IS_LPTIM_PERIOD(Period));
\r
993 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
\r
994 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
\r
995 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
\r
997 /* Set the LPTIM state */
\r
998 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1000 /* Configure edge sensitivity for encoder mode */
\r
1001 /* Get the LPTIMx CFGR value */
\r
1002 tmpcfgr = hlptim->Instance->CFGR;
\r
1004 /* Clear CKPOL bits */
\r
1005 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
\r
1007 /* Set Input polarity */
\r
1008 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
\r
1010 /* Write to LPTIMx CFGR */
\r
1011 hlptim->Instance->CFGR = tmpcfgr;
\r
1013 /* Set ENC bit to enable the encoder interface */
\r
1014 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
\r
1016 /* Enable "switch to down direction" interrupt */
\r
1017 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
\r
1019 /* Enable "switch to up direction" interrupt */
\r
1020 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
\r
1022 /* Enable the Peripheral */
\r
1023 __HAL_LPTIM_ENABLE(hlptim);
\r
1025 /* Load the period value in the autoreload register */
\r
1026 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1028 /* Start timer in continuous mode */
\r
1029 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1031 /* Change the TIM state*/
\r
1032 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1034 /* Return function status */
\r
1039 * @brief Stops the Encoder interface in interrupt mode.
\r
1040 * @param hlptim : LPTIM handle
\r
1041 * @retval HAL status
\r
1043 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
1045 /* Check the parameters */
\r
1046 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1048 /* Set the LPTIM state */
\r
1049 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1051 /* Disable the Peripheral */
\r
1052 __HAL_LPTIM_DISABLE(hlptim);
\r
1054 /* Reset ENC bit to disable the encoder interface */
\r
1055 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
\r
1057 /* Disable "switch to down direction" interrupt */
\r
1058 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
\r
1060 /* Disable "switch to up direction" interrupt */
\r
1061 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
\r
1063 /* Change the TIM state*/
\r
1064 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1066 /* Return function status */
\r
1071 * @brief Starts the Timeout function. The first trigger event will start the
\r
1072 * timer, any successive trigger event will reset the counter and
\r
1073 * the timer restarts.
\r
1074 * @param hlptim : LPTIM handle
\r
1075 * @param Period : Specifies the Autoreload value.
\r
1076 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1077 * @param Timeout : Specifies the TimeOut value to rest the counter.
\r
1078 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1079 * @retval HAL status
\r
1081 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
\r
1083 /* Check the parameters */
\r
1084 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1085 assert_param(IS_LPTIM_PERIOD(Period));
\r
1086 assert_param(IS_LPTIM_PULSE(Timeout));
\r
1088 /* Set the LPTIM state */
\r
1089 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1091 /* Set TIMOUT bit to enable the timeout function */
\r
1092 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
\r
1094 /* Enable the Peripheral */
\r
1095 __HAL_LPTIM_ENABLE(hlptim);
\r
1097 /* Load the period value in the autoreload register */
\r
1098 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1100 /* Load the Timeout value in the compare register */
\r
1101 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
\r
1103 /* Start timer in continuous mode */
\r
1104 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1106 /* Change the TIM state*/
\r
1107 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1109 /* Return function status */
\r
1114 * @brief Stops the Timeout function.
\r
1115 * @param hlptim : LPTIM handle
\r
1116 * @retval HAL status
\r
1118 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
\r
1120 /* Check the parameters */
\r
1121 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1123 /* Set the LPTIM state */
\r
1124 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1126 /* Disable the Peripheral */
\r
1127 __HAL_LPTIM_DISABLE(hlptim);
\r
1129 /* Reset TIMOUT bit to enable the timeout function */
\r
1130 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
\r
1132 /* Change the TIM state*/
\r
1133 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1135 /* Return function status */
\r
1140 * @brief Starts the Timeout function in interrupt mode. The first trigger
\r
1141 * event will start the timer, any successive trigger event will reset
\r
1142 * the counter and the timer restarts.
\r
1143 * @param hlptim : LPTIM handle
\r
1144 * @param Period : Specifies the Autoreload value.
\r
1145 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1146 * @param Timeout : Specifies the TimeOut value to rest the counter.
\r
1147 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1148 * @retval HAL status
\r
1150 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
\r
1152 /* Check the parameters */
\r
1153 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1154 assert_param(IS_LPTIM_PERIOD(Period));
\r
1155 assert_param(IS_LPTIM_PULSE(Timeout));
\r
1157 /* Set the LPTIM state */
\r
1158 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1160 /* Set TIMOUT bit to enable the timeout function */
\r
1161 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
\r
1163 /* Enable Compare match interrupt */
\r
1164 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
1166 /* Enable the Peripheral */
\r
1167 __HAL_LPTIM_ENABLE(hlptim);
\r
1169 /* Load the period value in the autoreload register */
\r
1170 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1172 /* Load the Timeout value in the compare register */
\r
1173 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
\r
1175 /* Start timer in continuous mode */
\r
1176 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1178 /* Change the TIM state*/
\r
1179 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1181 /* Return function status */
\r
1186 * @brief Stops the Timeout function in interrupt mode.
\r
1187 * @param hlptim : LPTIM handle
\r
1188 * @retval HAL status
\r
1190 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
1192 /* Check the parameters */
\r
1193 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1195 /* Set the LPTIM state */
\r
1196 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1198 /* Disable the Peripheral */
\r
1199 __HAL_LPTIM_DISABLE(hlptim);
\r
1201 /* Reset TIMOUT bit to enable the timeout function */
\r
1202 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
\r
1204 /* Disable Compare match interrupt */
\r
1205 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
\r
1207 /* Change the TIM state*/
\r
1208 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1210 /* Return function status */
\r
1215 * @brief Starts the Counter mode.
\r
1216 * @param hlptim : LPTIM handle
\r
1217 * @param Period : Specifies the Autoreload value.
\r
1218 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1219 * @retval HAL status
\r
1221 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
\r
1223 /* Check the parameters */
\r
1224 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1225 assert_param(IS_LPTIM_PERIOD(Period));
\r
1227 /* Set the LPTIM state */
\r
1228 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1230 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
\r
1231 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
\r
1233 /* Check if clock is prescaled */
\r
1234 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
\r
1235 /* Set clock prescaler to 0 */
\r
1236 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
\r
1239 /* Enable the Peripheral */
\r
1240 __HAL_LPTIM_ENABLE(hlptim);
\r
1242 /* Load the period value in the autoreload register */
\r
1243 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1245 /* Start timer in continuous mode */
\r
1246 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1248 /* Change the TIM state*/
\r
1249 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1251 /* Return function status */
\r
1256 * @brief Stops the Counter mode.
\r
1257 * @param hlptim : LPTIM handle
\r
1258 * @retval HAL status
\r
1260 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
\r
1262 /* Check the parameters */
\r
1263 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1265 /* Set the LPTIM state */
\r
1266 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1268 /* Disable the Peripheral */
\r
1269 __HAL_LPTIM_DISABLE(hlptim);
\r
1271 /* Change the TIM state*/
\r
1272 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1274 /* Return function status */
\r
1279 * @brief Starts the Counter mode in interrupt mode.
\r
1280 * @param hlptim : LPTIM handle
\r
1281 * @param Period : Specifies the Autoreload value.
\r
1282 * This parameter must be a value between 0x0000 and 0xFFFF.
\r
1283 * @retval HAL status
\r
1285 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
\r
1287 /* Check the parameters */
\r
1288 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1289 assert_param(IS_LPTIM_PERIOD(Period));
\r
1291 /* Set the LPTIM state */
\r
1292 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1294 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
\r
1295 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
\r
1297 /* Check if clock is prescaled */
\r
1298 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
\r
1299 /* Set clock prescaler to 0 */
\r
1300 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
\r
1303 /* Enable Autoreload write complete interrupt */
\r
1304 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
1306 /* Enable Autoreload match interrupt */
\r
1307 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
1309 /* Enable the Peripheral */
\r
1310 __HAL_LPTIM_ENABLE(hlptim);
\r
1312 /* Load the period value in the autoreload register */
\r
1313 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
\r
1315 /* Start timer in continuous mode */
\r
1316 __HAL_LPTIM_START_CONTINUOUS(hlptim);
\r
1318 /* Change the TIM state*/
\r
1319 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1321 /* Return function status */
\r
1326 * @brief Stops the Counter mode in interrupt mode.
\r
1327 * @param hlptim : LPTIM handle
\r
1328 * @retval HAL status
\r
1330 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
\r
1332 /* Check the parameters */
\r
1333 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1335 /* Set the LPTIM state */
\r
1336 hlptim->State= HAL_LPTIM_STATE_BUSY;
\r
1338 /* Disable the Peripheral */
\r
1339 __HAL_LPTIM_DISABLE(hlptim);
\r
1341 /* Disable Autoreload write complete interrupt */
\r
1342 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
\r
1344 /* Disable Autoreload match interrupt */
\r
1345 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
\r
1347 /* Change the TIM state*/
\r
1348 hlptim->State= HAL_LPTIM_STATE_READY;
\r
1350 /* Return function status */
\r
1358 /** @defgroup LPTIM_Group3 LPTIM Read operation functions
\r
1359 * @brief Read operation functions.
\r
1362 ==============================================================================
\r
1363 ##### LPTIM Read operation functions #####
\r
1364 ==============================================================================
\r
1365 [..] This section provides LPTIM Reading functions.
\r
1366 (+) Read the counter value.
\r
1367 (+) Read the period (Auto-reload) value.
\r
1368 (+) Read the pulse (Compare)value.
\r
1374 * @brief This function returns the current counter value.
\r
1375 * @param hlptim: LPTIM handle
\r
1376 * @retval Counter value.
\r
1378 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
\r
1380 /* Check the parameters */
\r
1381 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1383 return (hlptim->Instance->CNT);
\r
1387 * @brief This function return the current Autoreload (Period) value.
\r
1388 * @param hlptim: LPTIM handle
\r
1389 * @retval Autoreload value.
\r
1391 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
\r
1393 /* Check the parameters */
\r
1394 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1396 return (hlptim->Instance->ARR);
\r
1400 * @brief This function return the current Compare (Pulse) value.
\r
1401 * @param hlptim: LPTIM handle
\r
1402 * @retval Compare value.
\r
1404 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
\r
1406 /* Check the parameters */
\r
1407 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
\r
1409 return (hlptim->Instance->CMP);
\r
1418 /** @defgroup LPTIM_Group4 LPTIM IRQ handler
\r
1419 * @brief LPTIM IRQ handler.
\r
1422 ==============================================================================
\r
1423 ##### LPTIM IRQ handler #####
\r
1424 ==============================================================================
\r
1425 [..] This section provides LPTIM IRQ handler function.
\r
1432 * @brief This function handles LPTIM interrupt request.
\r
1433 * @param hlptim: LPTIM handle
\r
1436 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
\r
1438 /* Compare match interrupt */
\r
1439 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
\r
1441 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) !=RESET)
\r
1443 /* Clear Compare match flag */
\r
1444 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
\r
1445 /* Compare match Callback */
\r
1446 HAL_LPTIM_CompareMatchCallback(hlptim);
\r
1450 /* Autoreload match interrupt */
\r
1451 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
\r
1453 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) !=RESET)
\r
1455 /* Clear Autoreload match flag */
\r
1456 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
\r
1457 /* Autoreload match Callback */
\r
1458 HAL_LPTIM_AutoReloadMatchCallback(hlptim);
\r
1462 /* Trigger detected interrupt */
\r
1463 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
\r
1465 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) !=RESET)
\r
1467 /* Clear Trigger detected flag */
\r
1468 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
\r
1469 /* Trigger detected callback */
\r
1470 HAL_LPTIM_TriggerCallback(hlptim);
\r
1474 /* Compare write interrupt */
\r
1475 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
\r
1477 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_FLAG_CMPM) !=RESET)
\r
1479 /* Clear Compare write flag */
\r
1480 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
\r
1481 /* Compare write Callback */
\r
1482 HAL_LPTIM_CompareWriteCallback(hlptim);
\r
1486 /* Autoreload write interrupt */
\r
1487 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
\r
1489 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) !=RESET)
\r
1491 /* Clear Autoreload write flag */
\r
1492 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
\r
1493 /* Autoreload write Callback */
\r
1494 HAL_LPTIM_AutoReloadWriteCallback(hlptim);
\r
1498 /* Direction counter changed from Down to Up interrupt */
\r
1499 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
\r
1501 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) !=RESET)
\r
1503 /* Clear Direction counter changed from Down to Up flag */
\r
1504 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
\r
1505 /* Direction counter changed from Down to Up Callback */
\r
1506 HAL_LPTIM_DirectionUpCallback(hlptim);
\r
1510 /* Direction counter changed from Up to Down interrupt */
\r
1511 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
\r
1513 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) !=RESET)
\r
1515 /* Clear Direction counter changed from Up to Down flag */
\r
1516 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
\r
1517 /* Direction counter changed from Up to Down Callback */
\r
1518 HAL_LPTIM_DirectionDownCallback(hlptim);
\r
1524 * @brief Compare match callback in non blocking mode
\r
1525 * @param hlptim : LPTIM handle
\r
1528 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
\r
1530 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1531 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
\r
1536 * @brief Autoreload match callback in non blocking mode
\r
1537 * @param hlptim : LPTIM handle
\r
1540 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
\r
1542 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1543 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
\r
1548 * @brief Trigger detected callback in non blocking mode
\r
1549 * @param hlptim : LPTIM handle
\r
1552 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
\r
1554 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1555 the HAL_LPTIM_TriggerCallback could be implemented in the user file
\r
1560 * @brief Compare write callback in non blocking mode
\r
1561 * @param hlptim : LPTIM handle
\r
1564 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
\r
1566 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1567 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
\r
1572 * @brief Autoreload write callback in non blocking mode
\r
1573 * @param hlptim : LPTIM handle
\r
1576 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
\r
1578 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1579 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
\r
1584 * @brief Direction counter changed from Down to Up callback in non blocking mode
\r
1585 * @param hlptim : LPTIM handle
\r
1588 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
\r
1590 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1591 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
\r
1596 * @brief Direction counter changed from Up to Down callback in non blocking mode
\r
1597 * @param hlptim : LPTIM handle
\r
1600 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
\r
1602 /* NOTE : This function Should not be modified, when the callback is needed,
\r
1603 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
\r
1611 /** @defgroup LPTIM_Group5 Peripheral State functions
\r
1612 * @brief Peripheral State functions.
\r
1615 ==============================================================================
\r
1616 ##### Peripheral State functions #####
\r
1617 ==============================================================================
\r
1619 This subsection permits to get in run-time the status of the peripheral.
\r
1626 * @brief Returns the LPTIM state.
\r
1627 * @param hlptim: LPTIM handle
\r
1628 * @retval HAL state
\r
1630 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
\r
1632 return hlptim->State;
\r
1644 #endif /* HAL_LPTIM_MODULE_ENABLED */
\r
1653 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r