2 ******************************************************************************
3 * @file stm32g4xx_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.
15 ==============================================================================
16 ##### How to use this driver #####
17 ==============================================================================
19 The LPTIM HAL driver can be used as follows:
21 (#)Initialize the LPTIM low level resources by implementing the
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
31 (++) The instance: LPTIM1.
32 (++) Clock: the counter clock.
33 (+++) Source : it can be either the ULPTIM input (IN1) or one of
34 the internal clock; (APB, LSE or LSI).
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
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
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
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
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
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 =============================================
96 The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1
97 allows the user to configure dynamically the driver callbacks.
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.
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,
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 By default, after the Init and when the state is HAL_LPTIM_STATE_RESET
121 all interrupt callbacks are set to the corresponding weak functions:
122 examples @ref HAL_LPTIM_TriggerCallback(), @ref HAL_LPTIM_CompareMatchCallback().
124 Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
125 functionalities in the Init/DeInit only when these callbacks are null
126 (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init/DeInit
127 keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
129 Callbacks can be registered/unregistered in HAL_LPTIM_STATE_READY state only.
130 Exception done MspInit/MspDeInit that can be registered/unregistered
131 in HAL_LPTIM_STATE_READY or HAL_LPTIM_STATE_RESET state,
132 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
133 In that case first register the MspInit/MspDeInit user callbacks
134 using @ref HAL_LPTIM_RegisterCallback() before calling DeInit or Init function.
136 When The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or
137 not defined, the callback registration feature is not available and all callbacks
138 are set to the corresponding weak functions.
141 ******************************************************************************
144 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
145 * All rights reserved.</center></h2>
147 * This software component is licensed by ST under BSD 3-Clause license,
148 * the "License"; You may not use this file except in compliance with the
149 * License. You may obtain a copy of the License at:
150 * opensource.org/licenses/BSD-3-Clause
151 * ******************************************************************************
154 /* Includes ------------------------------------------------------------------*/
155 #include "stm32g4xx_hal.h"
157 /** @addtogroup STM32G4xx_HAL_Driver
161 /** @defgroup LPTIM LPTIM
162 * @brief LPTIM HAL module driver.
166 #ifdef HAL_LPTIM_MODULE_ENABLED
170 /* Private typedef -----------------------------------------------------------*/
171 /* Private define ------------------------------------------------------------*/
172 /* Private macro -------------------------------------------------------------*/
173 #define TIMEOUT 1000UL /* Timeout is 1s */
174 /* Private variables ---------------------------------------------------------*/
175 /* Private function prototypes -----------------------------------------------*/
176 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
177 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef
*lptim
);
178 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
180 /* Exported functions --------------------------------------------------------*/
182 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
186 /** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions
187 * @brief Initialization and Configuration functions.
190 ==============================================================================
191 ##### Initialization and de-initialization functions #####
192 ==============================================================================
193 [..] This section provides functions allowing to:
194 (+) Initialize the LPTIM according to the specified parameters in the
195 LPTIM_InitTypeDef and initialize the associated handle.
196 (+) DeInitialize the LPTIM peripheral.
197 (+) Initialize the LPTIM MSP.
198 (+) DeInitialize the LPTIM MSP.
205 * @brief Initialize the LPTIM according to the specified parameters in the
206 * LPTIM_InitTypeDef and initialize the associated handle.
207 * @param hlptim LPTIM handle
210 HAL_StatusTypeDef
HAL_LPTIM_Init(LPTIM_HandleTypeDef
*hlptim
)
214 /* Check the LPTIM handle allocation */
220 /* Check the parameters */
221 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
223 assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim
->Init
.Clock
.Source
));
224 assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim
->Init
.Clock
.Prescaler
));
225 if ((hlptim
->Init
.Clock
.Source
) == LPTIM_CLOCKSOURCE_ULPTIM
)
227 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim
->Init
.UltraLowPowerClock
.Polarity
));
228 assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim
->Init
.UltraLowPowerClock
.SampleTime
));
230 assert_param(IS_LPTIM_TRG_SOURCE(hlptim
->Init
.Trigger
.Source
));
231 if ((hlptim
->Init
.Trigger
.Source
) != LPTIM_TRIGSOURCE_SOFTWARE
)
233 assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim
->Init
.Trigger
.SampleTime
));
234 assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim
->Init
.Trigger
.ActiveEdge
));
236 assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim
->Init
.OutputPolarity
));
237 assert_param(IS_LPTIM_UPDATE_MODE(hlptim
->Init
.UpdateMode
));
238 assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim
->Init
.CounterSource
));
240 if (hlptim
->State
== HAL_LPTIM_STATE_RESET
)
242 /* Allocate lock resource and initialize it */
243 hlptim
->Lock
= HAL_UNLOCKED
;
245 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
246 /* Reset interrupt callbacks to legacy weak callbacks */
247 LPTIM_ResetCallback(hlptim
);
249 if (hlptim
->MspInitCallback
== NULL
)
251 hlptim
->MspInitCallback
= HAL_LPTIM_MspInit
;
254 /* Init the low level hardware : GPIO, CLOCK, NVIC */
255 hlptim
->MspInitCallback(hlptim
);
257 /* Init the low level hardware : GPIO, CLOCK, NVIC */
258 HAL_LPTIM_MspInit(hlptim
);
259 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
262 /* Change the LPTIM state */
263 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
265 /* Get the LPTIMx CFGR value */
266 tmpcfgr
= hlptim
->Instance
->CFGR
;
268 if (((hlptim
->Init
.Clock
.Source
) == LPTIM_CLOCKSOURCE_ULPTIM
) || ((hlptim
->Init
.CounterSource
) == LPTIM_COUNTERSOURCE_EXTERNAL
))
270 tmpcfgr
&= (uint32_t)(~(LPTIM_CFGR_CKPOL
| LPTIM_CFGR_CKFLT
));
272 if ((hlptim
->Init
.Trigger
.Source
) != LPTIM_TRIGSOURCE_SOFTWARE
)
274 tmpcfgr
&= (uint32_t)(~(LPTIM_CFGR_TRGFLT
| LPTIM_CFGR_TRIGSEL
));
277 /* Clear CKSEL, CKPOL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
278 tmpcfgr
&= (uint32_t)(~(LPTIM_CFGR_CKSEL
| LPTIM_CFGR_CKPOL
| LPTIM_CFGR_TRIGEN
| LPTIM_CFGR_PRELOAD
|
279 LPTIM_CFGR_WAVPOL
| LPTIM_CFGR_PRESC
| LPTIM_CFGR_COUNTMODE
));
281 /* Set initialization parameters */
282 tmpcfgr
|= (hlptim
->Init
.Clock
.Source
|
283 hlptim
->Init
.Clock
.Prescaler
|
284 hlptim
->Init
.OutputPolarity
|
285 hlptim
->Init
.UpdateMode
|
286 hlptim
->Init
.CounterSource
);
288 if (((hlptim
->Init
.Clock
.Source
) == LPTIM_CLOCKSOURCE_ULPTIM
) || ((hlptim
->Init
.CounterSource
) == LPTIM_COUNTERSOURCE_EXTERNAL
))
290 tmpcfgr
|= (hlptim
->Init
.UltraLowPowerClock
.Polarity
|
291 hlptim
->Init
.UltraLowPowerClock
.SampleTime
);
294 if ((hlptim
->Init
.Trigger
.Source
) != LPTIM_TRIGSOURCE_SOFTWARE
)
296 /* Enable External trigger and set the trigger source */
297 tmpcfgr
|= (hlptim
->Init
.Trigger
.Source
|
298 hlptim
->Init
.Trigger
.ActiveEdge
|
299 hlptim
->Init
.Trigger
.SampleTime
);
302 /* Write to LPTIMx CFGR */
303 hlptim
->Instance
->CFGR
= tmpcfgr
;
305 /* Configure LPTIM input sources */
306 if (hlptim
->Instance
== LPTIM1
)
308 /* Check LPTIM Input1 and Input2 sources */
309 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim
->Instance
, hlptim
->Init
.Input1Source
));
310 assert_param(IS_LPTIM_INPUT2_SOURCE(hlptim
->Instance
, hlptim
->Init
.Input2Source
));
312 /* Configure LPTIM Input1 and Input2 sources */
313 hlptim
->Instance
->OR
= (hlptim
->Init
.Input1Source
| hlptim
->Init
.Input2Source
);
316 /* Change the LPTIM state */
317 hlptim
->State
= HAL_LPTIM_STATE_READY
;
319 /* Return function status */
324 * @brief DeInitialize the LPTIM peripheral.
325 * @param hlptim LPTIM handle
328 HAL_StatusTypeDef
HAL_LPTIM_DeInit(LPTIM_HandleTypeDef
*hlptim
)
330 /* Check the LPTIM handle allocation */
336 /* Change the LPTIM state */
337 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
339 /* Disable the LPTIM Peripheral Clock */
340 __HAL_LPTIM_DISABLE(hlptim
);
342 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
343 if (hlptim
->MspDeInitCallback
== NULL
)
345 hlptim
->MspDeInitCallback
= HAL_LPTIM_MspDeInit
;
348 /* DeInit the low level hardware: CLOCK, NVIC.*/
349 hlptim
->MspDeInitCallback(hlptim
);
351 /* DeInit the low level hardware: CLOCK, NVIC.*/
352 HAL_LPTIM_MspDeInit(hlptim
);
353 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
355 /* Change the LPTIM state */
356 hlptim
->State
= HAL_LPTIM_STATE_RESET
;
359 __HAL_UNLOCK(hlptim
);
361 /* Return function status */
366 * @brief Initialize the LPTIM MSP.
367 * @param hlptim LPTIM handle
370 __weak
void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef
*hlptim
)
372 /* Prevent unused argument(s) compilation warning */
375 /* NOTE : This function should not be modified, when the callback is needed,
376 the HAL_LPTIM_MspInit could be implemented in the user file
381 * @brief DeInitialize LPTIM MSP.
382 * @param hlptim LPTIM handle
385 __weak
void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef
*hlptim
)
387 /* Prevent unused argument(s) compilation warning */
390 /* NOTE : This function should not be modified, when the callback is needed,
391 the HAL_LPTIM_MspDeInit could be implemented in the user file
399 /** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions
400 * @brief Start-Stop operation functions.
403 ==============================================================================
404 ##### LPTIM Start Stop operation functions #####
405 ==============================================================================
406 [..] This section provides functions allowing to:
407 (+) Start the PWM mode.
408 (+) Stop the PWM mode.
409 (+) Start the One pulse mode.
410 (+) Stop the One pulse mode.
411 (+) Start the Set once mode.
412 (+) Stop the Set once mode.
413 (+) Start the Encoder mode.
414 (+) Stop the Encoder mode.
415 (+) Start the Timeout mode.
416 (+) Stop the Timeout mode.
417 (+) Start the Counter mode.
418 (+) Stop the Counter mode.
426 * @brief Start the LPTIM PWM generation.
427 * @param hlptim LPTIM handle
428 * @param Period Specifies the Autoreload value.
429 * This parameter must be a value between 0x0000 and 0xFFFF.
430 * @param Pulse Specifies the compare value.
431 * This parameter must be a value between 0x0000 and 0xFFFF.
434 HAL_StatusTypeDef
HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
, uint32_t Pulse
)
436 /* Check the parameters */
437 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
438 assert_param(IS_LPTIM_PERIOD(Period
));
439 assert_param(IS_LPTIM_PULSE(Pulse
));
441 /* Set the LPTIM state */
442 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
444 /* Reset WAVE bit to set PWM mode */
445 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_WAVE
;
447 /* Enable the Peripheral */
448 __HAL_LPTIM_ENABLE(hlptim
);
450 /* Load the period value in the autoreload register */
451 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
453 /* Load the pulse value in the compare register */
454 __HAL_LPTIM_COMPARE_SET(hlptim
, Pulse
);
456 /* Start timer in continuous mode */
457 __HAL_LPTIM_START_CONTINUOUS(hlptim
);
459 /* Change the TIM state*/
460 hlptim
->State
= HAL_LPTIM_STATE_READY
;
462 /* Return function status */
467 * @brief Stop the LPTIM PWM generation.
468 * @param hlptim LPTIM handle
471 HAL_StatusTypeDef
HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef
*hlptim
)
473 /* Check the parameters */
474 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
476 /* Set the LPTIM state */
477 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
479 /* Disable the Peripheral */
480 __HAL_LPTIM_DISABLE(hlptim
);
482 /* Change the TIM state*/
483 hlptim
->State
= HAL_LPTIM_STATE_READY
;
485 /* Return function status */
490 * @brief Start the LPTIM PWM generation in interrupt mode.
491 * @param hlptim LPTIM handle
492 * @param Period Specifies the Autoreload value.
493 * This parameter must be a value between 0x0000 and 0xFFFF
494 * @param Pulse Specifies the compare value.
495 * This parameter must be a value between 0x0000 and 0xFFFF
498 HAL_StatusTypeDef
HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
, uint32_t Pulse
)
500 /* Check the parameters */
501 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
502 assert_param(IS_LPTIM_PERIOD(Period
));
503 assert_param(IS_LPTIM_PULSE(Pulse
));
505 /* Set the LPTIM state */
506 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
508 /* Reset WAVE bit to set PWM mode */
509 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_WAVE
;
511 /* Enable Autoreload write complete interrupt */
512 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_ARROK
);
514 /* Enable Compare write complete interrupt */
515 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_CMPOK
);
517 /* Enable Autoreload match interrupt */
518 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_ARRM
);
520 /* Enable Compare match interrupt */
521 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_CMPM
);
523 /* If external trigger source is used, then enable external trigger interrupt */
524 if ((hlptim
->Init
.Trigger
.Source
) != LPTIM_TRIGSOURCE_SOFTWARE
)
526 /* Enable external trigger interrupt */
527 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_EXTTRIG
);
530 /* Enable the Peripheral */
531 __HAL_LPTIM_ENABLE(hlptim
);
533 /* Load the period value in the autoreload register */
534 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
536 /* Load the pulse value in the compare register */
537 __HAL_LPTIM_COMPARE_SET(hlptim
, Pulse
);
539 /* Start timer in continuous mode */
540 __HAL_LPTIM_START_CONTINUOUS(hlptim
);
542 /* Change the TIM state*/
543 hlptim
->State
= HAL_LPTIM_STATE_READY
;
545 /* Return function status */
550 * @brief Stop the LPTIM PWM generation in interrupt mode.
551 * @param hlptim LPTIM handle
554 HAL_StatusTypeDef
HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef
*hlptim
)
556 /* Check the parameters */
557 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
559 /* Set the LPTIM state */
560 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
562 /* Disable the Peripheral */
563 __HAL_LPTIM_DISABLE(hlptim
);
565 /* Disable Autoreload write complete interrupt */
566 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_ARROK
);
568 /* Disable Compare write complete interrupt */
569 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_CMPOK
);
571 /* Disable Autoreload match interrupt */
572 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_ARRM
);
574 /* Disable Compare match interrupt */
575 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_CMPM
);
577 /* If external trigger source is used, then disable external trigger interrupt */
578 if ((hlptim
->Init
.Trigger
.Source
) != LPTIM_TRIGSOURCE_SOFTWARE
)
580 /* Disable external trigger interrupt */
581 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_EXTTRIG
);
584 /* Change the TIM state*/
585 hlptim
->State
= HAL_LPTIM_STATE_READY
;
587 /* Return function status */
592 * @brief Start the LPTIM One pulse generation.
593 * @param hlptim LPTIM handle
594 * @param Period Specifies the Autoreload value.
595 * This parameter must be a value between 0x0000 and 0xFFFF.
596 * @param Pulse Specifies the compare value.
597 * This parameter must be a value between 0x0000 and 0xFFFF.
600 HAL_StatusTypeDef
HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
, uint32_t Pulse
)
602 /* Check the parameters */
603 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
604 assert_param(IS_LPTIM_PERIOD(Period
));
605 assert_param(IS_LPTIM_PULSE(Pulse
));
607 /* Set the LPTIM state */
608 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
610 /* Reset WAVE bit to set one pulse mode */
611 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_WAVE
;
613 /* Enable the Peripheral */
614 __HAL_LPTIM_ENABLE(hlptim
);
616 /* Load the period value in the autoreload register */
617 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
619 /* Load the pulse value in the compare register */
620 __HAL_LPTIM_COMPARE_SET(hlptim
, Pulse
);
622 /* Start timer in single (one shot) mode */
623 __HAL_LPTIM_START_SINGLE(hlptim
);
625 /* Change the TIM state*/
626 hlptim
->State
= HAL_LPTIM_STATE_READY
;
628 /* Return function status */
633 * @brief Stop the LPTIM One pulse generation.
634 * @param hlptim LPTIM handle
637 HAL_StatusTypeDef
HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef
*hlptim
)
639 /* Check the parameters */
640 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
642 /* Set the LPTIM state */
643 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
645 /* Disable the Peripheral */
646 __HAL_LPTIM_DISABLE(hlptim
);
648 /* Change the TIM state*/
649 hlptim
->State
= HAL_LPTIM_STATE_READY
;
651 /* Return function status */
656 * @brief Start the LPTIM One pulse generation in interrupt mode.
657 * @param hlptim LPTIM handle
658 * @param Period Specifies the Autoreload value.
659 * This parameter must be a value between 0x0000 and 0xFFFF.
660 * @param Pulse Specifies the compare value.
661 * This parameter must be a value between 0x0000 and 0xFFFF.
664 HAL_StatusTypeDef
HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
, uint32_t Pulse
)
666 /* Check the parameters */
667 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
668 assert_param(IS_LPTIM_PERIOD(Period
));
669 assert_param(IS_LPTIM_PULSE(Pulse
));
671 /* Set the LPTIM state */
672 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
674 /* Reset WAVE bit to set one pulse mode */
675 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_WAVE
;
677 /* Enable Autoreload write complete interrupt */
678 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_ARROK
);
680 /* Enable Compare write complete interrupt */
681 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_CMPOK
);
683 /* Enable Autoreload match interrupt */
684 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_ARRM
);
686 /* Enable Compare match interrupt */
687 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_CMPM
);
689 /* If external trigger source is used, then enable external trigger interrupt */
690 if ((hlptim
->Init
.Trigger
.Source
) != LPTIM_TRIGSOURCE_SOFTWARE
)
692 /* Enable external trigger interrupt */
693 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_EXTTRIG
);
696 /* Enable the Peripheral */
697 __HAL_LPTIM_ENABLE(hlptim
);
699 /* Load the period value in the autoreload register */
700 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
702 /* Load the pulse value in the compare register */
703 __HAL_LPTIM_COMPARE_SET(hlptim
, Pulse
);
705 /* Start timer in single (one shot) mode */
706 __HAL_LPTIM_START_SINGLE(hlptim
);
708 /* Change the TIM state*/
709 hlptim
->State
= HAL_LPTIM_STATE_READY
;
711 /* Return function status */
716 * @brief Stop the LPTIM One pulse generation in interrupt mode.
717 * @param hlptim LPTIM handle
720 HAL_StatusTypeDef
HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef
*hlptim
)
722 /* Check the parameters */
723 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
725 /* Set the LPTIM state */
726 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
728 /* Disable the Peripheral */
729 __HAL_LPTIM_DISABLE(hlptim
);
731 /* Disable Autoreload write complete interrupt */
732 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_ARROK
);
734 /* Disable Compare write complete interrupt */
735 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_CMPOK
);
737 /* Disable Autoreload match interrupt */
738 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_ARRM
);
740 /* Disable Compare match interrupt */
741 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_CMPM
);
743 /* If external trigger source is used, then disable external trigger interrupt */
744 if ((hlptim
->Init
.Trigger
.Source
) != LPTIM_TRIGSOURCE_SOFTWARE
)
746 /* Disable external trigger interrupt */
747 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_EXTTRIG
);
750 /* Change the TIM state*/
751 hlptim
->State
= HAL_LPTIM_STATE_READY
;
753 /* Return function status */
758 * @brief Start the LPTIM in Set once mode.
759 * @param hlptim LPTIM handle
760 * @param Period Specifies the Autoreload value.
761 * This parameter must be a value between 0x0000 and 0xFFFF.
762 * @param Pulse Specifies the compare value.
763 * This parameter must be a value between 0x0000 and 0xFFFF.
766 HAL_StatusTypeDef
HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
, uint32_t Pulse
)
768 /* Check the parameters */
769 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
770 assert_param(IS_LPTIM_PERIOD(Period
));
771 assert_param(IS_LPTIM_PULSE(Pulse
));
773 /* Set the LPTIM state */
774 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
776 /* Set WAVE bit to enable the set once mode */
777 hlptim
->Instance
->CFGR
|= LPTIM_CFGR_WAVE
;
779 /* Enable the Peripheral */
780 __HAL_LPTIM_ENABLE(hlptim
);
782 /* Load the period value in the autoreload register */
783 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
785 /* Load the pulse value in the compare register */
786 __HAL_LPTIM_COMPARE_SET(hlptim
, Pulse
);
788 /* Start timer in single (one shot) mode */
789 __HAL_LPTIM_START_SINGLE(hlptim
);
791 /* Change the TIM state*/
792 hlptim
->State
= HAL_LPTIM_STATE_READY
;
794 /* Return function status */
799 * @brief Stop the LPTIM Set once mode.
800 * @param hlptim LPTIM handle
803 HAL_StatusTypeDef
HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef
*hlptim
)
805 /* Check the parameters */
806 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
808 /* Set the LPTIM state */
809 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
811 /* Disable the Peripheral */
812 __HAL_LPTIM_DISABLE(hlptim
);
814 /* Change the TIM state*/
815 hlptim
->State
= HAL_LPTIM_STATE_READY
;
817 /* Return function status */
822 * @brief Start the LPTIM Set once mode in interrupt mode.
823 * @param hlptim LPTIM handle
824 * @param Period Specifies the Autoreload value.
825 * This parameter must be a value between 0x0000 and 0xFFFF.
826 * @param Pulse Specifies the compare value.
827 * This parameter must be a value between 0x0000 and 0xFFFF.
830 HAL_StatusTypeDef
HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
, uint32_t Pulse
)
832 /* Check the parameters */
833 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
834 assert_param(IS_LPTIM_PERIOD(Period
));
835 assert_param(IS_LPTIM_PULSE(Pulse
));
837 /* Set the LPTIM state */
838 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
840 /* Set WAVE bit to enable the set once mode */
841 hlptim
->Instance
->CFGR
|= LPTIM_CFGR_WAVE
;
843 /* Enable Autoreload write complete interrupt */
844 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_ARROK
);
846 /* Enable Compare write complete interrupt */
847 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_CMPOK
);
849 /* Enable Autoreload match interrupt */
850 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_ARRM
);
852 /* Enable Compare match interrupt */
853 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_CMPM
);
855 /* If external trigger source is used, then enable external trigger interrupt */
856 if ((hlptim
->Init
.Trigger
.Source
) != LPTIM_TRIGSOURCE_SOFTWARE
)
858 /* Enable external trigger interrupt */
859 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_EXTTRIG
);
862 /* Enable the Peripheral */
863 __HAL_LPTIM_ENABLE(hlptim
);
865 /* Load the period value in the autoreload register */
866 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
868 /* Load the pulse value in the compare register */
869 __HAL_LPTIM_COMPARE_SET(hlptim
, Pulse
);
871 /* Start timer in single (one shot) mode */
872 __HAL_LPTIM_START_SINGLE(hlptim
);
874 /* Change the TIM state*/
875 hlptim
->State
= HAL_LPTIM_STATE_READY
;
877 /* Return function status */
882 * @brief Stop the LPTIM Set once mode in interrupt mode.
883 * @param hlptim LPTIM handle
886 HAL_StatusTypeDef
HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef
*hlptim
)
888 /* Check the parameters */
889 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
891 /* Set the LPTIM state */
892 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
894 /* Disable the Peripheral */
895 __HAL_LPTIM_DISABLE(hlptim
);
897 /* Disable Autoreload write complete interrupt */
898 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_ARROK
);
900 /* Disable Compare write complete interrupt */
901 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_CMPOK
);
903 /* Disable Autoreload match interrupt */
904 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_ARRM
);
906 /* Disable Compare match interrupt */
907 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_CMPM
);
909 /* If external trigger source is used, then disable external trigger interrupt */
910 if ((hlptim
->Init
.Trigger
.Source
) != LPTIM_TRIGSOURCE_SOFTWARE
)
912 /* Disable external trigger interrupt */
913 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_EXTTRIG
);
916 /* Change the TIM state*/
917 hlptim
->State
= HAL_LPTIM_STATE_READY
;
919 /* Return function status */
924 * @brief Start the Encoder interface.
925 * @param hlptim LPTIM handle
926 * @param Period Specifies the Autoreload value.
927 * This parameter must be a value between 0x0000 and 0xFFFF.
930 HAL_StatusTypeDef
HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
)
934 /* Check the parameters */
935 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
936 assert_param(IS_LPTIM_PERIOD(Period
));
937 assert_param(hlptim
->Init
.Clock
.Source
== LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC
);
938 assert_param(hlptim
->Init
.Clock
.Prescaler
== LPTIM_PRESCALER_DIV1
);
939 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim
->Init
.UltraLowPowerClock
.Polarity
));
941 /* Set the LPTIM state */
942 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
944 /* Get the LPTIMx CFGR value */
945 tmpcfgr
= hlptim
->Instance
->CFGR
;
947 /* Clear CKPOL bits */
948 tmpcfgr
&= (uint32_t)(~LPTIM_CFGR_CKPOL
);
950 /* Set Input polarity */
951 tmpcfgr
|= hlptim
->Init
.UltraLowPowerClock
.Polarity
;
953 /* Write to LPTIMx CFGR */
954 hlptim
->Instance
->CFGR
= tmpcfgr
;
956 /* Set ENC bit to enable the encoder interface */
957 hlptim
->Instance
->CFGR
|= LPTIM_CFGR_ENC
;
959 /* Enable the Peripheral */
960 __HAL_LPTIM_ENABLE(hlptim
);
962 /* Load the period value in the autoreload register */
963 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
965 /* Start timer in continuous mode */
966 __HAL_LPTIM_START_CONTINUOUS(hlptim
);
968 /* Change the TIM state*/
969 hlptim
->State
= HAL_LPTIM_STATE_READY
;
971 /* Return function status */
976 * @brief Stop the Encoder interface.
977 * @param hlptim LPTIM handle
980 HAL_StatusTypeDef
HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef
*hlptim
)
982 /* Check the parameters */
983 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
985 /* Set the LPTIM state */
986 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
988 /* Disable the Peripheral */
989 __HAL_LPTIM_DISABLE(hlptim
);
991 /* Reset ENC bit to disable the encoder interface */
992 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_ENC
;
994 /* Change the TIM state*/
995 hlptim
->State
= HAL_LPTIM_STATE_READY
;
997 /* Return function status */
1002 * @brief Start the Encoder interface in interrupt mode.
1003 * @param hlptim LPTIM handle
1004 * @param Period Specifies the Autoreload value.
1005 * This parameter must be a value between 0x0000 and 0xFFFF.
1006 * @retval HAL status
1008 HAL_StatusTypeDef
HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
)
1012 /* Check the parameters */
1013 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1014 assert_param(IS_LPTIM_PERIOD(Period
));
1015 assert_param(hlptim
->Init
.Clock
.Source
== LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC
);
1016 assert_param(hlptim
->Init
.Clock
.Prescaler
== LPTIM_PRESCALER_DIV1
);
1017 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim
->Init
.UltraLowPowerClock
.Polarity
));
1019 /* Set the LPTIM state */
1020 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1022 /* Configure edge sensitivity for encoder mode */
1023 /* Get the LPTIMx CFGR value */
1024 tmpcfgr
= hlptim
->Instance
->CFGR
;
1026 /* Clear CKPOL bits */
1027 tmpcfgr
&= (uint32_t)(~LPTIM_CFGR_CKPOL
);
1029 /* Set Input polarity */
1030 tmpcfgr
|= hlptim
->Init
.UltraLowPowerClock
.Polarity
;
1032 /* Write to LPTIMx CFGR */
1033 hlptim
->Instance
->CFGR
= tmpcfgr
;
1035 /* Set ENC bit to enable the encoder interface */
1036 hlptim
->Instance
->CFGR
|= LPTIM_CFGR_ENC
;
1038 /* Enable "switch to down direction" interrupt */
1039 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_DOWN
);
1041 /* Enable "switch to up direction" interrupt */
1042 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_UP
);
1044 /* Enable the Peripheral */
1045 __HAL_LPTIM_ENABLE(hlptim
);
1047 /* Load the period value in the autoreload register */
1048 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
1050 /* Start timer in continuous mode */
1051 __HAL_LPTIM_START_CONTINUOUS(hlptim
);
1053 /* Change the TIM state*/
1054 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1056 /* Return function status */
1061 * @brief Stop the Encoder interface in interrupt mode.
1062 * @param hlptim LPTIM handle
1063 * @retval HAL status
1065 HAL_StatusTypeDef
HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef
*hlptim
)
1067 /* Check the parameters */
1068 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1070 /* Set the LPTIM state */
1071 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1073 /* Disable the Peripheral */
1074 __HAL_LPTIM_DISABLE(hlptim
);
1076 /* Reset ENC bit to disable the encoder interface */
1077 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_ENC
;
1079 /* Disable "switch to down direction" interrupt */
1080 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_DOWN
);
1082 /* Disable "switch to up direction" interrupt */
1083 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_UP
);
1085 /* Change the TIM state*/
1086 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1088 /* Return function status */
1093 * @brief Start the Timeout function.
1094 * @note The first trigger event will start the timer, any successive
1095 * trigger event will reset the counter and the timer restarts.
1096 * @param hlptim LPTIM handle
1097 * @param Period Specifies the Autoreload value.
1098 * This parameter must be a value between 0x0000 and 0xFFFF.
1099 * @param Timeout Specifies the TimeOut value to reset the counter.
1100 * This parameter must be a value between 0x0000 and 0xFFFF.
1101 * @retval HAL status
1103 HAL_StatusTypeDef
HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
, uint32_t Timeout
)
1105 /* Check the parameters */
1106 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1107 assert_param(IS_LPTIM_PERIOD(Period
));
1108 assert_param(IS_LPTIM_PULSE(Timeout
));
1110 /* Set the LPTIM state */
1111 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1113 /* Set TIMOUT bit to enable the timeout function */
1114 hlptim
->Instance
->CFGR
|= LPTIM_CFGR_TIMOUT
;
1116 /* Enable the Peripheral */
1117 __HAL_LPTIM_ENABLE(hlptim
);
1119 /* Load the period value in the autoreload register */
1120 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
1122 /* Load the Timeout value in the compare register */
1123 __HAL_LPTIM_COMPARE_SET(hlptim
, Timeout
);
1125 /* Start timer in continuous mode */
1126 __HAL_LPTIM_START_CONTINUOUS(hlptim
);
1128 /* Change the TIM state*/
1129 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1131 /* Return function status */
1136 * @brief Stop the Timeout function.
1137 * @param hlptim LPTIM handle
1138 * @retval HAL status
1140 HAL_StatusTypeDef
HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef
*hlptim
)
1142 /* Check the parameters */
1143 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1145 /* Set the LPTIM state */
1146 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1148 /* Disable the Peripheral */
1149 __HAL_LPTIM_DISABLE(hlptim
);
1151 /* Reset TIMOUT bit to enable the timeout function */
1152 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_TIMOUT
;
1154 /* Change the TIM state*/
1155 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1157 /* Return function status */
1162 * @brief Start the Timeout function in interrupt mode.
1163 * @note The first trigger event will start the timer, any successive
1164 * trigger event will reset the counter and the timer restarts.
1165 * @param hlptim LPTIM handle
1166 * @param Period Specifies the Autoreload value.
1167 * This parameter must be a value between 0x0000 and 0xFFFF.
1168 * @param Timeout Specifies the TimeOut value to reset the counter.
1169 * This parameter must be a value between 0x0000 and 0xFFFF.
1170 * @retval HAL status
1172 HAL_StatusTypeDef
HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
, uint32_t Timeout
)
1174 /* Check the parameters */
1175 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1176 assert_param(IS_LPTIM_PERIOD(Period
));
1177 assert_param(IS_LPTIM_PULSE(Timeout
));
1179 /* Set the LPTIM state */
1180 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1182 /* Enable EXTI Line interrupt on the LPTIM Wake-up Timer */
1183 __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT();
1185 /* Set TIMOUT bit to enable the timeout function */
1186 hlptim
->Instance
->CFGR
|= LPTIM_CFGR_TIMOUT
;
1188 /* Enable Compare match interrupt */
1189 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_CMPM
);
1191 /* Enable the Peripheral */
1192 __HAL_LPTIM_ENABLE(hlptim
);
1194 /* Load the period value in the autoreload register */
1195 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
1197 /* Load the Timeout value in the compare register */
1198 __HAL_LPTIM_COMPARE_SET(hlptim
, Timeout
);
1200 /* Start timer in continuous mode */
1201 __HAL_LPTIM_START_CONTINUOUS(hlptim
);
1203 /* Change the TIM state*/
1204 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1206 /* Return function status */
1211 * @brief Stop the Timeout function in interrupt mode.
1212 * @param hlptim LPTIM handle
1213 * @retval HAL status
1215 HAL_StatusTypeDef
HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef
*hlptim
)
1217 /* Check the parameters */
1218 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1220 /* Set the LPTIM state */
1221 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1223 /* Disable EXTI Line interrupt on the LPTIM Wake-up Timer */
1224 __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT();
1226 /* Disable the Peripheral */
1227 __HAL_LPTIM_DISABLE(hlptim
);
1229 /* Reset TIMOUT bit to enable the timeout function */
1230 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_TIMOUT
;
1232 /* Disable Compare match interrupt */
1233 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_CMPM
);
1235 /* Change the TIM state*/
1236 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1238 /* Return function status */
1243 * @brief Start the Counter mode.
1244 * @param hlptim LPTIM handle
1245 * @param Period Specifies the Autoreload value.
1246 * This parameter must be a value between 0x0000 and 0xFFFF.
1247 * @retval HAL status
1249 HAL_StatusTypeDef
HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
)
1251 /* Check the parameters */
1252 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1253 assert_param(IS_LPTIM_PERIOD(Period
));
1255 /* Set the LPTIM state */
1256 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1258 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1259 if ((hlptim
->Init
.Clock
.Source
!= LPTIM_CLOCKSOURCE_ULPTIM
) && (hlptim
->Init
.CounterSource
== LPTIM_COUNTERSOURCE_EXTERNAL
))
1261 /* Check if clock is prescaled */
1262 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim
->Init
.Clock
.Prescaler
));
1263 /* Set clock prescaler to 0 */
1264 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_PRESC
;
1267 /* Enable the Peripheral */
1268 __HAL_LPTIM_ENABLE(hlptim
);
1270 /* Load the period value in the autoreload register */
1271 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
1273 /* Start timer in continuous mode */
1274 __HAL_LPTIM_START_CONTINUOUS(hlptim
);
1276 /* Change the TIM state*/
1277 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1279 /* Return function status */
1284 * @brief Stop the Counter mode.
1285 * @param hlptim LPTIM handle
1286 * @retval HAL status
1288 HAL_StatusTypeDef
HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef
*hlptim
)
1290 /* Check the parameters */
1291 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1293 /* Set the LPTIM state */
1294 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1296 /* Disable the Peripheral */
1297 __HAL_LPTIM_DISABLE(hlptim
);
1299 /* Change the TIM state*/
1300 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1302 /* Return function status */
1307 * @brief Start the Counter mode in interrupt mode.
1308 * @param hlptim LPTIM handle
1309 * @param Period Specifies the Autoreload value.
1310 * This parameter must be a value between 0x0000 and 0xFFFF.
1311 * @retval HAL status
1313 HAL_StatusTypeDef
HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef
*hlptim
, uint32_t Period
)
1315 /* Check the parameters */
1316 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1317 assert_param(IS_LPTIM_PERIOD(Period
));
1319 /* Set the LPTIM state */
1320 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1322 /* Enable EXTI Line interrupt on the LPTIM Wake-up Timer */
1323 __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT();
1325 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1326 if ((hlptim
->Init
.Clock
.Source
!= LPTIM_CLOCKSOURCE_ULPTIM
) && (hlptim
->Init
.CounterSource
== LPTIM_COUNTERSOURCE_EXTERNAL
))
1328 /* Check if clock is prescaled */
1329 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim
->Init
.Clock
.Prescaler
));
1330 /* Set clock prescaler to 0 */
1331 hlptim
->Instance
->CFGR
&= ~LPTIM_CFGR_PRESC
;
1334 /* Enable Autoreload write complete interrupt */
1335 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_ARROK
);
1337 /* Enable Autoreload match interrupt */
1338 __HAL_LPTIM_ENABLE_IT(hlptim
, LPTIM_IT_ARRM
);
1340 /* Enable the Peripheral */
1341 __HAL_LPTIM_ENABLE(hlptim
);
1343 /* Load the period value in the autoreload register */
1344 __HAL_LPTIM_AUTORELOAD_SET(hlptim
, Period
);
1346 /* Start timer in continuous mode */
1347 __HAL_LPTIM_START_CONTINUOUS(hlptim
);
1349 /* Change the TIM state*/
1350 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1352 /* Return function status */
1357 * @brief Stop the Counter mode in interrupt mode.
1358 * @param hlptim LPTIM handle
1359 * @retval HAL status
1361 HAL_StatusTypeDef
HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef
*hlptim
)
1363 /* Check the parameters */
1364 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1366 /* Set the LPTIM state */
1367 hlptim
->State
= HAL_LPTIM_STATE_BUSY
;
1369 /* Disable EXTI Line interrupt on the LPTIM Wake-up Timer */
1370 __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT();
1372 /* Disable the Peripheral */
1373 __HAL_LPTIM_DISABLE(hlptim
);
1375 /* Disable Autoreload write complete interrupt */
1376 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_ARROK
);
1378 /* Disable Autoreload match interrupt */
1379 __HAL_LPTIM_DISABLE_IT(hlptim
, LPTIM_IT_ARRM
);
1381 /* Change the TIM state*/
1382 hlptim
->State
= HAL_LPTIM_STATE_READY
;
1384 /* Return function status */
1392 /** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions
1393 * @brief Read operation functions.
1396 ==============================================================================
1397 ##### LPTIM Read operation functions #####
1398 ==============================================================================
1399 [..] This section provides LPTIM Reading functions.
1400 (+) Read the counter value.
1401 (+) Read the period (Auto-reload) value.
1402 (+) Read the pulse (Compare)value.
1408 * @brief Return the current counter value.
1409 * @param hlptim LPTIM handle
1410 * @retval Counter value.
1412 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef
*hlptim
)
1414 /* Check the parameters */
1415 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1417 return (hlptim
->Instance
->CNT
);
1421 * @brief Return the current Autoreload (Period) value.
1422 * @param hlptim LPTIM handle
1423 * @retval Autoreload value.
1425 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef
*hlptim
)
1427 /* Check the parameters */
1428 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1430 return (hlptim
->Instance
->ARR
);
1434 * @brief Return the current Compare (Pulse) value.
1435 * @param hlptim LPTIM handle
1436 * @retval Compare value.
1438 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef
*hlptim
)
1440 /* Check the parameters */
1441 assert_param(IS_LPTIM_INSTANCE(hlptim
->Instance
));
1443 return (hlptim
->Instance
->CMP
);
1450 /** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks
1451 * @brief LPTIM IRQ handler.
1454 ==============================================================================
1455 ##### LPTIM IRQ handler and callbacks #####
1456 ==============================================================================
1457 [..] This section provides LPTIM IRQ handler and callback functions called within
1459 (+) LPTIM interrupt request handler
1460 (+) Compare match Callback
1461 (+) Auto-reload match Callback
1462 (+) External trigger event detection Callback
1463 (+) Compare register write complete Callback
1464 (+) Auto-reload register write complete Callback
1465 (+) Up-counting direction change Callback
1466 (+) Down-counting direction change Callback
1473 * @brief Handle LPTIM interrupt request.
1474 * @param hlptim LPTIM handle
1477 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef
*hlptim
)
1479 /* Compare match interrupt */
1480 if (__HAL_LPTIM_GET_FLAG(hlptim
, LPTIM_FLAG_CMPM
) != RESET
)
1482 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim
, LPTIM_IT_CMPM
) != RESET
)
1484 /* Clear Compare match flag */
1485 __HAL_LPTIM_CLEAR_FLAG(hlptim
, LPTIM_FLAG_CMPM
);
1487 /* Compare match Callback */
1488 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1489 hlptim
->CompareMatchCallback(hlptim
);
1491 HAL_LPTIM_CompareMatchCallback(hlptim
);
1492 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1496 /* Autoreload match interrupt */
1497 if (__HAL_LPTIM_GET_FLAG(hlptim
, LPTIM_FLAG_ARRM
) != RESET
)
1499 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim
, LPTIM_IT_ARRM
) != RESET
)
1501 /* Clear Autoreload match flag */
1502 __HAL_LPTIM_CLEAR_FLAG(hlptim
, LPTIM_FLAG_ARRM
);
1504 /* Autoreload match Callback */
1505 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1506 hlptim
->AutoReloadMatchCallback(hlptim
);
1508 HAL_LPTIM_AutoReloadMatchCallback(hlptim
);
1509 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1513 /* Trigger detected interrupt */
1514 if (__HAL_LPTIM_GET_FLAG(hlptim
, LPTIM_FLAG_EXTTRIG
) != RESET
)
1516 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim
, LPTIM_IT_EXTTRIG
) != RESET
)
1518 /* Clear Trigger detected flag */
1519 __HAL_LPTIM_CLEAR_FLAG(hlptim
, LPTIM_FLAG_EXTTRIG
);
1521 /* Trigger detected callback */
1522 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1523 hlptim
->TriggerCallback(hlptim
);
1525 HAL_LPTIM_TriggerCallback(hlptim
);
1526 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1530 /* Compare write interrupt */
1531 if (__HAL_LPTIM_GET_FLAG(hlptim
, LPTIM_FLAG_CMPOK
) != RESET
)
1533 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim
, LPTIM_IT_CMPOK
) != RESET
)
1535 /* Clear Compare write flag */
1536 __HAL_LPTIM_CLEAR_FLAG(hlptim
, LPTIM_FLAG_CMPOK
);
1538 /* Compare write Callback */
1539 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1540 hlptim
->CompareWriteCallback(hlptim
);
1542 HAL_LPTIM_CompareWriteCallback(hlptim
);
1543 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1547 /* Autoreload write interrupt */
1548 if (__HAL_LPTIM_GET_FLAG(hlptim
, LPTIM_FLAG_ARROK
) != RESET
)
1550 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim
, LPTIM_IT_ARROK
) != RESET
)
1552 /* Clear Autoreload write flag */
1553 __HAL_LPTIM_CLEAR_FLAG(hlptim
, LPTIM_FLAG_ARROK
);
1555 /* Autoreload write Callback */
1556 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1557 hlptim
->AutoReloadWriteCallback(hlptim
);
1559 HAL_LPTIM_AutoReloadWriteCallback(hlptim
);
1560 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1564 /* Direction counter changed from Down to Up interrupt */
1565 if (__HAL_LPTIM_GET_FLAG(hlptim
, LPTIM_FLAG_UP
) != RESET
)
1567 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim
, LPTIM_IT_UP
) != RESET
)
1569 /* Clear Direction counter changed from Down to Up flag */
1570 __HAL_LPTIM_CLEAR_FLAG(hlptim
, LPTIM_FLAG_UP
);
1572 /* Direction counter changed from Down to Up Callback */
1573 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1574 hlptim
->DirectionUpCallback(hlptim
);
1576 HAL_LPTIM_DirectionUpCallback(hlptim
);
1577 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1581 /* Direction counter changed from Up to Down interrupt */
1582 if (__HAL_LPTIM_GET_FLAG(hlptim
, LPTIM_FLAG_DOWN
) != RESET
)
1584 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim
, LPTIM_IT_DOWN
) != RESET
)
1586 /* Clear Direction counter changed from Up to Down flag */
1587 __HAL_LPTIM_CLEAR_FLAG(hlptim
, LPTIM_FLAG_DOWN
);
1589 /* Direction counter changed from Up to Down Callback */
1590 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1591 hlptim
->DirectionDownCallback(hlptim
);
1593 HAL_LPTIM_DirectionDownCallback(hlptim
);
1594 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1600 * @brief Compare match callback in non-blocking mode.
1601 * @param hlptim LPTIM handle
1604 __weak
void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef
*hlptim
)
1606 /* Prevent unused argument(s) compilation warning */
1609 /* NOTE : This function should not be modified, when the callback is needed,
1610 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
1615 * @brief Autoreload match callback in non-blocking mode.
1616 * @param hlptim LPTIM handle
1619 __weak
void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef
*hlptim
)
1621 /* Prevent unused argument(s) compilation warning */
1624 /* NOTE : This function should not be modified, when the callback is needed,
1625 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
1630 * @brief Trigger detected callback in non-blocking mode.
1631 * @param hlptim LPTIM handle
1634 __weak
void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef
*hlptim
)
1636 /* Prevent unused argument(s) compilation warning */
1639 /* NOTE : This function should not be modified, when the callback is needed,
1640 the HAL_LPTIM_TriggerCallback could be implemented in the user file
1645 * @brief Compare write callback in non-blocking mode.
1646 * @param hlptim LPTIM handle
1649 __weak
void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef
*hlptim
)
1651 /* Prevent unused argument(s) compilation warning */
1654 /* NOTE : This function should not be modified, when the callback is needed,
1655 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
1660 * @brief Autoreload write callback in non-blocking mode.
1661 * @param hlptim LPTIM handle
1664 __weak
void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef
*hlptim
)
1666 /* Prevent unused argument(s) compilation warning */
1669 /* NOTE : This function should not be modified, when the callback is needed,
1670 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
1675 * @brief Direction counter changed from Down to Up callback in non-blocking mode.
1676 * @param hlptim LPTIM handle
1679 __weak
void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef
*hlptim
)
1681 /* Prevent unused argument(s) compilation warning */
1684 /* NOTE : This function should not be modified, when the callback is needed,
1685 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
1690 * @brief Direction counter changed from Up to Down callback in non-blocking mode.
1691 * @param hlptim LPTIM handle
1694 __weak
void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef
*hlptim
)
1696 /* Prevent unused argument(s) compilation warning */
1699 /* NOTE : This function should not be modified, when the callback is needed,
1700 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
1704 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1706 * @brief Register a User LPTIM callback to be used instead of the weak predefined callback
1707 * @param hlptim LPTIM handle
1708 * @param CallbackID ID of the callback to be registered
1709 * This parameter can be one of the following values:
1710 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
1711 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
1712 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID
1713 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
1714 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID
1715 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID
1716 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
1717 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID
1718 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID
1719 * @param pCallback pointer to the callback function
1722 HAL_StatusTypeDef
HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef
*hlptim
,
1723 HAL_LPTIM_CallbackIDTypeDef CallbackID
,
1724 pLPTIM_CallbackTypeDef pCallback
)
1726 HAL_StatusTypeDef status
= HAL_OK
;
1728 if (pCallback
== NULL
)
1733 /* Process locked */
1736 if (hlptim
->State
== HAL_LPTIM_STATE_READY
)
1740 case HAL_LPTIM_MSPINIT_CB_ID
:
1741 hlptim
->MspInitCallback
= pCallback
;
1744 case HAL_LPTIM_MSPDEINIT_CB_ID
:
1745 hlptim
->MspDeInitCallback
= pCallback
;
1748 case HAL_LPTIM_COMPARE_MATCH_CB_ID
:
1749 hlptim
->CompareMatchCallback
= pCallback
;
1752 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID
:
1753 hlptim
->AutoReloadMatchCallback
= pCallback
;
1756 case HAL_LPTIM_TRIGGER_CB_ID
:
1757 hlptim
->TriggerCallback
= pCallback
;
1760 case HAL_LPTIM_COMPARE_WRITE_CB_ID
:
1761 hlptim
->CompareWriteCallback
= pCallback
;
1764 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID
:
1765 hlptim
->AutoReloadWriteCallback
= pCallback
;
1768 case HAL_LPTIM_DIRECTION_UP_CB_ID
:
1769 hlptim
->DirectionUpCallback
= pCallback
;
1772 case HAL_LPTIM_DIRECTION_DOWN_CB_ID
:
1773 hlptim
->DirectionDownCallback
= pCallback
;
1777 /* Return error status */
1782 else if (hlptim
->State
== HAL_LPTIM_STATE_RESET
)
1786 case HAL_LPTIM_MSPINIT_CB_ID
:
1787 hlptim
->MspInitCallback
= pCallback
;
1790 case HAL_LPTIM_MSPDEINIT_CB_ID
:
1791 hlptim
->MspDeInitCallback
= pCallback
;
1795 /* Return error status */
1802 /* Return error status */
1807 __HAL_UNLOCK(hlptim
);
1813 * @brief Unregister a LPTIM callback
1814 * LLPTIM callback is redirected to the weak predefined callback
1815 * @param hlptim LPTIM handle
1816 * @param CallbackID ID of the callback to be unregistered
1817 * This parameter can be one of the following values:
1818 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
1819 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
1820 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID
1821 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
1822 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID
1823 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID
1824 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
1825 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID
1826 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID
1829 HAL_StatusTypeDef
HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef
*hlptim
,
1830 HAL_LPTIM_CallbackIDTypeDef CallbackID
)
1832 HAL_StatusTypeDef status
= HAL_OK
;
1834 /* Process locked */
1837 if (hlptim
->State
== HAL_LPTIM_STATE_READY
)
1841 case HAL_LPTIM_MSPINIT_CB_ID
:
1842 hlptim
->MspInitCallback
= HAL_LPTIM_MspInit
; /* Legacy weak MspInit Callback */
1845 case HAL_LPTIM_MSPDEINIT_CB_ID
:
1846 hlptim
->MspDeInitCallback
= HAL_LPTIM_MspDeInit
; /* Legacy weak Msp DeInit Callback */
1849 case HAL_LPTIM_COMPARE_MATCH_CB_ID
:
1850 hlptim
->CompareMatchCallback
= HAL_LPTIM_CompareMatchCallback
; /* Legacy weak Compare match Callback */
1853 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID
:
1854 hlptim
->AutoReloadMatchCallback
= HAL_LPTIM_AutoReloadMatchCallback
; /* Legacy weak Auto-reload match Callback */
1857 case HAL_LPTIM_TRIGGER_CB_ID
:
1858 hlptim
->TriggerCallback
= HAL_LPTIM_TriggerCallback
; /* Legacy weak External trigger event detection Callback */
1861 case HAL_LPTIM_COMPARE_WRITE_CB_ID
:
1862 hlptim
->CompareWriteCallback
= HAL_LPTIM_CompareWriteCallback
; /* Legacy weak Compare register write complete Callback */
1865 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID
:
1866 hlptim
->AutoReloadWriteCallback
= HAL_LPTIM_AutoReloadWriteCallback
; /* Legacy weak Auto-reload register write complete Callback */
1869 case HAL_LPTIM_DIRECTION_UP_CB_ID
:
1870 hlptim
->DirectionUpCallback
= HAL_LPTIM_DirectionUpCallback
; /* Legacy weak Up-counting direction change Callback */
1873 case HAL_LPTIM_DIRECTION_DOWN_CB_ID
:
1874 hlptim
->DirectionDownCallback
= HAL_LPTIM_DirectionDownCallback
; /* Legacy weak Down-counting direction change Callback */
1878 /* Return error status */
1883 else if (hlptim
->State
== HAL_LPTIM_STATE_RESET
)
1887 case HAL_LPTIM_MSPINIT_CB_ID
:
1888 hlptim
->MspInitCallback
= HAL_LPTIM_MspInit
; /* Legacy weak MspInit Callback */
1891 case HAL_LPTIM_MSPDEINIT_CB_ID
:
1892 hlptim
->MspDeInitCallback
= HAL_LPTIM_MspDeInit
; /* Legacy weak Msp DeInit Callback */
1896 /* Return error status */
1903 /* Return error status */
1908 __HAL_UNLOCK(hlptim
);
1912 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1918 /** @defgroup LPTIM_Group5 Peripheral State functions
1919 * @brief Peripheral State functions.
1922 ==============================================================================
1923 ##### Peripheral State functions #####
1924 ==============================================================================
1926 This subsection permits to get in run-time the status of the peripheral.
1933 * @brief Return the LPTIM handle state.
1934 * @param hlptim LPTIM handle
1937 HAL_LPTIM_StateTypeDef
HAL_LPTIM_GetState(LPTIM_HandleTypeDef
*hlptim
)
1939 /* Return LPTIM handle state */
1940 return hlptim
->State
;
1952 /* Private functions ---------------------------------------------------------*/
1954 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
1957 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1959 * @brief Reset interrupt callbacks to the legacy weak callbacks.
1960 * @param lptim pointer to a LPTIM_HandleTypeDef structure that contains
1961 * the configuration information for LPTIM module.
1964 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef
*lptim
)
1966 /* Reset the LPTIM callback to the legacy weak callbacks */
1967 lptim
->CompareMatchCallback
= HAL_LPTIM_CompareMatchCallback
; /* Compare match Callback */
1968 lptim
->AutoReloadMatchCallback
= HAL_LPTIM_AutoReloadMatchCallback
; /* Auto-reload match Callback */
1969 lptim
->TriggerCallback
= HAL_LPTIM_TriggerCallback
; /* External trigger event detection Callback */
1970 lptim
->CompareWriteCallback
= HAL_LPTIM_CompareWriteCallback
; /* Compare register write complete Callback */
1971 lptim
->AutoReloadWriteCallback
= HAL_LPTIM_AutoReloadWriteCallback
; /* Auto-reload register write complete Callback */
1972 lptim
->DirectionUpCallback
= HAL_LPTIM_DirectionUpCallback
; /* Up-counting direction change Callback */
1973 lptim
->DirectionDownCallback
= HAL_LPTIM_DirectionDownCallback
; /* Down-counting direction change Callback */
1975 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1978 * @brief Disable LPTIM HW instance.
1979 * @param lptim pointer to a LPTIM_HandleTypeDef structure that contains
1980 * the configuration information for LPTIM module.
1981 * @note The following sequence is required to solve LPTIM disable HW limitation.
1982 * Please check Errata Sheet ES0335 for more details under "MCU may remain
1983 * stuck in LPTIM interrupt when entering Stop mode" section.
1986 void LPTIM_Disable(LPTIM_HandleTypeDef
*lptim
)
1988 uint32_t tmpclksource
= 0;
1997 /*********** Save LPTIM Config ***********/
1998 /* Save LPTIM source clock */
1999 switch ((uint32_t)lptim
->Instance
)
2002 tmpclksource
= __HAL_RCC_GET_LPTIM1_SOURCE();
2008 /* Save LPTIM configuration registers */
2009 tmpIER
= lptim
->Instance
->IER
;
2010 tmpCFGR
= lptim
->Instance
->CFGR
;
2011 tmpCMP
= lptim
->Instance
->CMP
;
2012 tmpARR
= lptim
->Instance
->ARR
;
2013 tmpOR
= lptim
->Instance
->OR
;
2015 /*********** Reset LPTIM ***********/
2016 switch ((uint32_t)lptim
->Instance
)
2019 __HAL_RCC_LPTIM1_FORCE_RESET();
2020 __HAL_RCC_LPTIM1_RELEASE_RESET();
2026 /*********** Restore LPTIM Config ***********/
2028 uint32_t Time_Elapsed
;
2030 if ((tmpCMP
!= 0UL) || (tmpARR
!= 0UL))
2032 /* Force LPTIM source kernel clock from APB */
2033 switch ((uint32_t)lptim
->Instance
)
2036 __HAL_RCC_LPTIM1_CONFIG(RCC_LPTIM1CLKSOURCE_PCLK1
);
2044 /* Restore CMP register (LPTIM should be enabled first) */
2045 lptim
->Instance
->CR
|= LPTIM_CR_ENABLE
;
2046 lptim
->Instance
->CMP
= tmpCMP
;
2047 /* Polling on CMP write ok status after above restore operation */
2048 Ref_Time
= HAL_GetTick();
2051 Time_Elapsed
= HAL_GetTick() - Ref_Time
;
2052 } while ((!(__HAL_LPTIM_GET_FLAG(lptim
, LPTIM_FLAG_CMPOK
))) && (Time_Elapsed
<= TIMEOUT
));
2054 __HAL_LPTIM_CLEAR_FLAG(lptim
, LPTIM_FLAG_CMPOK
);
2059 /* Restore ARR register (LPTIM should be enabled first) */
2060 lptim
->Instance
->CR
|= LPTIM_CR_ENABLE
;
2061 lptim
->Instance
->ARR
= tmpARR
;
2062 /* Polling on ARR write ok status after above restore operation */
2063 Ref_Time
= HAL_GetTick();
2066 Time_Elapsed
= HAL_GetTick() - Ref_Time
;
2067 } while ((!(__HAL_LPTIM_GET_FLAG(lptim
, LPTIM_FLAG_ARROK
))) && (Time_Elapsed
<= TIMEOUT
));
2069 __HAL_LPTIM_CLEAR_FLAG(lptim
, LPTIM_FLAG_ARROK
);
2072 /* Restore LPTIM source kernel clock */
2073 switch ((uint32_t)lptim
->Instance
)
2076 __HAL_RCC_LPTIM1_CONFIG(tmpclksource
);
2083 /* Restore configuration registers (LPTIM should be disabled first) */
2084 lptim
->Instance
->CR
&= ~(LPTIM_CR_ENABLE
);
2085 lptim
->Instance
->IER
= tmpIER
;
2086 lptim
->Instance
->CFGR
= tmpCFGR
;
2087 lptim
->Instance
->OR
= tmpOR
;
2096 #endif /* HAL_LPTIM_MODULE_ENABLED */
2105 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/