Merge pull request #10592 from iNavFlight/MrD_Update-parameter-description
[inav.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_lptim.c
blobb11c521a7ac799dda357db633587dff13d895cd9
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_lptim.c
4 * @author MCD Application Team
5 * @brief LPTIM HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Low Power Timer (LPTIM) peripheral:
8 * + Initialization and de-initialization functions.
9 * + Start/Stop operation functions in polling mode.
10 * + Start/Stop operation functions in interrupt mode.
11 * + Reading operation functions.
12 * + Peripheral State functions.
14 @verbatim
15 ==============================================================================
16 ##### How to use this driver #####
17 ==============================================================================
18 [..]
19 The LPTIM HAL driver can be used as follows:
21 (#)Initialize the LPTIM low level resources by implementing the
22 HAL_LPTIM_MspInit():
23 (++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE().
24 (++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
25 (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
26 (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
27 (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
29 (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
30 configures mainly:
31 (++) The instance: LPTIM1 or LPTIM2.
32 (++) Clock: the counter clock.
33 (+++) Source : it can be either the ULPTIM input (IN1) or one of
34 the internal clock; (APB, LSE, LSI or MSI).
35 (+++) Prescaler: select the clock divider.
36 (++) UltraLowPowerClock : To be used only if the ULPTIM is selected
37 as counter clock source.
38 (+++) Polarity: polarity of the active edge for the counter unit
39 if the ULPTIM input is selected.
40 (+++) SampleTime: clock sampling time to configure the clock glitch
41 filter.
42 (++) Trigger: How the counter start.
43 (+++) Source: trigger can be software or one of the hardware triggers.
44 (+++) ActiveEdge : only for hardware trigger.
45 (+++) SampleTime : trigger sampling time to configure the trigger
46 glitch filter.
47 (++) OutputPolarity : 2 opposite polarities are possible.
48 (++) UpdateMode: specifies whether the update of the autoreload and
49 the compare values is done immediately or after the end of current
50 period.
51 (++) Input1Source: Source selected for input1 (GPIO or comparator output).
52 (++) Input2Source: Source selected for input2 (GPIO or comparator output).
53 Input2 is used only for encoder feature so is used only for LPTIM1 instance.
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
59 mode.
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
69 interruption mode.
71 (++) Encoder Mode: To use the encoder interface call
72 HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
73 interruption mode. Only available for LPTIM1 instance.
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 (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit().
93 *** Callback registration ***
94 =============================================
95 [..]
96 The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1
97 allows the user to configure dynamically the driver callbacks.
98 [..]
99 Use Function @ref HAL_LPTIM_RegisterCallback() to register a callback.
100 @ref HAL_LPTIM_RegisterCallback() takes as parameters the HAL peripheral handle,
101 the Callback ID and a pointer to the user callback function.
102 [..]
103 Use function @ref HAL_LPTIM_UnRegisterCallback() to reset a callback to the
104 default weak function.
105 @ref HAL_LPTIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
106 and the Callback ID.
107 [..]
108 These functions allow to register/unregister following callbacks:
110 (+) MspInitCallback : LPTIM Base Msp Init Callback.
111 (+) MspDeInitCallback : LPTIM Base Msp DeInit Callback.
112 (+) CompareMatchCallback : Compare match Callback.
113 (+) AutoReloadMatchCallback : Auto-reload match Callback.
114 (+) TriggerCallback : External trigger event detection Callback.
115 (+) CompareWriteCallback : Compare register write complete Callback.
116 (+) AutoReloadWriteCallback : Auto-reload register write complete Callback.
117 (+) DirectionUpCallback : Up-counting direction change Callback.
118 (+) DirectionDownCallback : Down-counting direction change Callback.
120 [..]
121 By default, after the Init and when the state is HAL_LPTIM_STATE_RESET
122 all interrupt callbacks are set to the corresponding weak functions:
123 examples @ref HAL_LPTIM_TriggerCallback(), @ref HAL_LPTIM_CompareMatchCallback().
125 [..]
126 Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
127 functionalities in the Init/DeInit only when these callbacks are null
128 (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init/DeInit
129 keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
131 [..]
132 Callbacks can be registered/unregistered in HAL_LPTIM_STATE_READY state only.
133 Exception done MspInit/MspDeInit that can be registered/unregistered
134 in HAL_LPTIM_STATE_READY or HAL_LPTIM_STATE_RESET state,
135 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
136 In that case first register the MspInit/MspDeInit user callbacks
137 using @ref HAL_LPTIM_RegisterCallback() before calling DeInit or Init function.
139 [..]
140 When The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or
141 not defined, the callback registration feature is not available and all callbacks
142 are set to the corresponding weak functions.
144 @endverbatim
145 ******************************************************************************
146 * @attention
148 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
149 * All rights reserved.</center></h2>
151 * This software component is licensed by ST under BSD 3-Clause license,
152 * the "License"; You may not use this file except in compliance with the
153 * License. You may obtain a copy of the License at:
154 * opensource.org/licenses/BSD-3-Clause
156 ******************************************************************************
159 /* Includes ------------------------------------------------------------------*/
160 #include "stm32h7xx_hal.h"
162 /** @addtogroup STM32H7xx_HAL_Driver
163 * @{
166 /** @defgroup LPTIM LPTIM
167 * @brief LPTIM HAL module driver.
168 * @{
171 #ifdef HAL_LPTIM_MODULE_ENABLED
173 #if defined (LPTIM1) || defined (LPTIM2) || defined (LPTIM3) || defined (LPTIM4) || defined (LPTIM5)
175 /* Private typedef -----------------------------------------------------------*/
176 /* Private define ------------------------------------------------------------*/
177 /* Private macro -------------------------------------------------------------*/
178 /** @addtogroup LPTIM_Private_Constants
179 * @{
181 #define TIMEOUT 1000UL /* Timeout is 1s */
183 * @}
186 /* Private variables ---------------------------------------------------------*/
187 /* Private function prototypes -----------------------------------------------*/
188 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
189 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim);
190 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
191 static HAL_StatusTypeDef LPTIM_WaitForFlag(LPTIM_HandleTypeDef *hlptim, uint32_t flag);
193 /* Exported functions --------------------------------------------------------*/
195 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
196 * @{
199 /** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions
200 * @brief Initialization and Configuration functions.
202 @verbatim
203 ==============================================================================
204 ##### Initialization and de-initialization functions #####
205 ==============================================================================
206 [..] This section provides functions allowing to:
207 (+) Initialize the LPTIM according to the specified parameters in the
208 LPTIM_InitTypeDef and initialize the associated handle.
209 (+) DeInitialize the LPTIM peripheral.
210 (+) Initialize the LPTIM MSP.
211 (+) DeInitialize the LPTIM MSP.
213 @endverbatim
214 * @{
218 * @brief Initialize the LPTIM according to the specified parameters in the
219 * LPTIM_InitTypeDef and initialize the associated handle.
220 * @param hlptim LPTIM handle
221 * @retval HAL status
223 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
225 uint32_t tmpcfgr;
227 /* Check the LPTIM handle allocation */
228 if (hlptim == NULL)
230 return HAL_ERROR;
233 /* Check the parameters */
234 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
236 assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
237 assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));
238 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
240 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
241 assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
243 assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
244 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
246 assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
247 assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
249 assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));
250 assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
251 assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
253 if (hlptim->State == HAL_LPTIM_STATE_RESET)
255 /* Allocate lock resource and initialize it */
256 hlptim->Lock = HAL_UNLOCKED;
258 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
259 /* Reset interrupt callbacks to legacy weak callbacks */
260 LPTIM_ResetCallback(hlptim);
262 if (hlptim->MspInitCallback == NULL)
264 hlptim->MspInitCallback = HAL_LPTIM_MspInit;
267 /* Init the low level hardware : GPIO, CLOCK, NVIC */
268 hlptim->MspInitCallback(hlptim);
269 #else
270 /* Init the low level hardware : GPIO, CLOCK, NVIC */
271 HAL_LPTIM_MspInit(hlptim);
272 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
275 /* Change the LPTIM state */
276 hlptim->State = HAL_LPTIM_STATE_BUSY;
278 /* Get the LPTIMx CFGR value */
279 tmpcfgr = hlptim->Instance->CFGR;
281 if (((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM) || ((hlptim->Init.CounterSource) == LPTIM_COUNTERSOURCE_EXTERNAL))
283 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
285 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
287 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
290 /* Clear CKSEL, CKPOL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
291 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_CKPOL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
292 LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE));
294 /* Set initialization parameters */
295 tmpcfgr |= (hlptim->Init.Clock.Source |
296 hlptim->Init.Clock.Prescaler |
297 hlptim->Init.OutputPolarity |
298 hlptim->Init.UpdateMode |
299 hlptim->Init.CounterSource);
301 if (((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM) || ((hlptim->Init.CounterSource) == LPTIM_COUNTERSOURCE_EXTERNAL))
303 tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
304 hlptim->Init.UltraLowPowerClock.SampleTime);
307 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
309 /* Enable External trigger and set the trigger source */
310 tmpcfgr |= (hlptim->Init.Trigger.Source |
311 hlptim->Init.Trigger.ActiveEdge |
312 hlptim->Init.Trigger.SampleTime);
315 /* Write to LPTIMx CFGR */
316 hlptim->Instance->CFGR = tmpcfgr;
318 /* Configure LPTIM input sources */
319 if ((hlptim->Instance == LPTIM1)||(hlptim->Instance == LPTIM2))
321 /* Check LPTIM Input1 and Input2 sources */
322 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance, hlptim->Init.Input1Source));
323 assert_param(IS_LPTIM_INPUT2_SOURCE(hlptim->Instance, hlptim->Init.Input2Source));
325 /* Configure LPTIM Input1 and Input2 sources */
326 hlptim->Instance->CFGR2 = (hlptim->Init.Input1Source | hlptim->Init.Input2Source);
328 else
330 if(hlptim->Instance == LPTIM3)
332 /* Check LPTIM3 Input1 source */
333 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance, hlptim->Init.Input1Source));
335 /* Configure LPTIM3 Input1 source */
336 hlptim->Instance->CFGR2 = hlptim->Init.Input1Source;
340 /* Change the LPTIM state */
341 hlptim->State = HAL_LPTIM_STATE_READY;
343 /* Return function status */
344 return HAL_OK;
348 * @brief DeInitialize the LPTIM peripheral.
349 * @param hlptim LPTIM handle
350 * @retval HAL status
352 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
354 /* Check the LPTIM handle allocation */
355 if (hlptim == NULL)
357 return HAL_ERROR;
360 /* Change the LPTIM state */
361 hlptim->State = HAL_LPTIM_STATE_BUSY;
363 /* Disable the LPTIM Peripheral Clock */
364 __HAL_LPTIM_DISABLE(hlptim);
366 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
368 return HAL_TIMEOUT;
371 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
372 if (hlptim->MspDeInitCallback == NULL)
374 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
377 /* DeInit the low level hardware: CLOCK, NVIC.*/
378 hlptim->MspDeInitCallback(hlptim);
379 #else
380 /* DeInit the low level hardware: CLOCK, NVIC.*/
381 HAL_LPTIM_MspDeInit(hlptim);
382 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
384 /* Change the LPTIM state */
385 hlptim->State = HAL_LPTIM_STATE_RESET;
387 /* Release Lock */
388 __HAL_UNLOCK(hlptim);
390 /* Return function status */
391 return HAL_OK;
395 * @brief Initialize the LPTIM MSP.
396 * @param hlptim LPTIM handle
397 * @retval None
399 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
401 /* Prevent unused argument(s) compilation warning */
402 UNUSED(hlptim);
404 /* NOTE : This function should not be modified, when the callback is needed,
405 the HAL_LPTIM_MspInit could be implemented in the user file
410 * @brief DeInitialize LPTIM MSP.
411 * @param hlptim LPTIM handle
412 * @retval None
414 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
416 /* Prevent unused argument(s) compilation warning */
417 UNUSED(hlptim);
419 /* NOTE : This function should not be modified, when the callback is needed,
420 the HAL_LPTIM_MspDeInit could be implemented in the user file
425 * @}
428 /** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions
429 * @brief Start-Stop operation functions.
431 @verbatim
432 ==============================================================================
433 ##### LPTIM Start Stop operation functions #####
434 ==============================================================================
435 [..] This section provides functions allowing to:
436 (+) Start the PWM mode.
437 (+) Stop the PWM mode.
438 (+) Start the One pulse mode.
439 (+) Stop the One pulse mode.
440 (+) Start the Set once mode.
441 (+) Stop the Set once mode.
442 (+) Start the Encoder mode.
443 (+) Stop the Encoder mode.
444 (+) Start the Timeout mode.
445 (+) Stop the Timeout mode.
446 (+) Start the Counter mode.
447 (+) Stop the Counter mode.
450 @endverbatim
451 * @{
455 * @brief Start the LPTIM PWM generation.
456 * @param hlptim LPTIM handle
457 * @param Period Specifies the Autoreload value.
458 * This parameter must be a value between 0x0000 and 0xFFFF.
459 * @param Pulse Specifies the compare value.
460 * This parameter must be a value between 0x0000 and 0xFFFF.
461 * @retval HAL status
463 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
465 /* Check the parameters */
466 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
467 assert_param(IS_LPTIM_PERIOD(Period));
468 assert_param(IS_LPTIM_PULSE(Pulse));
470 /* Set the LPTIM state */
471 hlptim->State = HAL_LPTIM_STATE_BUSY;
473 /* Reset WAVE bit to set PWM mode */
474 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
476 /* Enable the Peripheral */
477 __HAL_LPTIM_ENABLE(hlptim);
479 /* Clear flag */
480 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
482 /* Load the period value in the autoreload register */
483 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
485 /* Wait for the completion of the write operation to the LPTIM_ARR register */
486 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
488 return HAL_TIMEOUT;
491 /* Clear flag */
492 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
494 /* Load the pulse value in the compare register */
495 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
497 /* Wait for the completion of the write operation to the LPTIM_CMP register */
498 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
500 return HAL_TIMEOUT;
503 /* Start timer in continuous mode */
504 __HAL_LPTIM_START_CONTINUOUS(hlptim);
506 /* Change the TIM state*/
507 hlptim->State = HAL_LPTIM_STATE_READY;
509 /* Return function status */
510 return HAL_OK;
514 * @brief Stop the LPTIM PWM generation.
515 * @param hlptim LPTIM handle
516 * @retval HAL status
518 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
520 /* Check the parameters */
521 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
523 /* Set the LPTIM state */
524 hlptim->State = HAL_LPTIM_STATE_BUSY;
526 /* Disable the Peripheral */
527 __HAL_LPTIM_DISABLE(hlptim);
529 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
531 return HAL_TIMEOUT;
534 /* Change the TIM state*/
535 hlptim->State = HAL_LPTIM_STATE_READY;
537 /* Return function status */
538 return HAL_OK;
542 * @brief Start the LPTIM PWM generation in interrupt mode.
543 * @param hlptim LPTIM handle
544 * @param Period Specifies the Autoreload value.
545 * This parameter must be a value between 0x0000 and 0xFFFF
546 * @param Pulse Specifies the compare value.
547 * This parameter must be a value between 0x0000 and 0xFFFF
548 * @retval HAL status
550 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
552 /* Check the parameters */
553 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
554 assert_param(IS_LPTIM_PERIOD(Period));
555 assert_param(IS_LPTIM_PULSE(Pulse));
557 /* Set the LPTIM state */
558 hlptim->State = HAL_LPTIM_STATE_BUSY;
560 /* Reset WAVE bit to set PWM mode */
561 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
563 /* Enable the Peripheral */
564 __HAL_LPTIM_ENABLE(hlptim);
566 /* Clear flag */
567 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
569 /* Load the period value in the autoreload register */
570 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
572 /* Wait for the completion of the write operation to the LPTIM_ARR register */
573 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
575 return HAL_TIMEOUT;
578 /* Clear flag */
579 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
581 /* Load the pulse value in the compare register */
582 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
584 /* Wait for the completion of the write operation to the LPTIM_CMP register */
585 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
587 return HAL_TIMEOUT;
590 /* Disable the Peripheral */
591 __HAL_LPTIM_DISABLE(hlptim);
593 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
595 return HAL_TIMEOUT;
598 /* Enable Autoreload write complete interrupt */
599 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
601 /* Enable Compare write complete interrupt */
602 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
604 /* Enable Autoreload match interrupt */
605 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
607 /* Enable Compare match interrupt */
608 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
610 /* If external trigger source is used, then enable external trigger interrupt */
611 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
613 /* Enable external trigger interrupt */
614 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
617 /* Enable the Peripheral */
618 __HAL_LPTIM_ENABLE(hlptim);
620 /* Start timer in continuous mode */
621 __HAL_LPTIM_START_CONTINUOUS(hlptim);
623 /* Change the TIM state*/
624 hlptim->State = HAL_LPTIM_STATE_READY;
626 /* Return function status */
627 return HAL_OK;
631 * @brief Stop the LPTIM PWM generation in interrupt mode.
632 * @param hlptim LPTIM handle
633 * @retval HAL status
635 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
637 /* Check the parameters */
638 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
640 /* Set the LPTIM state */
641 hlptim->State = HAL_LPTIM_STATE_BUSY;
643 /* Disable the Peripheral */
644 __HAL_LPTIM_DISABLE(hlptim);
646 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
648 return HAL_TIMEOUT;
651 /* Disable Autoreload write complete interrupt */
652 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
654 /* Disable Compare write complete interrupt */
655 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
657 /* Disable Autoreload match interrupt */
658 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
660 /* Disable Compare match interrupt */
661 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
663 /* If external trigger source is used, then disable external trigger interrupt */
664 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
666 /* Disable external trigger interrupt */
667 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
670 /* Change the TIM state*/
671 hlptim->State = HAL_LPTIM_STATE_READY;
673 /* Return function status */
674 return HAL_OK;
678 * @brief Start the LPTIM One pulse generation.
679 * @param hlptim LPTIM handle
680 * @param Period Specifies the Autoreload value.
681 * This parameter must be a value between 0x0000 and 0xFFFF.
682 * @param Pulse Specifies the compare value.
683 * This parameter must be a value between 0x0000 and 0xFFFF.
684 * @retval HAL status
686 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
688 /* Check the parameters */
689 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
690 assert_param(IS_LPTIM_PERIOD(Period));
691 assert_param(IS_LPTIM_PULSE(Pulse));
693 /* Set the LPTIM state */
694 hlptim->State = HAL_LPTIM_STATE_BUSY;
696 /* Reset WAVE bit to set one pulse mode */
697 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
699 /* Enable the Peripheral */
700 __HAL_LPTIM_ENABLE(hlptim);
702 /* Clear flag */
703 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
705 /* Load the period value in the autoreload register */
706 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
708 /* Wait for the completion of the write operation to the LPTIM_ARR register */
709 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
711 return HAL_TIMEOUT;
714 /* Clear flag */
715 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
717 /* Load the pulse value in the compare register */
718 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
720 /* Wait for the completion of the write operation to the LPTIM_CMP register */
721 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
723 return HAL_TIMEOUT;
726 /* Start timer in single (one shot) mode */
727 __HAL_LPTIM_START_SINGLE(hlptim);
729 /* Change the TIM state*/
730 hlptim->State = HAL_LPTIM_STATE_READY;
732 /* Return function status */
733 return HAL_OK;
737 * @brief Stop the LPTIM One pulse generation.
738 * @param hlptim LPTIM handle
739 * @retval HAL status
741 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
743 /* Check the parameters */
744 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
746 /* Set the LPTIM state */
747 hlptim->State = HAL_LPTIM_STATE_BUSY;
749 /* Disable the Peripheral */
750 __HAL_LPTIM_DISABLE(hlptim);
752 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
754 return HAL_TIMEOUT;
757 /* Change the TIM state*/
758 hlptim->State = HAL_LPTIM_STATE_READY;
760 /* Return function status */
761 return HAL_OK;
765 * @brief Start the LPTIM One pulse generation in interrupt mode.
766 * @param hlptim LPTIM handle
767 * @param Period Specifies the Autoreload value.
768 * This parameter must be a value between 0x0000 and 0xFFFF.
769 * @param Pulse Specifies the compare value.
770 * This parameter must be a value between 0x0000 and 0xFFFF.
771 * @retval HAL status
773 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
775 /* Check the parameters */
776 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
777 assert_param(IS_LPTIM_PERIOD(Period));
778 assert_param(IS_LPTIM_PULSE(Pulse));
780 /* Set the LPTIM state */
781 hlptim->State = HAL_LPTIM_STATE_BUSY;
783 /* Reset WAVE bit to set one pulse mode */
784 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
786 /* Enable the Peripheral */
787 __HAL_LPTIM_ENABLE(hlptim);
789 /* Clear flag */
790 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
792 /* Load the period value in the autoreload register */
793 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
795 /* Wait for the completion of the write operation to the LPTIM_ARR register */
796 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
798 return HAL_TIMEOUT;
801 /* Clear flag */
802 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
804 /* Load the pulse value in the compare register */
805 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
807 /* Wait for the completion of the write operation to the LPTIM_CMP register */
808 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
810 return HAL_TIMEOUT;
813 /* Disable the Peripheral */
814 __HAL_LPTIM_DISABLE(hlptim);
816 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
818 return HAL_TIMEOUT;
821 /* Enable Autoreload write complete interrupt */
822 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
824 /* Enable Compare write complete interrupt */
825 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
827 /* Enable Autoreload match interrupt */
828 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
830 /* Enable Compare match interrupt */
831 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
833 /* If external trigger source is used, then enable external trigger interrupt */
834 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
836 /* Enable external trigger interrupt */
837 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
840 /* Enable the Peripheral */
841 __HAL_LPTIM_ENABLE(hlptim);
843 /* Start timer in single (one shot) mode */
844 __HAL_LPTIM_START_SINGLE(hlptim);
846 /* Change the TIM state*/
847 hlptim->State = HAL_LPTIM_STATE_READY;
849 /* Return function status */
850 return HAL_OK;
854 * @brief Stop the LPTIM One pulse generation in interrupt mode.
855 * @param hlptim LPTIM handle
856 * @retval HAL status
858 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
860 /* Check the parameters */
861 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
863 /* Set the LPTIM state */
864 hlptim->State = HAL_LPTIM_STATE_BUSY;
866 /* Disable the Peripheral */
867 __HAL_LPTIM_DISABLE(hlptim);
869 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
871 return HAL_TIMEOUT;
874 /* Disable Autoreload write complete interrupt */
875 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
877 /* Disable Compare write complete interrupt */
878 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
880 /* Disable Autoreload match interrupt */
881 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
883 /* Disable Compare match interrupt */
884 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
886 /* If external trigger source is used, then disable external trigger interrupt */
887 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
889 /* Disable external trigger interrupt */
890 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
893 /* Change the TIM state*/
894 hlptim->State = HAL_LPTIM_STATE_READY;
896 /* Return function status */
897 return HAL_OK;
901 * @brief Start the LPTIM in Set once mode.
902 * @param hlptim LPTIM handle
903 * @param Period Specifies the Autoreload value.
904 * This parameter must be a value between 0x0000 and 0xFFFF.
905 * @param Pulse Specifies the compare value.
906 * This parameter must be a value between 0x0000 and 0xFFFF.
907 * @retval HAL status
909 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
911 /* Check the parameters */
912 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
913 assert_param(IS_LPTIM_PERIOD(Period));
914 assert_param(IS_LPTIM_PULSE(Pulse));
916 /* Set the LPTIM state */
917 hlptim->State = HAL_LPTIM_STATE_BUSY;
919 /* Set WAVE bit to enable the set once mode */
920 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
922 /* Enable the Peripheral */
923 __HAL_LPTIM_ENABLE(hlptim);
925 /* Clear flag */
926 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
928 /* Load the period value in the autoreload register */
929 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
931 /* Wait for the completion of the write operation to the LPTIM_ARR register */
932 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
934 return HAL_TIMEOUT;
937 /* Clear flag */
938 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
940 /* Load the pulse value in the compare register */
941 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
943 /* Wait for the completion of the write operation to the LPTIM_CMP register */
944 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
946 return HAL_TIMEOUT;
949 /* Start timer in single (one shot) mode */
950 __HAL_LPTIM_START_SINGLE(hlptim);
952 /* Change the TIM state*/
953 hlptim->State = HAL_LPTIM_STATE_READY;
955 /* Return function status */
956 return HAL_OK;
960 * @brief Stop the LPTIM Set once mode.
961 * @param hlptim LPTIM handle
962 * @retval HAL status
964 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
966 /* Check the parameters */
967 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
969 /* Set the LPTIM state */
970 hlptim->State = HAL_LPTIM_STATE_BUSY;
972 /* Disable the Peripheral */
973 __HAL_LPTIM_DISABLE(hlptim);
975 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
977 return HAL_TIMEOUT;
980 /* Change the TIM state*/
981 hlptim->State = HAL_LPTIM_STATE_READY;
983 /* Return function status */
984 return HAL_OK;
988 * @brief Start the LPTIM Set once mode in interrupt mode.
989 * @param hlptim LPTIM handle
990 * @param Period Specifies the Autoreload value.
991 * This parameter must be a value between 0x0000 and 0xFFFF.
992 * @param Pulse Specifies the compare value.
993 * This parameter must be a value between 0x0000 and 0xFFFF.
994 * @retval HAL status
996 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
998 /* Check the parameters */
999 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1000 assert_param(IS_LPTIM_PERIOD(Period));
1001 assert_param(IS_LPTIM_PULSE(Pulse));
1003 /* Set the LPTIM state */
1004 hlptim->State = HAL_LPTIM_STATE_BUSY;
1006 /* Set WAVE bit to enable the set once mode */
1007 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
1009 /* Enable the Peripheral */
1010 __HAL_LPTIM_ENABLE(hlptim);
1012 /* Clear flag */
1013 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1015 /* Load the period value in the autoreload register */
1016 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1018 /* Wait for the completion of the write operation to the LPTIM_ARR register */
1019 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
1021 return HAL_TIMEOUT;
1024 /* Clear flag */
1025 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
1027 /* Load the pulse value in the compare register */
1028 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
1030 /* Wait for the completion of the write operation to the LPTIM_CMP register */
1031 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
1033 return HAL_TIMEOUT;
1036 /* Disable the Peripheral */
1037 __HAL_LPTIM_DISABLE(hlptim);
1039 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1041 return HAL_TIMEOUT;
1044 /* Enable Autoreload write complete interrupt */
1045 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
1047 /* Enable Compare write complete interrupt */
1048 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
1050 /* Enable Autoreload match interrupt */
1051 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
1053 /* Enable Compare match interrupt */
1054 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
1056 /* If external trigger source is used, then enable external trigger interrupt */
1057 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
1059 /* Enable external trigger interrupt */
1060 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
1063 /* Enable the Peripheral */
1064 __HAL_LPTIM_ENABLE(hlptim);
1066 /* Start timer in single (one shot) mode */
1067 __HAL_LPTIM_START_SINGLE(hlptim);
1069 /* Change the TIM state*/
1070 hlptim->State = HAL_LPTIM_STATE_READY;
1072 /* Return function status */
1073 return HAL_OK;
1077 * @brief Stop the LPTIM Set once mode in interrupt mode.
1078 * @param hlptim LPTIM handle
1079 * @retval HAL status
1081 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1083 /* Check the parameters */
1084 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1086 /* Set the LPTIM state */
1087 hlptim->State = HAL_LPTIM_STATE_BUSY;
1089 /* Disable the Peripheral */
1090 __HAL_LPTIM_DISABLE(hlptim);
1092 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1094 return HAL_TIMEOUT;
1097 /* Disable Autoreload write complete interrupt */
1098 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
1100 /* Disable Compare write complete interrupt */
1101 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
1103 /* Disable Autoreload match interrupt */
1104 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
1106 /* Disable Compare match interrupt */
1107 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
1109 /* If external trigger source is used, then disable external trigger interrupt */
1110 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
1112 /* Disable external trigger interrupt */
1113 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
1116 /* Change the TIM state*/
1117 hlptim->State = HAL_LPTIM_STATE_READY;
1119 /* Return function status */
1120 return HAL_OK;
1124 * @brief Start the Encoder interface.
1125 * @param hlptim LPTIM handle
1126 * @param Period Specifies the Autoreload value.
1127 * This parameter must be a value between 0x0000 and 0xFFFF.
1128 * @retval HAL status
1130 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1132 uint32_t tmpcfgr;
1134 /* Check the parameters */
1135 assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance));
1136 assert_param(IS_LPTIM_PERIOD(Period));
1137 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
1138 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
1139 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
1141 /* Set the LPTIM state */
1142 hlptim->State = HAL_LPTIM_STATE_BUSY;
1144 /* Get the LPTIMx CFGR value */
1145 tmpcfgr = hlptim->Instance->CFGR;
1147 /* Clear CKPOL bits */
1148 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
1150 /* Set Input polarity */
1151 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
1153 /* Write to LPTIMx CFGR */
1154 hlptim->Instance->CFGR = tmpcfgr;
1156 /* Set ENC bit to enable the encoder interface */
1157 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
1159 /* Enable the Peripheral */
1160 __HAL_LPTIM_ENABLE(hlptim);
1162 /* Clear flag */
1163 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1165 /* Load the period value in the autoreload register */
1166 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1168 /* Wait for the completion of the write operation to the LPTIM_ARR register */
1169 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
1171 return HAL_TIMEOUT;
1174 /* Start timer in continuous mode */
1175 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1177 /* Change the TIM state*/
1178 hlptim->State = HAL_LPTIM_STATE_READY;
1180 /* Return function status */
1181 return HAL_OK;
1185 * @brief Stop the Encoder interface.
1186 * @param hlptim LPTIM handle
1187 * @retval HAL status
1189 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
1191 /* Check the parameters */
1192 assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance));
1194 /* Set the LPTIM state */
1195 hlptim->State = HAL_LPTIM_STATE_BUSY;
1197 /* Disable the Peripheral */
1198 __HAL_LPTIM_DISABLE(hlptim);
1200 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1202 return HAL_TIMEOUT;
1205 /* Reset ENC bit to disable the encoder interface */
1206 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
1208 /* Change the TIM state*/
1209 hlptim->State = HAL_LPTIM_STATE_READY;
1211 /* Return function status */
1212 return HAL_OK;
1216 * @brief Start the Encoder interface in interrupt mode.
1217 * @param hlptim LPTIM handle
1218 * @param Period Specifies the Autoreload value.
1219 * This parameter must be a value between 0x0000 and 0xFFFF.
1220 * @retval HAL status
1222 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1224 uint32_t tmpcfgr;
1226 /* Check the parameters */
1227 assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance));
1228 assert_param(IS_LPTIM_PERIOD(Period));
1229 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
1230 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
1231 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
1233 /* Set the LPTIM state */
1234 hlptim->State = HAL_LPTIM_STATE_BUSY;
1236 /* Configure edge sensitivity for encoder mode */
1237 /* Get the LPTIMx CFGR value */
1238 tmpcfgr = hlptim->Instance->CFGR;
1240 /* Clear CKPOL bits */
1241 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
1243 /* Set Input polarity */
1244 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
1246 /* Write to LPTIMx CFGR */
1247 hlptim->Instance->CFGR = tmpcfgr;
1249 /* Set ENC bit to enable the encoder interface */
1250 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
1252 /* Enable the Peripheral */
1253 __HAL_LPTIM_ENABLE(hlptim);
1255 /* Clear flag */
1256 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1258 /* Load the period value in the autoreload register */
1259 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1261 /* Wait for the completion of the write operation to the LPTIM_ARR register */
1262 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
1264 return HAL_TIMEOUT;
1267 /* Disable the Peripheral */
1268 __HAL_LPTIM_DISABLE(hlptim);
1270 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1272 return HAL_TIMEOUT;
1275 /* Enable "switch to down direction" interrupt */
1276 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
1278 /* Enable "switch to up direction" interrupt */
1279 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
1281 /* Enable the Peripheral */
1282 __HAL_LPTIM_ENABLE(hlptim);
1284 /* Start timer in continuous mode */
1285 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1287 /* Change the TIM state*/
1288 hlptim->State = HAL_LPTIM_STATE_READY;
1290 /* Return function status */
1291 return HAL_OK;
1295 * @brief Stop the Encoder interface in interrupt mode.
1296 * @param hlptim LPTIM handle
1297 * @retval HAL status
1299 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1301 /* Check the parameters */
1302 assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance));
1304 /* Set the LPTIM state */
1305 hlptim->State = HAL_LPTIM_STATE_BUSY;
1307 /* Disable the Peripheral */
1308 __HAL_LPTIM_DISABLE(hlptim);
1310 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1312 return HAL_TIMEOUT;
1315 /* Reset ENC bit to disable the encoder interface */
1316 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
1318 /* Disable "switch to down direction" interrupt */
1319 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
1321 /* Disable "switch to up direction" interrupt */
1322 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
1324 /* Change the TIM state*/
1325 hlptim->State = HAL_LPTIM_STATE_READY;
1327 /* Return function status */
1328 return HAL_OK;
1332 * @brief Start the Timeout function.
1333 * @note The first trigger event will start the timer, any successive
1334 * trigger event will reset the counter and the timer restarts.
1335 * @param hlptim LPTIM handle
1336 * @param Period Specifies the Autoreload value.
1337 * This parameter must be a value between 0x0000 and 0xFFFF.
1338 * @param Timeout Specifies the TimeOut value to reset the counter.
1339 * This parameter must be a value between 0x0000 and 0xFFFF.
1340 * @retval HAL status
1342 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
1344 /* Check the parameters */
1345 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1346 assert_param(IS_LPTIM_PERIOD(Period));
1347 assert_param(IS_LPTIM_PULSE(Timeout));
1349 /* Set the LPTIM state */
1350 hlptim->State = HAL_LPTIM_STATE_BUSY;
1352 /* Set TIMOUT bit to enable the timeout function */
1353 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
1355 /* Enable the Peripheral */
1356 __HAL_LPTIM_ENABLE(hlptim);
1358 /* Clear flag */
1359 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1361 /* Load the period value in the autoreload register */
1362 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1364 /* Wait for the completion of the write operation to the LPTIM_ARR register */
1365 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
1367 return HAL_TIMEOUT;
1370 /* Clear flag */
1371 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
1373 /* Load the Timeout value in the compare register */
1374 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
1376 /* Wait for the completion of the write operation to the LPTIM_CMP register */
1377 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
1379 return HAL_TIMEOUT;
1382 /* Start timer in continuous mode */
1383 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1385 /* Change the TIM state*/
1386 hlptim->State = HAL_LPTIM_STATE_READY;
1388 /* Return function status */
1389 return HAL_OK;
1393 * @brief Stop the Timeout function.
1394 * @param hlptim LPTIM handle
1395 * @retval HAL status
1397 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
1399 /* Check the parameters */
1400 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1402 /* Set the LPTIM state */
1403 hlptim->State = HAL_LPTIM_STATE_BUSY;
1405 /* Disable the Peripheral */
1406 __HAL_LPTIM_DISABLE(hlptim);
1408 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1410 return HAL_TIMEOUT;
1413 /* Reset TIMOUT bit to enable the timeout function */
1414 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
1416 /* Change the TIM state*/
1417 hlptim->State = HAL_LPTIM_STATE_READY;
1419 /* Return function status */
1420 return HAL_OK;
1424 * @brief Start the Timeout function in interrupt mode.
1425 * @note The first trigger event will start the timer, any successive
1426 * trigger event will reset the counter and the timer restarts.
1427 * @param hlptim LPTIM handle
1428 * @param Period Specifies the Autoreload value.
1429 * This parameter must be a value between 0x0000 and 0xFFFF.
1430 * @param Timeout Specifies the TimeOut value to reset the counter.
1431 * This parameter must be a value between 0x0000 and 0xFFFF.
1432 * @retval HAL status
1434 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
1436 /* Check the parameters */
1437 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1438 assert_param(IS_LPTIM_PERIOD(Period));
1439 assert_param(IS_LPTIM_PULSE(Timeout));
1441 /* Set the LPTIM state */
1442 hlptim->State = HAL_LPTIM_STATE_BUSY;
1444 /* Set TIMOUT bit to enable the timeout function */
1445 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
1447 /* Enable the Peripheral */
1448 __HAL_LPTIM_ENABLE(hlptim);
1450 /* Clear flag */
1451 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1453 /* Load the period value in the autoreload register */
1454 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1456 /* Wait for the completion of the write operation to the LPTIM_ARR register */
1457 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
1459 return HAL_TIMEOUT;
1462 /* Clear flag */
1463 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
1465 /* Load the Timeout value in the compare register */
1466 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
1468 /* Wait for the completion of the write operation to the LPTIM_CMP register */
1469 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
1471 return HAL_TIMEOUT;
1474 /* Disable the Peripheral */
1475 __HAL_LPTIM_DISABLE(hlptim);
1477 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1479 return HAL_TIMEOUT;
1482 /* Enable Compare match interrupt */
1483 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
1485 /* Enable the Peripheral */
1486 __HAL_LPTIM_ENABLE(hlptim);
1488 /* Start timer in continuous mode */
1489 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1491 /* Change the TIM state*/
1492 hlptim->State = HAL_LPTIM_STATE_READY;
1494 /* Return function status */
1495 return HAL_OK;
1499 * @brief Stop the Timeout function in interrupt mode.
1500 * @param hlptim LPTIM handle
1501 * @retval HAL status
1503 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1505 /* Check the parameters */
1506 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1508 /* Set the LPTIM state */
1509 hlptim->State = HAL_LPTIM_STATE_BUSY;
1511 /* Disable the Peripheral */
1512 __HAL_LPTIM_DISABLE(hlptim);
1514 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1516 return HAL_TIMEOUT;
1519 /* Reset TIMOUT bit to enable the timeout function */
1520 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
1522 /* Disable Compare match interrupt */
1523 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
1525 /* Change the TIM state*/
1526 hlptim->State = HAL_LPTIM_STATE_READY;
1528 /* Return function status */
1529 return HAL_OK;
1533 * @brief Start the Counter mode.
1534 * @param hlptim LPTIM handle
1535 * @param Period Specifies the Autoreload value.
1536 * This parameter must be a value between 0x0000 and 0xFFFF.
1537 * @retval HAL status
1539 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1541 /* Check the parameters */
1542 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1543 assert_param(IS_LPTIM_PERIOD(Period));
1545 /* Set the LPTIM state */
1546 hlptim->State = HAL_LPTIM_STATE_BUSY;
1548 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1549 if ((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
1551 /* Check if clock is prescaled */
1552 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
1553 /* Set clock prescaler to 0 */
1554 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
1557 /* Enable the Peripheral */
1558 __HAL_LPTIM_ENABLE(hlptim);
1560 /* Clear flag */
1561 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1563 /* Load the period value in the autoreload register */
1564 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1566 /* Wait for the completion of the write operation to the LPTIM_ARR register */
1567 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
1569 return HAL_TIMEOUT;
1572 /* Start timer in continuous mode */
1573 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1575 /* Change the TIM state*/
1576 hlptim->State = HAL_LPTIM_STATE_READY;
1578 /* Return function status */
1579 return HAL_OK;
1583 * @brief Stop the Counter mode.
1584 * @param hlptim LPTIM handle
1585 * @retval HAL status
1587 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
1589 /* Check the parameters */
1590 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1592 /* Set the LPTIM state */
1593 hlptim->State = HAL_LPTIM_STATE_BUSY;
1595 /* Disable the Peripheral */
1596 __HAL_LPTIM_DISABLE(hlptim);
1598 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1600 return HAL_TIMEOUT;
1603 /* Change the TIM state*/
1604 hlptim->State = HAL_LPTIM_STATE_READY;
1606 /* Return function status */
1607 return HAL_OK;
1611 * @brief Start the Counter mode in interrupt mode.
1612 * @param hlptim LPTIM handle
1613 * @param Period Specifies the Autoreload value.
1614 * This parameter must be a value between 0x0000 and 0xFFFF.
1615 * @retval HAL status
1617 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1619 /* Check the parameters */
1620 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1621 assert_param(IS_LPTIM_PERIOD(Period));
1623 /* Set the LPTIM state */
1624 hlptim->State = HAL_LPTIM_STATE_BUSY;
1626 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1627 if ((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
1629 /* Check if clock is prescaled */
1630 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
1631 /* Set clock prescaler to 0 */
1632 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
1635 /* Enable the Peripheral */
1636 __HAL_LPTIM_ENABLE(hlptim);
1638 /* Clear flag */
1639 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1641 /* Load the period value in the autoreload register */
1642 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1644 /* Wait for the completion of the write operation to the LPTIM_ARR register */
1645 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
1647 return HAL_TIMEOUT;
1650 /* Disable the Peripheral */
1651 __HAL_LPTIM_DISABLE(hlptim);
1653 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1655 return HAL_TIMEOUT;
1658 /* Enable Autoreload write complete interrupt */
1659 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
1661 /* Enable Autoreload match interrupt */
1662 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
1664 /* Enable the Peripheral */
1665 __HAL_LPTIM_ENABLE(hlptim);
1667 /* Start timer in continuous mode */
1668 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1670 /* Change the TIM state*/
1671 hlptim->State = HAL_LPTIM_STATE_READY;
1673 /* Return function status */
1674 return HAL_OK;
1678 * @brief Stop the Counter mode in interrupt mode.
1679 * @param hlptim LPTIM handle
1680 * @retval HAL status
1682 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1684 /* Check the parameters */
1685 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1687 /* Set the LPTIM state */
1688 hlptim->State = HAL_LPTIM_STATE_BUSY;
1690 /* Disable the Peripheral */
1691 __HAL_LPTIM_DISABLE(hlptim);
1693 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
1695 return HAL_TIMEOUT;
1698 /* Disable Autoreload write complete interrupt */
1699 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
1701 /* Disable Autoreload match interrupt */
1702 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
1703 /* Change the TIM state*/
1704 hlptim->State = HAL_LPTIM_STATE_READY;
1706 /* Return function status */
1707 return HAL_OK;
1711 * @}
1714 /** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions
1715 * @brief Read operation functions.
1717 @verbatim
1718 ==============================================================================
1719 ##### LPTIM Read operation functions #####
1720 ==============================================================================
1721 [..] This section provides LPTIM Reading functions.
1722 (+) Read the counter value.
1723 (+) Read the period (Auto-reload) value.
1724 (+) Read the pulse (Compare)value.
1725 @endverbatim
1726 * @{
1730 * @brief Return the current counter value.
1731 * @param hlptim LPTIM handle
1732 * @retval Counter value.
1734 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
1736 /* Check the parameters */
1737 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1739 return (hlptim->Instance->CNT);
1743 * @brief Return the current Autoreload (Period) value.
1744 * @param hlptim LPTIM handle
1745 * @retval Autoreload value.
1747 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
1749 /* Check the parameters */
1750 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1752 return (hlptim->Instance->ARR);
1756 * @brief Return the current Compare (Pulse) value.
1757 * @param hlptim LPTIM handle
1758 * @retval Compare value.
1760 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
1762 /* Check the parameters */
1763 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1765 return (hlptim->Instance->CMP);
1769 * @}
1772 /** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks
1773 * @brief LPTIM IRQ handler.
1775 @verbatim
1776 ==============================================================================
1777 ##### LPTIM IRQ handler and callbacks #####
1778 ==============================================================================
1779 [..] This section provides LPTIM IRQ handler and callback functions called within
1780 the IRQ handler:
1781 (+) LPTIM interrupt request handler
1782 (+) Compare match Callback
1783 (+) Auto-reload match Callback
1784 (+) External trigger event detection Callback
1785 (+) Compare register write complete Callback
1786 (+) Auto-reload register write complete Callback
1787 (+) Up-counting direction change Callback
1788 (+) Down-counting direction change Callback
1790 @endverbatim
1791 * @{
1795 * @brief Handle LPTIM interrupt request.
1796 * @param hlptim LPTIM handle
1797 * @retval None
1799 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
1801 /* Compare match interrupt */
1802 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
1804 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) != RESET)
1806 /* Clear Compare match flag */
1807 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
1809 /* Compare match Callback */
1810 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1811 hlptim->CompareMatchCallback(hlptim);
1812 #else
1813 HAL_LPTIM_CompareMatchCallback(hlptim);
1814 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1818 /* Autoreload match interrupt */
1819 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
1821 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET)
1823 /* Clear Autoreload match flag */
1824 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
1826 /* Autoreload match Callback */
1827 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1828 hlptim->AutoReloadMatchCallback(hlptim);
1829 #else
1830 HAL_LPTIM_AutoReloadMatchCallback(hlptim);
1831 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1835 /* Trigger detected interrupt */
1836 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
1838 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) != RESET)
1840 /* Clear Trigger detected flag */
1841 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
1843 /* Trigger detected callback */
1844 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1845 hlptim->TriggerCallback(hlptim);
1846 #else
1847 HAL_LPTIM_TriggerCallback(hlptim);
1848 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1852 /* Compare write interrupt */
1853 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
1855 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) != RESET)
1857 /* Clear Compare write flag */
1858 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
1860 /* Compare write Callback */
1861 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1862 hlptim->CompareWriteCallback(hlptim);
1863 #else
1864 HAL_LPTIM_CompareWriteCallback(hlptim);
1865 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1869 /* Autoreload write interrupt */
1870 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
1872 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET)
1874 /* Clear Autoreload write flag */
1875 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1877 /* Autoreload write Callback */
1878 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1879 hlptim->AutoReloadWriteCallback(hlptim);
1880 #else
1881 HAL_LPTIM_AutoReloadWriteCallback(hlptim);
1882 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1886 /* Direction counter changed from Down to Up interrupt */
1887 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
1889 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) != RESET)
1891 /* Clear Direction counter changed from Down to Up flag */
1892 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
1894 /* Direction counter changed from Down to Up Callback */
1895 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1896 hlptim->DirectionUpCallback(hlptim);
1897 #else
1898 HAL_LPTIM_DirectionUpCallback(hlptim);
1899 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1903 /* Direction counter changed from Up to Down interrupt */
1904 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
1906 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) != RESET)
1908 /* Clear Direction counter changed from Up to Down flag */
1909 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
1911 /* Direction counter changed from Up to Down Callback */
1912 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1913 hlptim->DirectionDownCallback(hlptim);
1914 #else
1915 HAL_LPTIM_DirectionDownCallback(hlptim);
1916 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1922 * @brief Compare match callback in non-blocking mode.
1923 * @param hlptim LPTIM handle
1924 * @retval None
1926 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
1928 /* Prevent unused argument(s) compilation warning */
1929 UNUSED(hlptim);
1931 /* NOTE : This function should not be modified, when the callback is needed,
1932 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
1937 * @brief Autoreload match callback in non-blocking mode.
1938 * @param hlptim LPTIM handle
1939 * @retval None
1941 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
1943 /* Prevent unused argument(s) compilation warning */
1944 UNUSED(hlptim);
1946 /* NOTE : This function should not be modified, when the callback is needed,
1947 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
1952 * @brief Trigger detected callback in non-blocking mode.
1953 * @param hlptim LPTIM handle
1954 * @retval None
1956 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
1958 /* Prevent unused argument(s) compilation warning */
1959 UNUSED(hlptim);
1961 /* NOTE : This function should not be modified, when the callback is needed,
1962 the HAL_LPTIM_TriggerCallback could be implemented in the user file
1967 * @brief Compare write callback in non-blocking mode.
1968 * @param hlptim LPTIM handle
1969 * @retval None
1971 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
1973 /* Prevent unused argument(s) compilation warning */
1974 UNUSED(hlptim);
1976 /* NOTE : This function should not be modified, when the callback is needed,
1977 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
1982 * @brief Autoreload write callback in non-blocking mode.
1983 * @param hlptim LPTIM handle
1984 * @retval None
1986 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
1988 /* Prevent unused argument(s) compilation warning */
1989 UNUSED(hlptim);
1991 /* NOTE : This function should not be modified, when the callback is needed,
1992 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
1997 * @brief Direction counter changed from Down to Up callback in non-blocking mode.
1998 * @param hlptim LPTIM handle
1999 * @retval None
2001 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
2003 /* Prevent unused argument(s) compilation warning */
2004 UNUSED(hlptim);
2006 /* NOTE : This function should not be modified, when the callback is needed,
2007 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
2012 * @brief Direction counter changed from Up to Down callback in non-blocking mode.
2013 * @param hlptim LPTIM handle
2014 * @retval None
2016 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
2018 /* Prevent unused argument(s) compilation warning */
2019 UNUSED(hlptim);
2021 /* NOTE : This function should not be modified, when the callback is needed,
2022 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
2026 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
2028 * @brief Register a User LPTIM callback to be used instead of the weak predefined callback
2029 * @param hlptim LPTIM handle
2030 * @param CallbackID ID of the callback to be registered
2031 * This parameter can be one of the following values:
2032 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
2033 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
2034 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID
2035 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
2036 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID
2037 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID
2038 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
2039 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID
2040 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID
2041 * @param pCallback pointer to the callback function
2042 * @retval status
2044 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *hlptim,
2045 HAL_LPTIM_CallbackIDTypeDef CallbackID,
2046 pLPTIM_CallbackTypeDef pCallback)
2048 HAL_StatusTypeDef status = HAL_OK;
2050 if (pCallback == NULL)
2052 return HAL_ERROR;
2055 /* Process locked */
2056 __HAL_LOCK(hlptim);
2058 if (hlptim->State == HAL_LPTIM_STATE_READY)
2060 switch (CallbackID)
2062 case HAL_LPTIM_MSPINIT_CB_ID :
2063 hlptim->MspInitCallback = pCallback;
2064 break;
2066 case HAL_LPTIM_MSPDEINIT_CB_ID :
2067 hlptim->MspDeInitCallback = pCallback;
2068 break;
2070 case HAL_LPTIM_COMPARE_MATCH_CB_ID :
2071 hlptim->CompareMatchCallback = pCallback;
2072 break;
2074 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
2075 hlptim->AutoReloadMatchCallback = pCallback;
2076 break;
2078 case HAL_LPTIM_TRIGGER_CB_ID :
2079 hlptim->TriggerCallback = pCallback;
2080 break;
2082 case HAL_LPTIM_COMPARE_WRITE_CB_ID :
2083 hlptim->CompareWriteCallback = pCallback;
2084 break;
2086 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID :
2087 hlptim->AutoReloadWriteCallback = pCallback;
2088 break;
2090 case HAL_LPTIM_DIRECTION_UP_CB_ID :
2091 hlptim->DirectionUpCallback = pCallback;
2092 break;
2094 case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
2095 hlptim->DirectionDownCallback = pCallback;
2096 break;
2098 default :
2099 /* Return error status */
2100 status = HAL_ERROR;
2101 break;
2104 else if (hlptim->State == HAL_LPTIM_STATE_RESET)
2106 switch (CallbackID)
2108 case HAL_LPTIM_MSPINIT_CB_ID :
2109 hlptim->MspInitCallback = pCallback;
2110 break;
2112 case HAL_LPTIM_MSPDEINIT_CB_ID :
2113 hlptim->MspDeInitCallback = pCallback;
2114 break;
2116 default :
2117 /* Return error status */
2118 status = HAL_ERROR;
2119 break;
2122 else
2124 /* Return error status */
2125 status = HAL_ERROR;
2128 /* Release Lock */
2129 __HAL_UNLOCK(hlptim);
2131 return status;
2135 * @brief Unregister a LPTIM callback
2136 * LLPTIM callback is redirected to the weak predefined callback
2137 * @param hlptim LPTIM handle
2138 * @param CallbackID ID of the callback to be unregistered
2139 * This parameter can be one of the following values:
2140 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
2141 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
2142 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID
2143 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
2144 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID
2145 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID
2146 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
2147 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID
2148 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID
2149 * @retval status
2151 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *hlptim,
2152 HAL_LPTIM_CallbackIDTypeDef CallbackID)
2154 HAL_StatusTypeDef status = HAL_OK;
2156 /* Process locked */
2157 __HAL_LOCK(hlptim);
2159 if (hlptim->State == HAL_LPTIM_STATE_READY)
2161 switch (CallbackID)
2163 case HAL_LPTIM_MSPINIT_CB_ID :
2164 hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */
2165 break;
2167 case HAL_LPTIM_MSPDEINIT_CB_ID :
2168 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak Msp DeInit Callback */
2169 break;
2171 case HAL_LPTIM_COMPARE_MATCH_CB_ID :
2172 hlptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback; /* Legacy weak Compare match Callback */
2173 break;
2175 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
2176 hlptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; /* Legacy weak Auto-reload match Callback */
2177 break;
2179 case HAL_LPTIM_TRIGGER_CB_ID :
2180 hlptim->TriggerCallback = HAL_LPTIM_TriggerCallback; /* Legacy weak External trigger event detection Callback */
2181 break;
2183 case HAL_LPTIM_COMPARE_WRITE_CB_ID :
2184 hlptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback; /* Legacy weak Compare register write complete Callback */
2185 break;
2187 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID :
2188 hlptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback; /* Legacy weak Auto-reload register write complete Callback */
2189 break;
2191 case HAL_LPTIM_DIRECTION_UP_CB_ID :
2192 hlptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback; /* Legacy weak Up-counting direction change Callback */
2193 break;
2195 case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
2196 hlptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback; /* Legacy weak Down-counting direction change Callback */
2197 break;
2199 default :
2200 /* Return error status */
2201 status = HAL_ERROR;
2202 break;
2205 else if (hlptim->State == HAL_LPTIM_STATE_RESET)
2207 switch (CallbackID)
2209 case HAL_LPTIM_MSPINIT_CB_ID :
2210 hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */
2211 break;
2213 case HAL_LPTIM_MSPDEINIT_CB_ID :
2214 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak Msp DeInit Callback */
2215 break;
2217 default :
2218 /* Return error status */
2219 status = HAL_ERROR;
2220 break;
2223 else
2225 /* Return error status */
2226 status = HAL_ERROR;
2229 /* Release Lock */
2230 __HAL_UNLOCK(hlptim);
2232 return status;
2234 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
2237 * @}
2240 /** @defgroup LPTIM_Group5 Peripheral State functions
2241 * @brief Peripheral State functions.
2243 @verbatim
2244 ==============================================================================
2245 ##### Peripheral State functions #####
2246 ==============================================================================
2247 [..]
2248 This subsection permits to get in run-time the status of the peripheral.
2250 @endverbatim
2251 * @{
2255 * @brief Return the LPTIM handle state.
2256 * @param hlptim LPTIM handle
2257 * @retval HAL state
2259 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
2261 /* Return LPTIM handle state */
2262 return hlptim->State;
2266 * @}
2271 * @}
2274 /* Private functions ---------------------------------------------------------*/
2276 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
2277 * @{
2279 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
2281 * @brief Reset interrupt callbacks to the legacy weak callbacks.
2282 * @param lptim pointer to a LPTIM_HandleTypeDef structure that contains
2283 * the configuration information for LPTIM module.
2284 * @retval None
2286 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim)
2288 /* Reset the LPTIM callback to the legacy weak callbacks */
2289 lptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback; /* Compare match Callback */
2290 lptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; /* Auto-reload match Callback */
2291 lptim->TriggerCallback = HAL_LPTIM_TriggerCallback; /* External trigger event detection Callback */
2292 lptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback; /* Compare register write complete Callback */
2293 lptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback; /* Auto-reload register write complete Callback */
2294 lptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback; /* Up-counting direction change Callback */
2295 lptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback; /* Down-counting direction change Callback */
2297 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
2300 * @brief LPTimer Wait for flag set
2301 * @param hlptim pointer to a LPTIM_HandleTypeDef structure that contains
2302 * the configuration information for LPTIM module.
2303 * @param flag The lptim flag
2304 * @retval HAL status
2306 static HAL_StatusTypeDef LPTIM_WaitForFlag(LPTIM_HandleTypeDef *hlptim, uint32_t flag)
2308 HAL_StatusTypeDef result = HAL_OK;
2309 uint32_t count = TIMEOUT * (SystemCoreClock / 20UL / 1000UL);
2312 count--;
2313 if (count == 0UL)
2315 result = HAL_TIMEOUT;
2318 while((!(__HAL_LPTIM_GET_FLAG((hlptim), (flag)))) && (count != 0UL));
2320 return result;
2324 * @brief Disable LPTIM HW instance.
2325 * @param hlptim pointer to a LPTIM_HandleTypeDef structure that contains
2326 * the configuration information for LPTIM module.
2327 * @note The following sequence is required to solve LPTIM disable HW limitation.
2328 * Please check Errata Sheet ES0335 for more details under "MCU may remain
2329 * stuck in LPTIM interrupt when entering Stop mode" section.
2330 * @retval None
2332 void LPTIM_Disable(LPTIM_HandleTypeDef *hlptim)
2334 uint32_t tmpclksource = 0;
2335 uint32_t tmpIER;
2336 uint32_t tmpCFGR;
2337 uint32_t tmpCMP;
2338 uint32_t tmpARR;
2339 uint32_t tmpCFGR2;
2341 __disable_irq();
2343 /*********** Save LPTIM Config ***********/
2344 /* Save LPTIM source clock */
2345 switch ((uint32_t)hlptim->Instance)
2347 case LPTIM1_BASE:
2348 tmpclksource = __HAL_RCC_GET_LPTIM1_SOURCE();
2349 break;
2350 case LPTIM2_BASE:
2351 tmpclksource = __HAL_RCC_GET_LPTIM2_SOURCE();
2352 break;
2353 #if defined(LPTIM3)
2354 case LPTIM3_BASE:
2355 tmpclksource = __HAL_RCC_GET_LPTIM3_SOURCE();
2356 break;
2357 #endif /* LPTIM3 */
2358 #if defined(LPTIM4)
2359 case LPTIM4_BASE:
2360 tmpclksource = __HAL_RCC_GET_LPTIM4_SOURCE();
2361 break;
2362 #endif /* LPTIM4 */
2363 #if defined(LPTIM5)
2364 case LPTIM5_BASE:
2365 tmpclksource = __HAL_RCC_GET_LPTIM5_SOURCE();
2366 break;
2367 #endif /* LPTIM5 */
2368 default:
2369 break;
2372 /* Save LPTIM configuration registers */
2373 tmpIER = hlptim->Instance->IER;
2374 tmpCFGR = hlptim->Instance->CFGR;
2375 tmpCMP = hlptim->Instance->CMP;
2376 tmpARR = hlptim->Instance->ARR;
2377 tmpCFGR2 = hlptim->Instance->CFGR2;
2379 /*********** Reset LPTIM ***********/
2380 switch ((uint32_t)hlptim->Instance)
2382 case LPTIM1_BASE:
2383 __HAL_RCC_LPTIM1_FORCE_RESET();
2384 __HAL_RCC_LPTIM1_RELEASE_RESET();
2385 break;
2386 case LPTIM2_BASE:
2387 __HAL_RCC_LPTIM2_FORCE_RESET();
2388 __HAL_RCC_LPTIM2_RELEASE_RESET();
2389 break;
2390 #if defined(LPTIM3)
2391 case LPTIM3_BASE:
2392 __HAL_RCC_LPTIM3_FORCE_RESET();
2393 __HAL_RCC_LPTIM3_RELEASE_RESET();
2394 break;
2395 #endif /* LPTIM3 */
2396 #if defined(LPTIM4)
2397 case LPTIM4_BASE:
2398 __HAL_RCC_LPTIM4_FORCE_RESET();
2399 __HAL_RCC_LPTIM4_RELEASE_RESET();
2400 break;
2401 #endif /* LPTIM4 */
2402 #if defined(LPTIM5)
2403 case LPTIM5_BASE:
2404 __HAL_RCC_LPTIM5_FORCE_RESET();
2405 __HAL_RCC_LPTIM5_RELEASE_RESET();
2406 break;
2407 #endif /* LPTIM5 */
2408 default:
2409 break;
2412 /*********** Restore LPTIM Config ***********/
2413 if ((tmpCMP != 0UL) || (tmpARR != 0UL))
2415 /* Force LPTIM source kernel clock from APB */
2416 switch ((uint32_t)hlptim->Instance)
2418 case LPTIM1_BASE:
2419 __HAL_RCC_LPTIM1_CONFIG(RCC_LPTIM1CLKSOURCE_D2PCLK1);
2420 break;
2421 case LPTIM2_BASE:
2422 __HAL_RCC_LPTIM2_CONFIG(RCC_LPTIM2CLKSOURCE_D3PCLK1);
2423 break;
2424 #if defined(LPTIM3)
2425 case LPTIM3_BASE:
2426 __HAL_RCC_LPTIM3_CONFIG(RCC_LPTIM3CLKSOURCE_D3PCLK1);
2427 break;
2428 #endif /* LPTIM3 */
2429 #if defined(LPTIM4)
2430 case LPTIM4_BASE:
2431 __HAL_RCC_LPTIM4_CONFIG(RCC_LPTIM4CLKSOURCE_D3PCLK1);
2432 break;
2433 #endif /* LPTIM4 */
2434 #if defined(LPTIM5)
2435 case LPTIM5_BASE:
2436 __HAL_RCC_LPTIM5_CONFIG(RCC_LPTIM5CLKSOURCE_D3PCLK1);
2437 break;
2438 #endif /* LPTIM5 */
2439 default:
2440 break;
2443 if (tmpCMP != 0UL)
2445 /* Restore CMP register (LPTIM should be enabled first) */
2446 hlptim->Instance->CR |= LPTIM_CR_ENABLE;
2447 hlptim->Instance->CMP = tmpCMP;
2449 /* Wait for the completion of the write operation to the LPTIM_CMP register */
2450 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
2452 hlptim->State = HAL_LPTIM_STATE_TIMEOUT;
2454 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
2457 if (tmpARR != 0UL)
2459 /* Restore ARR register (LPTIM should be enabled first) */
2460 hlptim->Instance->CR |= LPTIM_CR_ENABLE;
2461 hlptim->Instance->ARR = tmpARR;
2463 /* Wait for the completion of the write operation to the LPTIM_ARR register */
2464 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
2466 hlptim->State = HAL_LPTIM_STATE_TIMEOUT;
2469 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
2472 /* Restore LPTIM source kernel clock */
2473 switch ((uint32_t)hlptim->Instance)
2475 case LPTIM1_BASE:
2476 __HAL_RCC_LPTIM1_CONFIG(tmpclksource);
2477 break;
2478 case LPTIM2_BASE:
2479 __HAL_RCC_LPTIM2_CONFIG(tmpclksource);
2480 break;
2481 #if defined(LPTIM3)
2482 case LPTIM3_BASE:
2483 __HAL_RCC_LPTIM3_CONFIG(tmpclksource);
2484 break;
2485 #endif /* LPTIM3 */
2486 #if defined(LPTIM4)
2487 case LPTIM4_BASE:
2488 __HAL_RCC_LPTIM4_CONFIG(tmpclksource);
2489 break;
2490 #endif /* LPTIM4 */
2491 #if defined(LPTIM5)
2492 case LPTIM5_BASE:
2493 __HAL_RCC_LPTIM5_CONFIG(tmpclksource);
2494 break;
2495 #endif /* LPTIM5 */
2496 default:
2497 break;
2501 /* Restore configuration registers (LPTIM should be disabled first) */
2502 hlptim->Instance->CR &= ~(LPTIM_CR_ENABLE);
2503 hlptim->Instance->IER = tmpIER;
2504 hlptim->Instance->CFGR = tmpCFGR;
2505 hlptim->Instance->CFGR2 = tmpCFGR2;
2507 __enable_irq();
2510 * @}
2512 #endif /* LPTIM1 || LPTIM2 || LPTIM3 || LPTIM4 || LPTIM5 */
2514 #endif /* HAL_LPTIM_MODULE_ENABLED */
2516 * @}
2520 * @}
2523 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/