2 ******************************************************************************
3 * @file stm32l0xx_hal_lptim.c
4 * @author MCD Application Team
6 * @date 06-February-2015
7 * @brief LPTIM HAL module driver.
9 * This file provides firmware functions to manage the following
10 * functionalities of the Low Power Timer (LPTIM) peripheral:
11 * + Initialization and de-initialization functions.
12 * + Start/Stop operation functions in polling mode.
13 * + Start/Stop operation functions in interrupt mode.
14 * + Reading operation functions.
15 * + Peripheral State functions.
18 ==============================================================================
19 ##### How to use this driver #####
20 ==============================================================================
22 The LPTIM HAL driver can be used as follows:
24 (#)Initialize the LPTIM low level resources by implementing the
26 (##) Enable the LPTIM interface clock using __HAL_RCC_LPTIM1_CLK_ENABLE().
27 (##) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
28 (+) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
29 (+) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
30 (+) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
32 (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
34 (##) The instance: Only LPTIM1 is present in STM32L053xx.
35 (##) Clock: the counter clock.
36 - Source : it can be either the ULPTIM input (IN1) or one of
37 the internal clock; (APB, LSE, LSI or MSI).
38 - Prescaler: select the clock divider.
39 (##) UltraLowPowerClock : To be used only if the ULPTIM is selected
40 as counter clock source.
41 - Polarity: polarity of the active edge for the counter unit
42 if the ULPTIM input is selected.
43 - SampleTime: clock sampling time to configure the clock glitch
45 (##) Trigger: How the counter start.
46 - Source: trigger can be software or one of the hardware triggers.
47 - ActiveEdge : only for hardware trigger.
48 - SampleTime : trigger sampling time to configure the trigger
50 (##) OutputPolarity : 2 opposite polarities are possibles.
51 (##) UpdateMode: specifies whether the update of the autoreload and
52 the compare values is done immediately or after the end of current
55 (#)Six modes are available:
57 (##) PWM Mode: To generate a PWM signal with specified period and pulse,
58 call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
61 (##) One Pulse Mode: To generate pulse with specified width in response
62 to a stimulus, call HAL_LPTIM_OnePulse_Start() or
63 HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
65 (##) Set once Mode: In this mode, the output changes the level (from
66 low level to high level if the output polarity is configured high, else
67 the opposite) when a compare match occurs. To start this mode, call
68 HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
71 (##) Encoder Mode: To use the encoder interface call
72 HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
75 (##) Time out Mode: an active edge on one selected trigger input rests
76 the counter. The first trigger event will start the timer, any
77 successive trigger event will reset the counter and the timer will
78 restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or
79 HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
81 (##) Counter Mode: counter can be used to count external events on
82 the LPTIM Input1 or it can be used to count internal clock cycles.
83 To start this mode, call HAL_LPTIM_Counter_Start() or
84 HAL_LPTIM_Counter_Start_IT() for interruption mode.
87 (#) User can stop any process by calling the corresponding API:
88 HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
89 already started in interruption mode.
91 (#)Call HAL_LPTIM_DeInit() to deinitialize the LPTIM peripheral.
94 ******************************************************************************
97 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
99 * Redistribution and use in source and binary forms, with or without modification,
100 * are permitted provided that the following conditions are met:
101 * 1. Redistributions of source code must retain the above copyright notice,
102 * this list of conditions and the following disclaimer.
103 * 2. Redistributions in binary form must reproduce the above copyright notice,
104 * this list of conditions and the following disclaimer in the documentation
105 * and/or other materials provided with the distribution.
106 * 3. Neither the name of STMicroelectronics nor the names of its contributors
107 * may be used to endorse or promote products derived from this software
108 * without specific prior written permission.
110 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
111 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
113 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
114 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
115 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
116 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
117 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
118 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
119 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
121 ******************************************************************************
124 /* Includes ------------------------------------------------------------------*/
125 #include "stm32l0xx_hal.h"
127 /** @addtogroup STM32L0xx_HAL_Driver
131 /** @addtogroup LPTIM
132 * @brief LPTIM HAL module driver.
136 #ifdef HAL_LPTIM_MODULE_ENABLED
138 /** @addtogroup LPTIM_Exported_Functions
142 /** @addtogroup LPTIM_Exported_Functions_Group1
143 * @brief Initialization and Configuration functions.
146 ==============================================================================
147 ##### Initialization and de-initialization functions #####
148 ==============================================================================
149 [..] This section provides functions allowing to:
150 (+) Initialize the LPTIM according to the specified parameters in the
151 LPTIM_InitTypeDef and creates the associated handle.
152 (+) DeInitialize the LPTIM peripheral.
153 (+) Initialize the LPTIM MSP.
154 (+) DeInitialize LPTIM MSP.
161 * @brief Initializes the LPTIM according to the specified parameters in the
162 * LPTIM_InitTypeDef and creates the associated handle.
163 * @param hlptim : LPTIM handle
166 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
168 uint32_t tmpcfgr = 0;
170 /* Check the LPTIM handle allocation */
176 /* Check the parameters */
177 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
179 assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
180 assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));
181 if((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
183 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
184 assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
186 assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
187 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
189 assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
190 assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
192 assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));
193 assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
194 assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
196 if(hlptim->State == HAL_LPTIM_STATE_RESET)
198 /* Init the low level hardware */
199 HAL_LPTIM_MspInit(hlptim);
202 /* Change the LPTIM state */
203 hlptim->State = HAL_LPTIM_STATE_BUSY;
205 /* Get the LPTIMx CFGR value */
206 tmpcfgr = hlptim->Instance->CFGR;
208 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
210 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
212 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
214 tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
217 /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
218 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
219 LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE ));
221 /* Set initialization parameters */
222 tmpcfgr |= (hlptim->Init.Clock.Source |
223 hlptim->Init.Clock.Prescaler |
224 hlptim->Init.OutputPolarity |
225 hlptim->Init.UpdateMode |
226 hlptim->Init.CounterSource);
228 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
230 tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
231 hlptim->Init.UltraLowPowerClock.SampleTime);
234 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
236 /* Enable External trigger and set the trigger source */
237 tmpcfgr |= (hlptim->Init.Trigger.Source |
238 hlptim->Init.Trigger.ActiveEdge |
239 hlptim->Init.Trigger.SampleTime);
242 /* Write to LPTIMx CFGR */
243 hlptim->Instance->CFGR = tmpcfgr;
245 /* Change the LPTIM state */
246 hlptim->State = HAL_LPTIM_STATE_READY;
248 /* Return function status */
253 * @brief DeInitializes the LPTIM peripheral.
254 * @param hlptim : LPTIM handle
257 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
259 /* Check the LPTIM handle allocation */
265 /* Change the LPTIM state */
266 hlptim->State = HAL_LPTIM_STATE_BUSY;
268 /* Disable the LPTIM Peripheral Clock */
269 __HAL_LPTIM_DISABLE(hlptim);
271 /* DeInit the low level hardware: CLOCK, NVIC.*/
272 HAL_LPTIM_MspDeInit(hlptim);
274 /* Change the LPTIM state */
275 hlptim->State = HAL_LPTIM_STATE_RESET;
278 __HAL_UNLOCK(hlptim);
280 /* Return function status */
285 * @brief Initializes the LPTIM MSP.
286 * @param hlptim : LPTIM handle
289 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
291 /* NOTE : This function Should not be modified, when the callback is needed,
292 the HAL_LPTIM_MspInit could be implemented in the user file
297 * @brief DeInitializes LPTIM MSP.
298 * @param hlptim : LPTIM handle
301 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
303 /* NOTE : This function Should not be modified, when the callback is needed,
304 the HAL_LPTIM_MspDeInit could be implemented in the user file
312 /** @addtogroup LPTIM_Exported_Functions_Group2
313 * @brief Start-Stop operation functions.
316 ==============================================================================
317 ##### LPTIM Start Stop operation functions #####
318 ==============================================================================
319 [..] This section provides functions allowing to:
320 (+) Start the PWM mode.
321 (+) Stop the PWM mode.
322 (+) Start the One pulse mode.
323 (+) Stop the One pulse mode.
324 (+) Start the Set once mode.
325 (+) Stop the Set once mode.
326 (+) Start the Encoder mode.
327 (+) Stop the Encoder mode.
328 (+) Start the Timeout mode.
329 (+) Stop the Timeout mode.
330 (+) Start the Counter mode.
331 (+) Stop the Counter mode.
339 * @brief Starts the LPTIM PWM generation.
340 * @param hlptim : LPTIM handle
341 * @param Period : Specifies the Autoreload value.
342 * This parameter must be a value between 0x0000 and 0xFFFF.
343 * @param Pulse : Specifies the compare value.
344 * This parameter must be a value between 0x0000 and 0xFFFF.
347 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
349 /* Check the parameters */
350 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
351 assert_param(IS_LPTIM_PERIOD(Period));
352 assert_param(IS_LPTIM_PULSE(Pulse));
354 /* Set the LPTIM state */
355 hlptim->State= HAL_LPTIM_STATE_BUSY;
357 /* Reset WAVE bit to set PWM mode */
358 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
360 /* Enable the Peripheral */
361 __HAL_LPTIM_ENABLE(hlptim);
363 /* Load the period value in the autoreload register */
364 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
366 /* Load the pulse value in the compare register */
367 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
369 /* Start timer in continuous mode */
370 __HAL_LPTIM_START_CONTINUOUS(hlptim);
372 /* Change the TIM state*/
373 hlptim->State= HAL_LPTIM_STATE_READY;
375 /* Return function status */
380 * @brief Stops the LPTIM PWM generation.
381 * @param hlptim : LPTIM handle
384 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
386 /* Check the parameters */
387 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
389 /* Set the LPTIM state */
390 hlptim->State= HAL_LPTIM_STATE_BUSY;
392 /* Disable the Peripheral */
393 __HAL_LPTIM_DISABLE(hlptim);
395 /* Change the TIM state*/
396 hlptim->State= HAL_LPTIM_STATE_READY;
398 /* Return function status */
403 * @brief Starts the LPTIM PWM generation in interrupt mode.
404 * @param hlptim : LPTIM handle
405 * @param Period : Specifies the Autoreload value.
406 * This parameter must be a value between 0x0000 and 0xFFFF
407 * @param Pulse : Specifies the compare value.
408 * This parameter must be a value between 0x0000 and 0xFFFF
411 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
413 /* Check the parameters */
414 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
415 assert_param(IS_LPTIM_PERIOD(Period));
416 assert_param(IS_LPTIM_PULSE(Pulse));
418 /* Set the LPTIM state */
419 hlptim->State= HAL_LPTIM_STATE_BUSY;
421 /* Reset WAVE bit to set PWM mode */
422 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
424 /* Enable Autoreload write complete interrupt */
425 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
427 /* Enable Compare write complete interrupt */
428 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
430 /* Enable Autoreload match interrupt */
431 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
433 /* Enable Compare match interrupt */
434 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
436 /* If external trigger source is used, then enable external trigger interrupt */
437 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
439 /* Enable external trigger interrupt */
440 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
443 /* Enable the Peripheral */
444 __HAL_LPTIM_ENABLE(hlptim);
446 /* Load the period value in the autoreload register */
447 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
449 /* Load the pulse value in the compare register */
450 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
452 /* Start timer in continuous mode */
453 __HAL_LPTIM_START_CONTINUOUS(hlptim);
455 /* Change the TIM state*/
456 hlptim->State= HAL_LPTIM_STATE_READY;
458 /* Return function status */
463 * @brief Stops the LPTIM PWM generation in interrupt mode.
464 * @param hlptim : LPTIM handle
467 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
469 /* Check the parameters */
470 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
472 /* Set the LPTIM state */
473 hlptim->State= HAL_LPTIM_STATE_BUSY;
475 /* Disable the Peripheral */
476 __HAL_LPTIM_DISABLE(hlptim);
478 /* Disable Autoreload write complete interrupt */
479 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
481 /* Disable Compare write complete interrupt */
482 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
484 /* Disable Autoreload match interrupt */
485 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
487 /* Disable Compare match interrupt */
488 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
490 /* If external trigger source is used, then disable external trigger interrupt */
491 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
493 /* Disable external trigger interrupt */
494 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
497 /* Change the TIM state*/
498 hlptim->State= HAL_LPTIM_STATE_READY;
500 /* Return function status */
505 * @brief Starts the LPTIM One pulse generation.
506 * @param hlptim : LPTIM handle
507 * @param Period : Specifies the Autoreload value.
508 * This parameter must be a value between 0x0000 and 0xFFFF.
509 * @param Pulse : Specifies the compare value.
510 * This parameter must be a value between 0x0000 and 0xFFFF.
513 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
515 /* Check the parameters */
516 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
517 assert_param(IS_LPTIM_PERIOD(Period));
518 assert_param(IS_LPTIM_PULSE(Pulse));
520 /* Set the LPTIM state */
521 hlptim->State= HAL_LPTIM_STATE_BUSY;
523 /* Reset WAVE bit to set one pulse mode */
524 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
526 /* Enable the Peripheral */
527 __HAL_LPTIM_ENABLE(hlptim);
529 /* Load the period value in the autoreload register */
530 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
532 /* Load the pulse value in the compare register */
533 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
535 /* Start timer in single mode */
536 __HAL_LPTIM_START_SINGLE(hlptim);
538 /* Change the TIM state*/
539 hlptim->State= HAL_LPTIM_STATE_READY;
541 /* Return function status */
546 * @brief Stops the LPTIM One pulse generation.
547 * @param hlptim : LPTIM handle
550 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
552 /* Check the parameters */
553 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
555 /* Set the LPTIM state */
556 hlptim->State= HAL_LPTIM_STATE_BUSY;
558 /* Disable the Peripheral */
559 __HAL_LPTIM_DISABLE(hlptim);
561 /* Change the TIM state*/
562 hlptim->State= HAL_LPTIM_STATE_READY;
564 /* Return function status */
569 * @brief Starts the LPTIM One pulse generation in interrupt mode.
570 * @param hlptim : LPTIM handle
571 * @param Period : Specifies the Autoreload value.
572 * This parameter must be a value between 0x0000 and 0xFFFF.
573 * @param Pulse : Specifies the compare value.
574 * This parameter must be a value between 0x0000 and 0xFFFF.
577 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
579 /* Check the parameters */
580 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
581 assert_param(IS_LPTIM_PERIOD(Period));
582 assert_param(IS_LPTIM_PULSE(Pulse));
584 /* Set the LPTIM state */
585 hlptim->State= HAL_LPTIM_STATE_BUSY;
587 /* Reset WAVE bit to set one pulse mode */
588 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
590 /* Enable Autoreload write complete interrupt */
591 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
593 /* Enable Compare write complete interrupt */
594 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
596 /* Enable Autoreload match interrupt */
597 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
599 /* Enable Compare match interrupt */
600 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
602 /* If external trigger source is used, then enable external trigger interrupt */
603 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
605 /* Enable external trigger interrupt */
606 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
609 /* Enable the Peripheral */
610 __HAL_LPTIM_ENABLE(hlptim);
612 /* Load the period value in the autoreload register */
613 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
615 /* Load the pulse value in the compare register */
616 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
618 /* Start timer in continuous mode */
619 __HAL_LPTIM_START_SINGLE(hlptim);
621 /* Change the TIM state*/
622 hlptim->State= HAL_LPTIM_STATE_READY;
624 /* Return function status */
629 * @brief Stops the LPTIM One pulse generation in interrupt mode.
630 * @param hlptim : LPTIM handle
633 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
635 /* Check the parameters */
636 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
638 /* Set the LPTIM state */
639 hlptim->State= HAL_LPTIM_STATE_BUSY;
641 /* Disable the Peripheral */
642 __HAL_LPTIM_DISABLE(hlptim);
644 /* Disable Autoreload write complete interrupt */
645 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
647 /* Disable Compare write complete interrupt */
648 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
650 /* Disable Autoreload match interrupt */
651 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
653 /* Disable Compare match interrupt */
654 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
656 /* If external trigger source is used, then disable external trigger interrupt */
657 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
659 /* Disable external trigger interrupt */
660 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
663 /* Change the TIM state*/
664 hlptim->State= HAL_LPTIM_STATE_READY;
666 /* Return function status */
671 * @brief Starts the LPTIM in Set once mode.
672 * @param hlptim : LPTIM handle
673 * @param Period : Specifies the Autoreload value.
674 * This parameter must be a value between 0x0000 and 0xFFFF.
675 * @param Pulse : Specifies the compare value.
676 * This parameter must be a value between 0x0000 and 0xFFFF.
679 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
681 /* Check the parameters */
682 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
683 assert_param(IS_LPTIM_PERIOD(Period));
684 assert_param(IS_LPTIM_PULSE(Pulse));
686 /* Set the LPTIM state */
687 hlptim->State= HAL_LPTIM_STATE_BUSY;
689 /* Set WAVE bit to enable the set once mode */
690 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
692 /* Enable the Peripheral */
693 __HAL_LPTIM_ENABLE(hlptim);
695 /* Load the period value in the autoreload register */
696 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
698 /* Load the pulse value in the compare register */
699 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
701 /* Start timer in continuous mode */
702 __HAL_LPTIM_START_SINGLE(hlptim);
704 /* Change the TIM state*/
705 hlptim->State= HAL_LPTIM_STATE_READY;
707 /* Return function status */
712 * @brief Stops the LPTIM Set once mode.
713 * @param hlptim : LPTIM handle
716 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
718 /* Check the parameters */
719 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
721 /* Set the LPTIM state */
722 hlptim->State= HAL_LPTIM_STATE_BUSY;
724 /* Disable the Peripheral */
725 __HAL_LPTIM_DISABLE(hlptim);
727 /* Change the TIM state*/
728 hlptim->State= HAL_LPTIM_STATE_READY;
730 /* Return function status */
735 * @brief Starts the LPTIM Set once mode in interrupt mode.
736 * @param hlptim : LPTIM handle
737 * @param Period : Specifies the Autoreload value.
738 * This parameter must be a value between 0x0000 and 0xFFFF.
739 * @param Pulse : Specifies the compare value.
740 * This parameter must be a value between 0x0000 and 0xFFFF.
743 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
745 /* Check the parameters */
746 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
747 assert_param(IS_LPTIM_PERIOD(Period));
748 assert_param(IS_LPTIM_PULSE(Pulse));
750 /* Set the LPTIM state */
751 hlptim->State= HAL_LPTIM_STATE_BUSY;
753 /* Set WAVE bit to enable the set once mode */
754 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
756 /* Enable Autoreload write complete interrupt */
757 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
759 /* Enable Compare write complete interrupt */
760 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
762 /* Enable Autoreload match interrupt */
763 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
765 /* Enable Compare match interrupt */
766 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
768 /* If external trigger source is used, then enable external trigger interrupt */
769 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
771 /* Enable external trigger interrupt */
772 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
775 /* Enable the Peripheral */
776 __HAL_LPTIM_ENABLE(hlptim);
778 /* Load the period value in the autoreload register */
779 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
781 /* Load the pulse value in the compare register */
782 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
784 /* Start timer in continuous mode */
785 __HAL_LPTIM_START_SINGLE(hlptim);
787 /* Change the TIM state*/
788 hlptim->State= HAL_LPTIM_STATE_READY;
790 /* Return function status */
795 * @brief Stops the LPTIM Set once mode in interrupt mode.
796 * @param hlptim : LPTIM handle
799 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
801 /* Check the parameters */
802 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
804 /* Set the LPTIM state */
805 hlptim->State= HAL_LPTIM_STATE_BUSY;
807 /* Disable the Peripheral */
808 __HAL_LPTIM_DISABLE(hlptim);
810 /* Disable Autoreload write complete interrupt */
811 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
813 /* Disable Compare write complete interrupt */
814 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
816 /* Disable Autoreload match interrupt */
817 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
819 /* Disable Compare match interrupt */
820 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
822 /* If external trigger source is used, then disable external trigger interrupt */
823 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
825 /* Disable external trigger interrupt */
826 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
829 /* Change the TIM state*/
830 hlptim->State= HAL_LPTIM_STATE_READY;
832 /* Return function status */
837 * @brief Starts the Encoder interface.
838 * @param hlptim : LPTIM handle
839 * @param Period : Specifies the Autoreload value.
840 * This parameter must be a value between 0x0000 and 0xFFFF.
843 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
845 uint32_t tmpcfgr = 0;
847 /* Check the parameters */
848 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
849 assert_param(IS_LPTIM_PERIOD(Period));
850 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
851 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
852 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
854 /* Configure edge sensitivity for encoder mode */
855 /* Set the LPTIM state */
856 hlptim->State= HAL_LPTIM_STATE_BUSY;
858 /* Get the LPTIMx CFGR value */
859 tmpcfgr = hlptim->Instance->CFGR;
861 /* Clear CKPOL bits */
862 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
864 /* Set Input polarity */
865 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
867 /* Write to LPTIMx CFGR */
868 hlptim->Instance->CFGR = tmpcfgr;
870 /* Set ENC bit to enable the encoder interface */
871 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
873 /* Enable the Peripheral */
874 __HAL_LPTIM_ENABLE(hlptim);
876 /* Load the period value in the autoreload register */
877 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
879 /* Start timer in continuous mode */
880 __HAL_LPTIM_START_CONTINUOUS(hlptim);
882 /* Change the TIM state*/
883 hlptim->State= HAL_LPTIM_STATE_READY;
885 /* Return function status */
890 * @brief Stops the Encoder interface.
891 * @param hlptim : LPTIM handle
894 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
896 /* Check the parameters */
897 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
899 /* Set the LPTIM state */
900 hlptim->State= HAL_LPTIM_STATE_BUSY;
902 /* Disable the Peripheral */
903 __HAL_LPTIM_DISABLE(hlptim);
905 /* Reset ENC bit to disable the encoder interface */
906 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
908 /* Change the TIM state*/
909 hlptim->State= HAL_LPTIM_STATE_READY;
911 /* Return function status */
916 * @brief Starts the Encoder interface in interrupt mode.
917 * @param hlptim : LPTIM handle
918 * @param Period : Specifies the Autoreload value.
919 * This parameter must be a value between 0x0000 and 0xFFFF.
922 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
924 uint32_t tmpcfgr = 0;
926 /* Check the parameters */
927 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
928 assert_param(IS_LPTIM_PERIOD(Period));
929 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
930 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
931 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
933 /* Set the LPTIM state */
934 hlptim->State= HAL_LPTIM_STATE_BUSY;
936 /* Configure edge sensitivity for encoder mode */
937 /* Get the LPTIMx CFGR value */
938 tmpcfgr = hlptim->Instance->CFGR;
940 /* Clear CKPOL bits */
941 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
943 /* Set Input polarity */
944 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
946 /* Write to LPTIMx CFGR */
947 hlptim->Instance->CFGR = tmpcfgr;
949 /* Set ENC bit to enable the encoder interface */
950 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
952 /* Enable "switch to down direction" interrupt */
953 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
955 /* Enable "switch to up direction" interrupt */
956 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
958 /* Enable the Peripheral */
959 __HAL_LPTIM_ENABLE(hlptim);
961 /* Load the period value in the autoreload register */
962 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
964 /* Start timer in continuous mode */
965 __HAL_LPTIM_START_CONTINUOUS(hlptim);
967 /* Change the TIM state*/
968 hlptim->State= HAL_LPTIM_STATE_READY;
970 /* Return function status */
975 * @brief Stops the Encoder interface in nterrupt mode.
976 * @param hlptim : LPTIM handle
979 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
981 /* Check the parameters */
982 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
984 /* Set the LPTIM state */
985 hlptim->State= HAL_LPTIM_STATE_BUSY;
987 /* Disable the Peripheral */
988 __HAL_LPTIM_DISABLE(hlptim);
990 /* Reset ENC bit to disable the encoder interface */
991 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
993 /* Disable "switch to down direction" interrupt */
994 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
996 /* Disable "switch to up direction" interrupt */
997 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
999 /* Change the TIM state*/
1000 hlptim->State= HAL_LPTIM_STATE_READY;
1002 /* Return function status */
1007 * @brief Starts the Timeout function. The first trigger event will start the
1008 * timer, any successive trigger event will reset the counter and
1009 * the timer restarts.
1010 * @param hlptim : LPTIM handle
1011 * @param Period : Specifies the Autoreload value.
1012 * This parameter must be a value between 0x0000 and 0xFFFF.
1013 * @param Timeout : Specifies the TimeOut value to rest the counter.
1014 * This parameter must be a value between 0x0000 and 0xFFFF.
1015 * @retval HAL status
1017 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
1019 /* Check the parameters */
1020 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1021 assert_param(IS_LPTIM_PERIOD(Period));
1022 assert_param(IS_LPTIM_PULSE(Timeout));
1024 /* Set the LPTIM state */
1025 hlptim->State= HAL_LPTIM_STATE_BUSY;
1027 /* Set TIMOUT bit to enable the timeout function */
1028 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
1030 /* Enable the Peripheral */
1031 __HAL_LPTIM_ENABLE(hlptim);
1033 /* Load the period value in the autoreload register */
1034 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1036 /* Load the Timeout value in the compare register */
1037 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
1039 /* Start timer in continuous mode */
1040 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1042 /* Change the TIM state*/
1043 hlptim->State= HAL_LPTIM_STATE_READY;
1045 /* Return function status */
1050 * @brief Stops the Timeout function.
1051 * @param hlptim : LPTIM handle
1052 * @retval HAL status
1054 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
1056 /* Check the parameters */
1057 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1059 /* Set the LPTIM state */
1060 hlptim->State= HAL_LPTIM_STATE_BUSY;
1062 /* Disable the Peripheral */
1063 __HAL_LPTIM_DISABLE(hlptim);
1065 /* Reset TIMOUT bit to enable the timeout function */
1066 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
1068 /* Change the TIM state*/
1069 hlptim->State= HAL_LPTIM_STATE_READY;
1071 /* Return function status */
1076 * @brief Starts the Timeout function in interrupt mode. The first trigger
1077 * event will start the timer, any successive trigger event will reset
1078 * the counter and the timer restarts.
1079 * @param hlptim : LPTIM handle
1080 * @param Period : Specifies the Autoreload value.
1081 * This parameter must be a value between 0x0000 and 0xFFFF.
1082 * @param Timeout : Specifies the TimeOut value to rest the counter.
1083 * This parameter must be a value between 0x0000 and 0xFFFF.
1084 * @retval HAL status
1086 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
1088 /* Check the parameters */
1089 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1090 assert_param(IS_LPTIM_PERIOD(Period));
1091 assert_param(IS_LPTIM_PULSE(Timeout));
1093 /* Set the LPTIM state */
1094 hlptim->State= HAL_LPTIM_STATE_BUSY;
1096 /* Set TIMOUT bit to enable the timeout function */
1097 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
1099 /* Enable Compare match interrupt */
1100 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
1102 /* Enable the Peripheral */
1103 __HAL_LPTIM_ENABLE(hlptim);
1105 /* Load the period value in the autoreload register */
1106 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1108 /* Load the Timeout value in the compare register */
1109 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
1111 /* Start timer in continuous mode */
1112 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1114 /* Change the TIM state*/
1115 hlptim->State= HAL_LPTIM_STATE_READY;
1117 /* Return function status */
1122 * @brief Stops the Timeout function in interrupt mode.
1123 * @param hlptim : LPTIM handle
1124 * @retval HAL status
1126 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1128 /* Check the parameters */
1129 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1131 /* Set the LPTIM state */
1132 hlptim->State= HAL_LPTIM_STATE_BUSY;
1134 /* Disable the Peripheral */
1135 __HAL_LPTIM_DISABLE(hlptim);
1137 /* Reset TIMOUT bit to enable the timeout function */
1138 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
1140 /* Disable Compare match interrupt */
1141 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
1143 /* Change the TIM state*/
1144 hlptim->State= HAL_LPTIM_STATE_READY;
1146 /* Return function status */
1151 * @brief Starts the Counter mode.
1152 * @param hlptim : LPTIM handle
1153 * @param Period : Specifies the Autoreload value.
1154 * This parameter must be a value between 0x0000 and 0xFFFF.
1155 * @retval HAL status
1157 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1159 /* Check the parameters */
1160 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1161 assert_param(IS_LPTIM_PERIOD(Period));
1163 /* Set the LPTIM state */
1164 hlptim->State= HAL_LPTIM_STATE_BUSY;
1166 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1167 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
1169 /* Check if clock is prescaled */
1170 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
1171 /* Set clock prescaler to 0 */
1172 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
1175 /* Enable the Peripheral */
1176 __HAL_LPTIM_ENABLE(hlptim);
1178 /* Load the period value in the autoreload register */
1179 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1181 /* Start timer in continuous mode */
1182 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1184 /* Change the TIM state*/
1185 hlptim->State= HAL_LPTIM_STATE_READY;
1187 /* Return function status */
1192 * @brief Stops the Counter mode.
1193 * @param hlptim : LPTIM handle
1194 * @retval HAL status
1196 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
1198 /* Check the parameters */
1199 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1201 /* Set the LPTIM state */
1202 hlptim->State= HAL_LPTIM_STATE_BUSY;
1204 /* Disable the Peripheral */
1205 __HAL_LPTIM_DISABLE(hlptim);
1207 /* Change the TIM state*/
1208 hlptim->State= HAL_LPTIM_STATE_READY;
1210 /* Return function status */
1215 * @brief Starts the Counter mode in interrupt mode.
1216 * @param hlptim : LPTIM handle
1217 * @param Period : Specifies the Autoreload value.
1218 * This parameter must be a value between 0x0000 and 0xFFFF.
1219 * @retval HAL status
1221 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1223 /* Check the parameters */
1224 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1225 assert_param(IS_LPTIM_PERIOD(Period));
1227 /* Set the LPTIM state */
1228 hlptim->State= HAL_LPTIM_STATE_BUSY;
1230 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1231 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
1233 /* Check if clock is prescaled */
1234 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
1235 /* Set clock prescaler to 0 */
1236 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
1239 /* Enable Autoreload write complete interrupt */
1240 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
1242 /* Enable Autoreload match interrupt */
1243 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
1245 /* Enable the Peripheral */
1246 __HAL_LPTIM_ENABLE(hlptim);
1248 /* Load the period value in the autoreload register */
1249 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1251 /* Start timer in continuous mode */
1252 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1254 /* Change the TIM state*/
1255 hlptim->State= HAL_LPTIM_STATE_READY;
1257 /* Return function status */
1262 * @brief Stops the Counter mode in interrupt mode.
1263 * @param hlptim : LPTIM handle
1264 * @retval HAL status
1266 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1268 /* Check the parameters */
1269 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1271 /* Set the LPTIM state */
1272 hlptim->State= HAL_LPTIM_STATE_BUSY;
1274 /* Disable the Peripheral */
1275 __HAL_LPTIM_DISABLE(hlptim);
1277 /* Disable Autoreload write complete interrupt */
1278 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
1280 /* Disable Autoreload match interrupt */
1281 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
1283 /* Change the TIM state*/
1284 hlptim->State= HAL_LPTIM_STATE_READY;
1286 /* Return function status */
1294 /** @addtogroup LPTIM_Exported_Functions_Group3
1295 * @brief Read operation functions.
1298 ==============================================================================
1299 ##### LPTIM Read operation functions #####
1300 ==============================================================================
1301 [..] This section provides LPTIM Reading functions.
1302 (+) Read the counter value.
1303 (+) Read the period (Auto-reload) value.
1304 (+) Read the pulse (Compare)value.
1310 * @brief This function returns the current counter value.
1311 * @param hlptim: LPTIM handle
1312 * @retval Counter value.
1314 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
1316 /* Check the parameters */
1317 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1319 return (hlptim->Instance->CNT);
1323 * @brief This function return the current Autoreload (Period) value.
1324 * @param hlptim: LPTIM handle
1325 * @retval Autoreload value.
1327 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
1329 /* Check the parameters */
1330 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1332 return (hlptim->Instance->ARR);
1336 * @brief This function return the current Compare (Pulse) value.
1337 * @param hlptim: LPTIM handle
1338 * @retval Compare value.
1340 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
1342 /* Check the parameters */
1343 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1345 return (hlptim->Instance->CMP);
1354 /** @addtogroup LPTIM_Exported_Functions_Group4
1355 * @brief LPTIM IRQ handler.
1358 ==============================================================================
1359 ##### LPTIM IRQ handler #####
1360 ==============================================================================
1361 [..] This section provides LPTIM IRQ handler function.
1368 * @brief This function handles LPTIM interrupt request.
1369 * @param hlptim: LPTIM handle
1372 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
1374 /* Compare match interrupt */
1375 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
1377 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) !=RESET)
1379 /* Clear Compare match flag */
1380 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
1382 /* Compare match Callback */
1383 HAL_LPTIM_CompareMatchCallback(hlptim);
1387 /* Autoreload match interrupt */
1388 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
1390 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) !=RESET)
1392 /* Clear Autoreload match flag */
1393 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
1395 /* Autoreload match Callback */
1396 HAL_LPTIM_AutoReloadMatchCallback(hlptim);
1400 /* Trigger detected interrupt */
1401 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
1403 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) !=RESET)
1405 /* Clear Trigger detected flag */
1406 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
1408 /* Trigger detected callback */
1409 HAL_LPTIM_TriggerCallback(hlptim);
1413 /* Compare write interrupt */
1414 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
1416 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) !=RESET)
1418 /* Clear Compare write flag */
1419 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
1421 /* Compare write Callback */
1422 HAL_LPTIM_CompareWriteCallback(hlptim);
1426 /* Autoreload write interrupt */
1427 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
1429 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) !=RESET)
1431 /* Clear Autoreload write flag */
1432 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1434 /* Autoreload write Callback */
1435 HAL_LPTIM_AutoReloadWriteCallback(hlptim);
1439 /* Direction counter changed from Down to Up interrupt */
1440 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
1442 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) !=RESET)
1444 /* Clear Direction counter changed from Down to Up flag */
1445 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
1447 /* Direction counter changed from Down to Up Callback */
1448 HAL_LPTIM_DirectionUpCallback(hlptim);
1452 /* Direction counter changed from Up to Down interrupt */
1453 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
1455 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) !=RESET)
1457 /* Clear Direction counter changed from Up to Down flag */
1458 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
1460 /* Direction counter changed from Up to Down Callback */
1461 HAL_LPTIM_DirectionDownCallback(hlptim);
1467 * @brief Compare match callback in non blocking mode
1468 * @param hlptim : LPTIM handle
1471 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
1473 /* NOTE : This function Should not be modified, when the callback is needed,
1474 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
1479 * @brief Autoreload match callback in non blocking mode
1480 * @param hlptim : LPTIM handle
1483 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
1485 /* NOTE : This function Should not be modified, when the callback is needed,
1486 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
1491 * @brief Trigger detected callback in non blocking mode
1492 * @param hlptim : LPTIM handle
1495 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
1497 /* NOTE : This function Should not be modified, when the callback is needed,
1498 the HAL_LPTIM_TriggerCallback could be implemented in the user file
1503 * @brief Compare write callback in non blocking mode
1504 * @param hlptim : LPTIM handle
1507 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
1509 /* NOTE : This function Should not be modified, when the callback is needed,
1510 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
1515 * @brief Autoreload write callback in non blocking mode
1516 * @param hlptim : LPTIM handle
1519 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
1521 /* NOTE : This function Should not be modified, when the callback is needed,
1522 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
1527 * @brief Direction counter changed from Down to Up callback in non blocking mode
1528 * @param hlptim : LPTIM handle
1531 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
1533 /* NOTE : This function Should not be modified, when the callback is needed,
1534 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
1539 * @brief Direction counter changed from Up to Down callback in non blocking mode
1540 * @param hlptim : LPTIM handle
1543 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
1545 /* NOTE : This function Should not be modified, when the callback is needed,
1546 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
1554 /** @addtogroup LPTIM_Exported_Functions_Group5
1555 * @brief Peripheral State functions.
1558 ==============================================================================
1559 ##### Peripheral State functions #####
1560 ==============================================================================
1562 This subsection permits to get in run-time the status of the peripheral.
1569 * @brief Returns the LPTIM state.
1570 * @param hlptim: LPTIM handle
1573 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
1575 return hlptim->State;
1590 #endif /* HAL_LPTIM_MODULE_ENABLED */
1601 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/