1 | /**
|
---|
2 | ******************************************************************************
|
---|
3 | * @file stm32f4xx_hal_lptim.c
|
---|
4 | * @author MCD Application Team
|
---|
5 | * @version V1.4.1
|
---|
6 | * @date 09-October-2015
|
---|
7 | * @brief LPTIM HAL module driver.
|
---|
8 | *
|
---|
9 | * This file provides firmware functions to manage the following
|
---|
10 | * functionalities of the Low Power Timer (LPTIM) peripheral:
|
---|
11 | * + Initialization and de-initialization functions.
|
---|
12 | * + Start/Stop operation functions in polling mode.
|
---|
13 | * + Start/Stop operation functions in interrupt mode.
|
---|
14 | * + Reading operation functions.
|
---|
15 | * + Peripheral State functions.
|
---|
16 | *
|
---|
17 | @verbatim
|
---|
18 | ==============================================================================
|
---|
19 | ##### How to use this driver #####
|
---|
20 | ==============================================================================
|
---|
21 | [..]
|
---|
22 | The LPTIM HAL driver can be used as follows:
|
---|
23 |
|
---|
24 | (#)Initialize the LPTIM low level resources by implementing the
|
---|
25 | HAL_LPTIM_MspInit():
|
---|
26 | (##) Enable the LPTIM interface clock using __LPTIMx_CLK_ENABLE().
|
---|
27 | (##) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
|
---|
28 | (+) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
|
---|
29 | (+) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
|
---|
30 | (+) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
|
---|
31 |
|
---|
32 | (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
|
---|
33 | configures mainly:
|
---|
34 | (##) The instance: LPTIM1.
|
---|
35 | (##) Clock: the counter clock.
|
---|
36 | - Source : it can be either the ULPTIM input (IN1) or one of
|
---|
37 | the internal clock; (APB, LSE, LSI or MSI).
|
---|
38 | - Prescaler: select the clock divider.
|
---|
39 | (##) UltraLowPowerClock : To be used only if the ULPTIM is selected
|
---|
40 | as counter clock source.
|
---|
41 | - Polarity: polarity of the active edge for the counter unit
|
---|
42 | if the ULPTIM input is selected.
|
---|
43 | - SampleTime: clock sampling time to configure the clock glitch
|
---|
44 | filter.
|
---|
45 | (##) Trigger: How the counter start.
|
---|
46 | - Source: trigger can be software or one of the hardware triggers.
|
---|
47 | - ActiveEdge : only for hardware trigger.
|
---|
48 | - SampleTime : trigger sampling time to configure the trigger
|
---|
49 | glitch filter.
|
---|
50 | (##) OutputPolarity : 2 opposite polarities are possibles.
|
---|
51 | (##) UpdateMode: specifies whether the update of the autoreload and
|
---|
52 | the compare values is done immediately or after the end of current
|
---|
53 | period.
|
---|
54 |
|
---|
55 | (#)Six modes are available:
|
---|
56 |
|
---|
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.
|
---|
60 |
|
---|
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.
|
---|
64 |
|
---|
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.
|
---|
70 |
|
---|
71 | (##) Encoder Mode: To use the encoder interface call
|
---|
72 | HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
|
---|
73 | interruption mode.
|
---|
74 |
|
---|
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.
|
---|
80 |
|
---|
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.
|
---|
85 |
|
---|
86 | (#) User can stop any process by calling the corresponding API:
|
---|
87 | HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
|
---|
88 | already started in interruption mode.
|
---|
89 |
|
---|
90 | (#)Call HAL_LPTIM_DeInit() to deinitialize the LPTIM peripheral.
|
---|
91 |
|
---|
92 | @endverbatim
|
---|
93 | ******************************************************************************
|
---|
94 | * @attention
|
---|
95 | *
|
---|
96 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
---|
97 | *
|
---|
98 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
99 | * are permitted provided that the following conditions are met:
|
---|
100 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
101 | * this list of conditions and the following disclaimer.
|
---|
102 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
103 | * this list of conditions and the following disclaimer in the documentation
|
---|
104 | * and/or other materials provided with the distribution.
|
---|
105 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
---|
106 | * may be used to endorse or promote products derived from this software
|
---|
107 | * without specific prior written permission.
|
---|
108 | *
|
---|
109 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
110 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
111 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
112 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
---|
113 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
114 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
115 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
116 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
117 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
118 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
119 | *
|
---|
120 | ******************************************************************************
|
---|
121 | */
|
---|
122 |
|
---|
123 | /* Includes ------------------------------------------------------------------*/
|
---|
124 | #include "stm32f4xx_hal.h"
|
---|
125 |
|
---|
126 | /** @addtogroup STM32F4xx_HAL_Driver
|
---|
127 | * @{
|
---|
128 | */
|
---|
129 |
|
---|
130 | /** @defgroup LPTIM LPTIM
|
---|
131 | * @brief LPTIM HAL module driver.
|
---|
132 | * @{
|
---|
133 | */
|
---|
134 |
|
---|
135 | #ifdef HAL_LPTIM_MODULE_ENABLED
|
---|
136 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx)
|
---|
137 | /* Private types -------------------------------------------------------------*/
|
---|
138 | /** @defgroup LPTIM_Private_Types LPTIM Private Types
|
---|
139 | * @{
|
---|
140 | */
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * @}
|
---|
144 | */
|
---|
145 |
|
---|
146 | /* Private defines -----------------------------------------------------------*/
|
---|
147 | /** @defgroup LPTIM_Private_Defines LPTIM Private Defines
|
---|
148 | * @{
|
---|
149 | */
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * @}
|
---|
153 | */
|
---|
154 |
|
---|
155 | /* Private variables ---------------------------------------------------------*/
|
---|
156 | /** @addtogroup LPTIM_Private_Variables LPTIM Private Variables
|
---|
157 | * @{
|
---|
158 | */
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * @}
|
---|
162 | */
|
---|
163 |
|
---|
164 | /* Private constants ---------------------------------------------------------*/
|
---|
165 | /** @addtogroup LPTIM_Private_Constants LPTIM Private Constants
|
---|
166 | * @{
|
---|
167 | */
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * @}
|
---|
171 | */
|
---|
172 |
|
---|
173 | /* Private macros ------------------------------------------------------------*/
|
---|
174 | /** @addtogroup LPTIM_Private_Macros LPTIM Private Macros
|
---|
175 | * @{
|
---|
176 | */
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * @}
|
---|
180 | */
|
---|
181 |
|
---|
182 | /* Private function prototypes -----------------------------------------------*/
|
---|
183 | /** @addtogroup LPTIM_Private_Functions_Prototypes LPTIM Private Functions Prototypes
|
---|
184 | * @{
|
---|
185 | */
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * @}
|
---|
189 | */
|
---|
190 |
|
---|
191 | /* Private functions ---------------------------------------------------------*/
|
---|
192 | /** @addtogroup LPTIM_Private_Functions LPTIM Private Functions
|
---|
193 | * @{
|
---|
194 | */
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * @}
|
---|
198 | */
|
---|
199 |
|
---|
200 | /* Exported functions ---------------------------------------------------------*/
|
---|
201 | /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
|
---|
202 | * @{
|
---|
203 | */
|
---|
204 |
|
---|
205 | /** @defgroup LPTIM_Group1 Initialization/de-initialization functions
|
---|
206 | * @brief Initialization and Configuration functions.
|
---|
207 | *
|
---|
208 | @verbatim
|
---|
209 | ==============================================================================
|
---|
210 | ##### Initialization and de-initialization functions #####
|
---|
211 | ==============================================================================
|
---|
212 | [..] This section provides functions allowing to:
|
---|
213 | (+) Initialize the LPTIM according to the specified parameters in the
|
---|
214 | LPTIM_InitTypeDef and creates the associated handle.
|
---|
215 | (+) DeInitialize the LPTIM peripheral.
|
---|
216 | (+) Initialize the LPTIM MSP.
|
---|
217 | (+) DeInitialize LPTIM MSP.
|
---|
218 |
|
---|
219 | @endverbatim
|
---|
220 | * @{
|
---|
221 | */
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * @brief Initializes the LPTIM according to the specified parameters in the
|
---|
225 | * LPTIM_InitTypeDef and creates the associated handle.
|
---|
226 | * @param hlptim: LPTIM handle
|
---|
227 | * @retval HAL status
|
---|
228 | */
|
---|
229 | HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
|
---|
230 | {
|
---|
231 | uint32_t tmpcfgr = 0;
|
---|
232 |
|
---|
233 | /* Check the LPTIM handle allocation */
|
---|
234 | if(hlptim == NULL)
|
---|
235 | {
|
---|
236 | return HAL_ERROR;
|
---|
237 | }
|
---|
238 |
|
---|
239 | /* Check the parameters */
|
---|
240 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
241 |
|
---|
242 | assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
|
---|
243 | assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));
|
---|
244 | if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
|
---|
245 | {
|
---|
246 | assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
|
---|
247 | assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
|
---|
248 | }
|
---|
249 | assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
|
---|
250 | if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
|
---|
251 | {
|
---|
252 | assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
|
---|
253 | assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
|
---|
254 | }
|
---|
255 | assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));
|
---|
256 | assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
|
---|
257 | assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
|
---|
258 |
|
---|
259 | if(hlptim->State == HAL_LPTIM_STATE_RESET)
|
---|
260 | {
|
---|
261 | /* Allocate lock resource and initialize it */
|
---|
262 | hlptim->Lock = HAL_UNLOCKED;
|
---|
263 | /* Init the low level hardware */
|
---|
264 | HAL_LPTIM_MspInit(hlptim);
|
---|
265 | }
|
---|
266 |
|
---|
267 | /* Change the LPTIM state */
|
---|
268 | hlptim->State = HAL_LPTIM_STATE_BUSY;
|
---|
269 |
|
---|
270 | /* Get the LPTIMx CFGR value */
|
---|
271 | tmpcfgr = hlptim->Instance->CFGR;
|
---|
272 |
|
---|
273 | if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
|
---|
274 | {
|
---|
275 | tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
|
---|
276 | }
|
---|
277 | if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
|
---|
278 | {
|
---|
279 | tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
|
---|
280 | }
|
---|
281 |
|
---|
282 | /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
|
---|
283 | tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
|
---|
284 | LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE ));
|
---|
285 |
|
---|
286 | /* Set initialization parameters */
|
---|
287 | tmpcfgr |= (hlptim->Init.Clock.Source |
|
---|
288 | hlptim->Init.Clock.Prescaler |
|
---|
289 | hlptim->Init.OutputPolarity |
|
---|
290 | hlptim->Init.UpdateMode |
|
---|
291 | hlptim->Init.CounterSource);
|
---|
292 |
|
---|
293 | if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
|
---|
294 | {
|
---|
295 | tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
|
---|
296 | hlptim->Init.UltraLowPowerClock.SampleTime);
|
---|
297 | }
|
---|
298 |
|
---|
299 | if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
|
---|
300 | {
|
---|
301 | /* Enable External trigger and set the trigger source */
|
---|
302 | tmpcfgr |= (hlptim->Init.Trigger.Source |
|
---|
303 | hlptim->Init.Trigger.ActiveEdge |
|
---|
304 | hlptim->Init.Trigger.SampleTime);
|
---|
305 | }
|
---|
306 |
|
---|
307 | /* Write to LPTIMx CFGR */
|
---|
308 | hlptim->Instance->CFGR = tmpcfgr;
|
---|
309 |
|
---|
310 | /* Change the LPTIM state */
|
---|
311 | hlptim->State = HAL_LPTIM_STATE_READY;
|
---|
312 |
|
---|
313 | /* Return function status */
|
---|
314 | return HAL_OK;
|
---|
315 | }
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * @brief DeInitializes the LPTIM peripheral.
|
---|
319 | * @param hlptim: LPTIM handle
|
---|
320 | * @retval HAL status
|
---|
321 | */
|
---|
322 | HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
|
---|
323 | {
|
---|
324 | /* Check the LPTIM handle allocation */
|
---|
325 | if(hlptim == NULL)
|
---|
326 | {
|
---|
327 | return HAL_ERROR;
|
---|
328 | }
|
---|
329 |
|
---|
330 | /* Change the LPTIM state */
|
---|
331 | hlptim->State = HAL_LPTIM_STATE_BUSY;
|
---|
332 |
|
---|
333 | /* Disable the LPTIM Peripheral Clock */
|
---|
334 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
335 |
|
---|
336 | /* DeInit the low level hardware: CLOCK, NVIC.*/
|
---|
337 | HAL_LPTIM_MspDeInit(hlptim);
|
---|
338 |
|
---|
339 | /* Change the LPTIM state */
|
---|
340 | hlptim->State = HAL_LPTIM_STATE_RESET;
|
---|
341 |
|
---|
342 | /* Release Lock */
|
---|
343 | __HAL_UNLOCK(hlptim);
|
---|
344 |
|
---|
345 | /* Return function status */
|
---|
346 | return HAL_OK;
|
---|
347 | }
|
---|
348 |
|
---|
349 | /**
|
---|
350 | * @brief Initializes the LPTIM MSP.
|
---|
351 | * @param hlptim: LPTIM handle
|
---|
352 | * @retval None
|
---|
353 | */
|
---|
354 | __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
|
---|
355 | {
|
---|
356 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
357 | the HAL_LPTIM_MspInit could be implemented in the user file
|
---|
358 | */
|
---|
359 | }
|
---|
360 |
|
---|
361 | /**
|
---|
362 | * @brief DeInitializes LPTIM MSP.
|
---|
363 | * @param hlptim: LPTIM handle
|
---|
364 | * @retval None
|
---|
365 | */
|
---|
366 | __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
|
---|
367 | {
|
---|
368 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
369 | the HAL_LPTIM_MspDeInit could be implemented in the user file
|
---|
370 | */
|
---|
371 | }
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * @}
|
---|
375 | */
|
---|
376 |
|
---|
377 | /** @defgroup LPTIM_Group2 LPTIM Start-Stop operation functions
|
---|
378 | * @brief Start-Stop operation functions.
|
---|
379 | *
|
---|
380 | @verbatim
|
---|
381 | ==============================================================================
|
---|
382 | ##### LPTIM Start Stop operation functions #####
|
---|
383 | ==============================================================================
|
---|
384 | [..] This section provides functions allowing to:
|
---|
385 | (+) Start the PWM mode.
|
---|
386 | (+) Stop the PWM mode.
|
---|
387 | (+) Start the One pulse mode.
|
---|
388 | (+) Stop the One pulse mode.
|
---|
389 | (+) Start the Set once mode.
|
---|
390 | (+) Stop the Set once mode.
|
---|
391 | (+) Start the Encoder mode.
|
---|
392 | (+) Stop the Encoder mode.
|
---|
393 | (+) Start the Timeout mode.
|
---|
394 | (+) Stop the Timeout mode.
|
---|
395 | (+) Start the Counter mode.
|
---|
396 | (+) Stop the Counter mode.
|
---|
397 |
|
---|
398 |
|
---|
399 | @endverbatim
|
---|
400 | * @{
|
---|
401 | */
|
---|
402 |
|
---|
403 | /**
|
---|
404 | * @brief Starts the LPTIM PWM generation.
|
---|
405 | * @param hlptim : LPTIM handle
|
---|
406 | * @param Period : Specifies the Autoreload value.
|
---|
407 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
408 | * @param Pulse : Specifies the compare value.
|
---|
409 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
410 | * @retval HAL status
|
---|
411 | */
|
---|
412 | HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
|
---|
413 | {
|
---|
414 | /* Check the parameters */
|
---|
415 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
416 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
417 | assert_param(IS_LPTIM_PULSE(Pulse));
|
---|
418 |
|
---|
419 | /* Set the LPTIM state */
|
---|
420 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
421 |
|
---|
422 | /* Reset WAVE bit to set PWM mode */
|
---|
423 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
|
---|
424 |
|
---|
425 | /* Enable the Peripheral */
|
---|
426 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
427 |
|
---|
428 | /* Load the period value in the autoreload register */
|
---|
429 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
430 |
|
---|
431 | /* Load the pulse value in the compare register */
|
---|
432 | __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
|
---|
433 |
|
---|
434 | /* Start timer in continuous mode */
|
---|
435 | __HAL_LPTIM_START_CONTINUOUS(hlptim);
|
---|
436 |
|
---|
437 | /* Change the TIM state*/
|
---|
438 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
439 |
|
---|
440 | /* Return function status */
|
---|
441 | return HAL_OK;
|
---|
442 | }
|
---|
443 |
|
---|
444 | /**
|
---|
445 | * @brief Stops the LPTIM PWM generation.
|
---|
446 | * @param hlptim : LPTIM handle
|
---|
447 | * @retval HAL status
|
---|
448 | */
|
---|
449 | HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
|
---|
450 | {
|
---|
451 | /* Check the parameters */
|
---|
452 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
453 |
|
---|
454 | /* Set the LPTIM state */
|
---|
455 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
456 |
|
---|
457 | /* Disable the Peripheral */
|
---|
458 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
459 |
|
---|
460 | /* Change the TIM state*/
|
---|
461 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
462 |
|
---|
463 | /* Return function status */
|
---|
464 | return HAL_OK;
|
---|
465 | }
|
---|
466 |
|
---|
467 | /**
|
---|
468 | * @brief Starts the LPTIM PWM generation in interrupt mode.
|
---|
469 | * @param hlptim : LPTIM handle
|
---|
470 | * @param Period : Specifies the Autoreload value.
|
---|
471 | * This parameter must be a value between 0x0000 and 0xFFFF
|
---|
472 | * @param Pulse : Specifies the compare value.
|
---|
473 | * This parameter must be a value between 0x0000 and 0xFFFF
|
---|
474 | * @retval HAL status
|
---|
475 | */
|
---|
476 | HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
|
---|
477 | {
|
---|
478 | /* Check the parameters */
|
---|
479 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
480 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
481 | assert_param(IS_LPTIM_PULSE(Pulse));
|
---|
482 |
|
---|
483 | /* Set the LPTIM state */
|
---|
484 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
485 |
|
---|
486 | /* Reset WAVE bit to set PWM mode */
|
---|
487 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
|
---|
488 |
|
---|
489 | /* Enable Autoreload write complete interrupt */
|
---|
490 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
|
---|
491 |
|
---|
492 | /* Enable Compare write complete interrupt */
|
---|
493 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
|
---|
494 |
|
---|
495 | /* Enable Autoreload match interrupt */
|
---|
496 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
|
---|
497 |
|
---|
498 | /* Enable Compare match interrupt */
|
---|
499 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
|
---|
500 |
|
---|
501 | /* If external trigger source is used, then enable external trigger interrupt */
|
---|
502 | if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
|
---|
503 | {
|
---|
504 | /* Enable external trigger interrupt */
|
---|
505 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
|
---|
506 | }
|
---|
507 |
|
---|
508 | /* Enable the Peripheral */
|
---|
509 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
510 |
|
---|
511 | /* Load the period value in the autoreload register */
|
---|
512 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
513 |
|
---|
514 | /* Load the pulse value in the compare register */
|
---|
515 | __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
|
---|
516 |
|
---|
517 | /* Start timer in continuous mode */
|
---|
518 | __HAL_LPTIM_START_CONTINUOUS(hlptim);
|
---|
519 |
|
---|
520 | /* Change the TIM state*/
|
---|
521 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
522 |
|
---|
523 | /* Return function status */
|
---|
524 | return HAL_OK;
|
---|
525 | }
|
---|
526 |
|
---|
527 | /**
|
---|
528 | * @brief Stops the LPTIM PWM generation in interrupt mode.
|
---|
529 | * @param hlptim : LPTIM handle
|
---|
530 | * @retval HAL status
|
---|
531 | */
|
---|
532 | HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
|
---|
533 | {
|
---|
534 | /* Check the parameters */
|
---|
535 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
536 |
|
---|
537 | /* Set the LPTIM state */
|
---|
538 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
539 |
|
---|
540 | /* Disable the Peripheral */
|
---|
541 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
542 |
|
---|
543 | /* Disable Autoreload write complete interrupt */
|
---|
544 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
|
---|
545 |
|
---|
546 | /* Disable Compare write complete interrupt */
|
---|
547 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
|
---|
548 |
|
---|
549 | /* Disable Autoreload match interrupt */
|
---|
550 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
|
---|
551 |
|
---|
552 | /* Disable Compare match interrupt */
|
---|
553 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
|
---|
554 |
|
---|
555 | /* If external trigger source is used, then disable external trigger interrupt */
|
---|
556 | if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
|
---|
557 | {
|
---|
558 | /* Disable external trigger interrupt */
|
---|
559 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
|
---|
560 | }
|
---|
561 |
|
---|
562 | /* Change the TIM state*/
|
---|
563 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
564 |
|
---|
565 | /* Return function status */
|
---|
566 | return HAL_OK;
|
---|
567 | }
|
---|
568 |
|
---|
569 | /**
|
---|
570 | * @brief Starts the LPTIM One pulse generation.
|
---|
571 | * @param hlptim : LPTIM handle
|
---|
572 | * @param Period : Specifies the Autoreload value.
|
---|
573 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
574 | * @param Pulse : Specifies the compare value.
|
---|
575 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
576 | * @retval HAL status
|
---|
577 | */
|
---|
578 | HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
|
---|
579 | {
|
---|
580 | /* Check the parameters */
|
---|
581 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
582 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
583 | assert_param(IS_LPTIM_PULSE(Pulse));
|
---|
584 |
|
---|
585 | /* Set the LPTIM state */
|
---|
586 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
587 |
|
---|
588 | /* Reset WAVE bit to set one pulse mode */
|
---|
589 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
|
---|
590 |
|
---|
591 | /* Enable the Peripheral */
|
---|
592 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
593 |
|
---|
594 | /* Load the period value in the autoreload register */
|
---|
595 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
596 |
|
---|
597 | /* Load the pulse value in the compare register */
|
---|
598 | __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
|
---|
599 |
|
---|
600 | /* Start timer in continuous mode */
|
---|
601 | __HAL_LPTIM_START_SINGLE(hlptim);
|
---|
602 |
|
---|
603 | /* Change the TIM state*/
|
---|
604 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
605 |
|
---|
606 | /* Return function status */
|
---|
607 | return HAL_OK;
|
---|
608 | }
|
---|
609 |
|
---|
610 | /**
|
---|
611 | * @brief Stops the LPTIM One pulse generation.
|
---|
612 | * @param hlptim : LPTIM handle
|
---|
613 | * @retval HAL status
|
---|
614 | */
|
---|
615 | HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
|
---|
616 | {
|
---|
617 | /* Check the parameters */
|
---|
618 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
619 |
|
---|
620 | /* Set the LPTIM state */
|
---|
621 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
622 |
|
---|
623 | /* Disable the Peripheral */
|
---|
624 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
625 |
|
---|
626 | /* Change the TIM state*/
|
---|
627 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
628 |
|
---|
629 | /* Return function status */
|
---|
630 | return HAL_OK;
|
---|
631 | }
|
---|
632 |
|
---|
633 | /**
|
---|
634 | * @brief Starts the LPTIM One pulse generation in interrupt mode.
|
---|
635 | * @param hlptim : LPTIM handle
|
---|
636 | * @param Period : Specifies the Autoreload value.
|
---|
637 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
638 | * @param Pulse : Specifies the compare value.
|
---|
639 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
640 | * @retval HAL status
|
---|
641 | */
|
---|
642 | HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
|
---|
643 | {
|
---|
644 | /* Check the parameters */
|
---|
645 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
646 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
647 | assert_param(IS_LPTIM_PULSE(Pulse));
|
---|
648 |
|
---|
649 | /* Set the LPTIM state */
|
---|
650 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
651 |
|
---|
652 | /* Reset WAVE bit to set one pulse mode */
|
---|
653 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
|
---|
654 |
|
---|
655 | /* Enable Autoreload write complete interrupt */
|
---|
656 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
|
---|
657 |
|
---|
658 | /* Enable Compare write complete interrupt */
|
---|
659 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
|
---|
660 |
|
---|
661 | /* Enable Autoreload match interrupt */
|
---|
662 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
|
---|
663 |
|
---|
664 | /* Enable Compare match interrupt */
|
---|
665 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
|
---|
666 |
|
---|
667 | /* If external trigger source is used, then enable external trigger interrupt */
|
---|
668 | if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
|
---|
669 | {
|
---|
670 | /* Enable external trigger interrupt */
|
---|
671 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
|
---|
672 | }
|
---|
673 |
|
---|
674 | /* Enable the Peripheral */
|
---|
675 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
676 |
|
---|
677 | /* Load the period value in the autoreload register */
|
---|
678 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
679 |
|
---|
680 | /* Load the pulse value in the compare register */
|
---|
681 | __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
|
---|
682 |
|
---|
683 | /* Start timer in continuous mode */
|
---|
684 | __HAL_LPTIM_START_SINGLE(hlptim);
|
---|
685 |
|
---|
686 | /* Change the TIM state*/
|
---|
687 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
688 |
|
---|
689 | /* Return function status */
|
---|
690 | return HAL_OK;
|
---|
691 | }
|
---|
692 |
|
---|
693 | /**
|
---|
694 | * @brief Stops the LPTIM One pulse generation in interrupt mode.
|
---|
695 | * @param hlptim : LPTIM handle
|
---|
696 | * @retval HAL status
|
---|
697 | */
|
---|
698 | HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
|
---|
699 | {
|
---|
700 | /* Check the parameters */
|
---|
701 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
702 |
|
---|
703 | /* Set the LPTIM state */
|
---|
704 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
705 |
|
---|
706 | /* Disable the Peripheral */
|
---|
707 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
708 |
|
---|
709 | /* Disable Autoreload write complete interrupt */
|
---|
710 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
|
---|
711 |
|
---|
712 | /* Disable Compare write complete interrupt */
|
---|
713 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
|
---|
714 |
|
---|
715 | /* Disable Autoreload match interrupt */
|
---|
716 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
|
---|
717 |
|
---|
718 | /* Disable Compare match interrupt */
|
---|
719 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
|
---|
720 |
|
---|
721 | /* If external trigger source is used, then disable external trigger interrupt */
|
---|
722 | if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
|
---|
723 | {
|
---|
724 | /* Disable external trigger interrupt */
|
---|
725 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
|
---|
726 | }
|
---|
727 |
|
---|
728 | /* Change the TIM state*/
|
---|
729 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
730 |
|
---|
731 | /* Return function status */
|
---|
732 | return HAL_OK;
|
---|
733 | }
|
---|
734 |
|
---|
735 | /**
|
---|
736 | * @brief Starts the LPTIM in Set once mode.
|
---|
737 | * @param hlptim : LPTIM handle
|
---|
738 | * @param Period : Specifies the Autoreload value.
|
---|
739 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
740 | * @param Pulse : Specifies the compare value.
|
---|
741 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
742 | * @retval HAL status
|
---|
743 | */
|
---|
744 | HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
|
---|
745 | {
|
---|
746 | /* Check the parameters */
|
---|
747 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
748 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
749 | assert_param(IS_LPTIM_PULSE(Pulse));
|
---|
750 |
|
---|
751 | /* Set the LPTIM state */
|
---|
752 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
753 |
|
---|
754 | /* Set WAVE bit to enable the set once mode */
|
---|
755 | hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
|
---|
756 |
|
---|
757 | /* Enable the Peripheral */
|
---|
758 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
759 |
|
---|
760 | /* Load the period value in the autoreload register */
|
---|
761 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
762 |
|
---|
763 | /* Load the pulse value in the compare register */
|
---|
764 | __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
|
---|
765 |
|
---|
766 | /* Start timer in single mode */
|
---|
767 | __HAL_LPTIM_START_SINGLE(hlptim);
|
---|
768 |
|
---|
769 | /* Change the TIM state*/
|
---|
770 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
771 |
|
---|
772 | /* Return function status */
|
---|
773 | return HAL_OK;
|
---|
774 | }
|
---|
775 |
|
---|
776 | /**
|
---|
777 | * @brief Stops the LPTIM Set once mode.
|
---|
778 | * @param hlptim : LPTIM handle
|
---|
779 | * @retval HAL status
|
---|
780 | */
|
---|
781 | HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
|
---|
782 | {
|
---|
783 | /* Check the parameters */
|
---|
784 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
785 |
|
---|
786 | /* Set the LPTIM state */
|
---|
787 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
788 |
|
---|
789 | /* Disable the Peripheral */
|
---|
790 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
791 |
|
---|
792 | /* Change the TIM state*/
|
---|
793 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
794 |
|
---|
795 | /* Return function status */
|
---|
796 | return HAL_OK;
|
---|
797 | }
|
---|
798 |
|
---|
799 | /**
|
---|
800 | * @brief Starts the LPTIM Set once mode in interrupt mode.
|
---|
801 | * @param hlptim : LPTIM handle
|
---|
802 | * @param Period : Specifies the Autoreload value.
|
---|
803 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
804 | * @param Pulse : Specifies the compare value.
|
---|
805 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
806 | * @retval HAL status
|
---|
807 | */
|
---|
808 | HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
|
---|
809 | {
|
---|
810 | /* Check the parameters */
|
---|
811 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
812 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
813 | assert_param(IS_LPTIM_PULSE(Pulse));
|
---|
814 |
|
---|
815 | /* Set the LPTIM state */
|
---|
816 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
817 |
|
---|
818 | /* Set WAVE bit to enable the set once mode */
|
---|
819 | hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
|
---|
820 |
|
---|
821 | /* Enable Autoreload write complete interrupt */
|
---|
822 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
|
---|
823 |
|
---|
824 | /* Enable Compare write complete interrupt */
|
---|
825 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
|
---|
826 |
|
---|
827 | /* Enable Autoreload match interrupt */
|
---|
828 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
|
---|
829 |
|
---|
830 | /* Enable Compare match interrupt */
|
---|
831 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
|
---|
832 |
|
---|
833 | /* If external trigger source is used, then enable external trigger interrupt */
|
---|
834 | if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
|
---|
835 | {
|
---|
836 | /* Enable external trigger interrupt */
|
---|
837 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
|
---|
838 | }
|
---|
839 |
|
---|
840 | /* Enable the Peripheral */
|
---|
841 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
842 |
|
---|
843 | /* Load the period value in the autoreload register */
|
---|
844 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
845 |
|
---|
846 | /* Load the pulse value in the compare register */
|
---|
847 | __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
|
---|
848 |
|
---|
849 | /* Start timer in single mode */
|
---|
850 | __HAL_LPTIM_START_SINGLE(hlptim);
|
---|
851 |
|
---|
852 | /* Change the TIM state*/
|
---|
853 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
854 |
|
---|
855 | /* Return function status */
|
---|
856 | return HAL_OK;
|
---|
857 | }
|
---|
858 |
|
---|
859 | /**
|
---|
860 | * @brief Stops the LPTIM Set once mode in interrupt mode.
|
---|
861 | * @param hlptim : LPTIM handle
|
---|
862 | * @retval HAL status
|
---|
863 | */
|
---|
864 | HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
|
---|
865 | {
|
---|
866 | /* Check the parameters */
|
---|
867 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
868 |
|
---|
869 | /* Set the LPTIM state */
|
---|
870 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
871 |
|
---|
872 | /* Disable the Peripheral */
|
---|
873 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
874 |
|
---|
875 | /* Disable Autoreload write complete interrupt */
|
---|
876 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
|
---|
877 |
|
---|
878 | /* Disable Compare write complete interrupt */
|
---|
879 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
|
---|
880 |
|
---|
881 | /* Disable Autoreload match interrupt */
|
---|
882 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
|
---|
883 |
|
---|
884 | /* Disable Compare match interrupt */
|
---|
885 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
|
---|
886 |
|
---|
887 | /* If external trigger source is used, then disable external trigger interrupt */
|
---|
888 | if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
|
---|
889 | {
|
---|
890 | /* Disable external trigger interrupt */
|
---|
891 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
|
---|
892 | }
|
---|
893 |
|
---|
894 | /* Change the TIM state*/
|
---|
895 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
896 |
|
---|
897 | /* Return function status */
|
---|
898 | return HAL_OK;
|
---|
899 | }
|
---|
900 |
|
---|
901 | /**
|
---|
902 | * @brief Starts the Encoder interface.
|
---|
903 | * @param hlptim : LPTIM handle
|
---|
904 | * @param Period : Specifies the Autoreload value.
|
---|
905 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
906 | * @retval HAL status
|
---|
907 | */
|
---|
908 | HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
|
---|
909 | {
|
---|
910 | uint32_t tmpcfgr = 0;
|
---|
911 |
|
---|
912 | /* Check the parameters */
|
---|
913 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
914 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
915 | assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
|
---|
916 | assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
|
---|
917 | assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
|
---|
918 |
|
---|
919 | /* Set the LPTIM state */
|
---|
920 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
921 |
|
---|
922 | /* Get the LPTIMx CFGR value */
|
---|
923 | tmpcfgr = hlptim->Instance->CFGR;
|
---|
924 |
|
---|
925 | /* Clear CKPOL bits */
|
---|
926 | tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
|
---|
927 |
|
---|
928 | /* Set Input polarity */
|
---|
929 | tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
|
---|
930 |
|
---|
931 | /* Write to LPTIMx CFGR */
|
---|
932 | hlptim->Instance->CFGR = tmpcfgr;
|
---|
933 |
|
---|
934 | /* Set ENC bit to enable the encoder interface */
|
---|
935 | hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
|
---|
936 |
|
---|
937 | /* Enable the Peripheral */
|
---|
938 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
939 |
|
---|
940 | /* Load the period value in the autoreload register */
|
---|
941 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
942 |
|
---|
943 | /* Start timer in continuous mode */
|
---|
944 | __HAL_LPTIM_START_CONTINUOUS(hlptim);
|
---|
945 |
|
---|
946 | /* Change the TIM state*/
|
---|
947 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
948 |
|
---|
949 | /* Return function status */
|
---|
950 | return HAL_OK;
|
---|
951 | }
|
---|
952 |
|
---|
953 | /**
|
---|
954 | * @brief Stops the Encoder interface.
|
---|
955 | * @param hlptim : LPTIM handle
|
---|
956 | * @retval HAL status
|
---|
957 | */
|
---|
958 | HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
|
---|
959 | {
|
---|
960 | /* Check the parameters */
|
---|
961 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
962 |
|
---|
963 | /* Set the LPTIM state */
|
---|
964 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
965 |
|
---|
966 | /* Disable the Peripheral */
|
---|
967 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
968 |
|
---|
969 | /* Reset ENC bit to disable the encoder interface */
|
---|
970 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
|
---|
971 |
|
---|
972 | /* Change the TIM state*/
|
---|
973 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
974 |
|
---|
975 | /* Return function status */
|
---|
976 | return HAL_OK;
|
---|
977 | }
|
---|
978 |
|
---|
979 | /**
|
---|
980 | * @brief Starts the Encoder interface in interrupt mode.
|
---|
981 | * @param hlptim : LPTIM handle
|
---|
982 | * @param Period : Specifies the Autoreload value.
|
---|
983 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
984 | * @retval HAL status
|
---|
985 | */
|
---|
986 | HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
|
---|
987 | {
|
---|
988 | uint32_t tmpcfgr = 0;
|
---|
989 |
|
---|
990 | /* Check the parameters */
|
---|
991 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
992 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
993 | assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
|
---|
994 | assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
|
---|
995 | assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
|
---|
996 |
|
---|
997 | /* Set the LPTIM state */
|
---|
998 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
999 |
|
---|
1000 | /* Configure edge sensitivity for encoder mode */
|
---|
1001 | /* Get the LPTIMx CFGR value */
|
---|
1002 | tmpcfgr = hlptim->Instance->CFGR;
|
---|
1003 |
|
---|
1004 | /* Clear CKPOL bits */
|
---|
1005 | tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
|
---|
1006 |
|
---|
1007 | /* Set Input polarity */
|
---|
1008 | tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
|
---|
1009 |
|
---|
1010 | /* Write to LPTIMx CFGR */
|
---|
1011 | hlptim->Instance->CFGR = tmpcfgr;
|
---|
1012 |
|
---|
1013 | /* Set ENC bit to enable the encoder interface */
|
---|
1014 | hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
|
---|
1015 |
|
---|
1016 | /* Enable "switch to down direction" interrupt */
|
---|
1017 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
|
---|
1018 |
|
---|
1019 | /* Enable "switch to up direction" interrupt */
|
---|
1020 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
|
---|
1021 |
|
---|
1022 | /* Enable the Peripheral */
|
---|
1023 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
1024 |
|
---|
1025 | /* Load the period value in the autoreload register */
|
---|
1026 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
1027 |
|
---|
1028 | /* Start timer in continuous mode */
|
---|
1029 | __HAL_LPTIM_START_CONTINUOUS(hlptim);
|
---|
1030 |
|
---|
1031 | /* Change the TIM state*/
|
---|
1032 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1033 |
|
---|
1034 | /* Return function status */
|
---|
1035 | return HAL_OK;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | /**
|
---|
1039 | * @brief Stops the Encoder interface in interrupt mode.
|
---|
1040 | * @param hlptim : LPTIM handle
|
---|
1041 | * @retval HAL status
|
---|
1042 | */
|
---|
1043 | HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
|
---|
1044 | {
|
---|
1045 | /* Check the parameters */
|
---|
1046 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1047 |
|
---|
1048 | /* Set the LPTIM state */
|
---|
1049 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
1050 |
|
---|
1051 | /* Disable the Peripheral */
|
---|
1052 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
1053 |
|
---|
1054 | /* Reset ENC bit to disable the encoder interface */
|
---|
1055 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
|
---|
1056 |
|
---|
1057 | /* Disable "switch to down direction" interrupt */
|
---|
1058 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
|
---|
1059 |
|
---|
1060 | /* Disable "switch to up direction" interrupt */
|
---|
1061 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
|
---|
1062 |
|
---|
1063 | /* Change the TIM state*/
|
---|
1064 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1065 |
|
---|
1066 | /* Return function status */
|
---|
1067 | return HAL_OK;
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | /**
|
---|
1071 | * @brief Starts the Timeout function. The first trigger event will start the
|
---|
1072 | * timer, any successive trigger event will reset the counter and
|
---|
1073 | * the timer restarts.
|
---|
1074 | * @param hlptim : LPTIM handle
|
---|
1075 | * @param Period : Specifies the Autoreload value.
|
---|
1076 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
1077 | * @param Timeout : Specifies the TimeOut value to rest the counter.
|
---|
1078 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
1079 | * @retval HAL status
|
---|
1080 | */
|
---|
1081 | HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
|
---|
1082 | {
|
---|
1083 | /* Check the parameters */
|
---|
1084 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1085 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
1086 | assert_param(IS_LPTIM_PULSE(Timeout));
|
---|
1087 |
|
---|
1088 | /* Set the LPTIM state */
|
---|
1089 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
1090 |
|
---|
1091 | /* Set TIMOUT bit to enable the timeout function */
|
---|
1092 | hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
|
---|
1093 |
|
---|
1094 | /* Enable the Peripheral */
|
---|
1095 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
1096 |
|
---|
1097 | /* Load the period value in the autoreload register */
|
---|
1098 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
1099 |
|
---|
1100 | /* Load the Timeout value in the compare register */
|
---|
1101 | __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
|
---|
1102 |
|
---|
1103 | /* Start timer in continuous mode */
|
---|
1104 | __HAL_LPTIM_START_CONTINUOUS(hlptim);
|
---|
1105 |
|
---|
1106 | /* Change the TIM state*/
|
---|
1107 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1108 |
|
---|
1109 | /* Return function status */
|
---|
1110 | return HAL_OK;
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | /**
|
---|
1114 | * @brief Stops the Timeout function.
|
---|
1115 | * @param hlptim : LPTIM handle
|
---|
1116 | * @retval HAL status
|
---|
1117 | */
|
---|
1118 | HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
|
---|
1119 | {
|
---|
1120 | /* Check the parameters */
|
---|
1121 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1122 |
|
---|
1123 | /* Set the LPTIM state */
|
---|
1124 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
1125 |
|
---|
1126 | /* Disable the Peripheral */
|
---|
1127 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
1128 |
|
---|
1129 | /* Reset TIMOUT bit to enable the timeout function */
|
---|
1130 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
|
---|
1131 |
|
---|
1132 | /* Change the TIM state*/
|
---|
1133 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1134 |
|
---|
1135 | /* Return function status */
|
---|
1136 | return HAL_OK;
|
---|
1137 | }
|
---|
1138 |
|
---|
1139 | /**
|
---|
1140 | * @brief Starts the Timeout function in interrupt mode. The first trigger
|
---|
1141 | * event will start the timer, any successive trigger event will reset
|
---|
1142 | * the counter and the timer restarts.
|
---|
1143 | * @param hlptim : LPTIM handle
|
---|
1144 | * @param Period : Specifies the Autoreload value.
|
---|
1145 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
1146 | * @param Timeout : Specifies the TimeOut value to rest the counter.
|
---|
1147 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
1148 | * @retval HAL status
|
---|
1149 | */
|
---|
1150 | HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
|
---|
1151 | {
|
---|
1152 | /* Check the parameters */
|
---|
1153 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1154 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
1155 | assert_param(IS_LPTIM_PULSE(Timeout));
|
---|
1156 |
|
---|
1157 | /* Set the LPTIM state */
|
---|
1158 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
1159 |
|
---|
1160 | /* Set TIMOUT bit to enable the timeout function */
|
---|
1161 | hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
|
---|
1162 |
|
---|
1163 | /* Enable Compare match interrupt */
|
---|
1164 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
|
---|
1165 |
|
---|
1166 | /* Enable the Peripheral */
|
---|
1167 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
1168 |
|
---|
1169 | /* Load the period value in the autoreload register */
|
---|
1170 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
1171 |
|
---|
1172 | /* Load the Timeout value in the compare register */
|
---|
1173 | __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
|
---|
1174 |
|
---|
1175 | /* Start timer in continuous mode */
|
---|
1176 | __HAL_LPTIM_START_CONTINUOUS(hlptim);
|
---|
1177 |
|
---|
1178 | /* Change the TIM state*/
|
---|
1179 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1180 |
|
---|
1181 | /* Return function status */
|
---|
1182 | return HAL_OK;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | /**
|
---|
1186 | * @brief Stops the Timeout function in interrupt mode.
|
---|
1187 | * @param hlptim : LPTIM handle
|
---|
1188 | * @retval HAL status
|
---|
1189 | */
|
---|
1190 | HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
|
---|
1191 | {
|
---|
1192 | /* Check the parameters */
|
---|
1193 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1194 |
|
---|
1195 | /* Set the LPTIM state */
|
---|
1196 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
1197 |
|
---|
1198 | /* Disable the Peripheral */
|
---|
1199 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
1200 |
|
---|
1201 | /* Reset TIMOUT bit to enable the timeout function */
|
---|
1202 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
|
---|
1203 |
|
---|
1204 | /* Disable Compare match interrupt */
|
---|
1205 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
|
---|
1206 |
|
---|
1207 | /* Change the TIM state*/
|
---|
1208 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1209 |
|
---|
1210 | /* Return function status */
|
---|
1211 | return HAL_OK;
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | /**
|
---|
1215 | * @brief Starts the Counter mode.
|
---|
1216 | * @param hlptim : LPTIM handle
|
---|
1217 | * @param Period : Specifies the Autoreload value.
|
---|
1218 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
1219 | * @retval HAL status
|
---|
1220 | */
|
---|
1221 | HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
|
---|
1222 | {
|
---|
1223 | /* Check the parameters */
|
---|
1224 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1225 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
1226 |
|
---|
1227 | /* Set the LPTIM state */
|
---|
1228 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
1229 |
|
---|
1230 | /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
|
---|
1231 | if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
|
---|
1232 | {
|
---|
1233 | /* Check if clock is prescaled */
|
---|
1234 | assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
|
---|
1235 | /* Set clock prescaler to 0 */
|
---|
1236 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | /* Enable the Peripheral */
|
---|
1240 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
1241 |
|
---|
1242 | /* Load the period value in the autoreload register */
|
---|
1243 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
1244 |
|
---|
1245 | /* Start timer in continuous mode */
|
---|
1246 | __HAL_LPTIM_START_CONTINUOUS(hlptim);
|
---|
1247 |
|
---|
1248 | /* Change the TIM state*/
|
---|
1249 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1250 |
|
---|
1251 | /* Return function status */
|
---|
1252 | return HAL_OK;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | /**
|
---|
1256 | * @brief Stops the Counter mode.
|
---|
1257 | * @param hlptim : LPTIM handle
|
---|
1258 | * @retval HAL status
|
---|
1259 | */
|
---|
1260 | HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
|
---|
1261 | {
|
---|
1262 | /* Check the parameters */
|
---|
1263 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1264 |
|
---|
1265 | /* Set the LPTIM state */
|
---|
1266 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
1267 |
|
---|
1268 | /* Disable the Peripheral */
|
---|
1269 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
1270 |
|
---|
1271 | /* Change the TIM state*/
|
---|
1272 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1273 |
|
---|
1274 | /* Return function status */
|
---|
1275 | return HAL_OK;
|
---|
1276 | }
|
---|
1277 |
|
---|
1278 | /**
|
---|
1279 | * @brief Starts the Counter mode in interrupt mode.
|
---|
1280 | * @param hlptim : LPTIM handle
|
---|
1281 | * @param Period : Specifies the Autoreload value.
|
---|
1282 | * This parameter must be a value between 0x0000 and 0xFFFF.
|
---|
1283 | * @retval HAL status
|
---|
1284 | */
|
---|
1285 | HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
|
---|
1286 | {
|
---|
1287 | /* Check the parameters */
|
---|
1288 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1289 | assert_param(IS_LPTIM_PERIOD(Period));
|
---|
1290 |
|
---|
1291 | /* Set the LPTIM state */
|
---|
1292 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
1293 |
|
---|
1294 | /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
|
---|
1295 | if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
|
---|
1296 | {
|
---|
1297 | /* Check if clock is prescaled */
|
---|
1298 | assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
|
---|
1299 | /* Set clock prescaler to 0 */
|
---|
1300 | hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 | /* Enable Autoreload write complete interrupt */
|
---|
1304 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
|
---|
1305 |
|
---|
1306 | /* Enable Autoreload match interrupt */
|
---|
1307 | __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
|
---|
1308 |
|
---|
1309 | /* Enable the Peripheral */
|
---|
1310 | __HAL_LPTIM_ENABLE(hlptim);
|
---|
1311 |
|
---|
1312 | /* Load the period value in the autoreload register */
|
---|
1313 | __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
|
---|
1314 |
|
---|
1315 | /* Start timer in continuous mode */
|
---|
1316 | __HAL_LPTIM_START_CONTINUOUS(hlptim);
|
---|
1317 |
|
---|
1318 | /* Change the TIM state*/
|
---|
1319 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1320 |
|
---|
1321 | /* Return function status */
|
---|
1322 | return HAL_OK;
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | /**
|
---|
1326 | * @brief Stops the Counter mode in interrupt mode.
|
---|
1327 | * @param hlptim : LPTIM handle
|
---|
1328 | * @retval HAL status
|
---|
1329 | */
|
---|
1330 | HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
|
---|
1331 | {
|
---|
1332 | /* Check the parameters */
|
---|
1333 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1334 |
|
---|
1335 | /* Set the LPTIM state */
|
---|
1336 | hlptim->State= HAL_LPTIM_STATE_BUSY;
|
---|
1337 |
|
---|
1338 | /* Disable the Peripheral */
|
---|
1339 | __HAL_LPTIM_DISABLE(hlptim);
|
---|
1340 |
|
---|
1341 | /* Disable Autoreload write complete interrupt */
|
---|
1342 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
|
---|
1343 |
|
---|
1344 | /* Disable Autoreload match interrupt */
|
---|
1345 | __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
|
---|
1346 |
|
---|
1347 | /* Change the TIM state*/
|
---|
1348 | hlptim->State= HAL_LPTIM_STATE_READY;
|
---|
1349 |
|
---|
1350 | /* Return function status */
|
---|
1351 | return HAL_OK;
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | /**
|
---|
1355 | * @}
|
---|
1356 | */
|
---|
1357 |
|
---|
1358 | /** @defgroup LPTIM_Group3 LPTIM Read operation functions
|
---|
1359 | * @brief Read operation functions.
|
---|
1360 | *
|
---|
1361 | @verbatim
|
---|
1362 | ==============================================================================
|
---|
1363 | ##### LPTIM Read operation functions #####
|
---|
1364 | ==============================================================================
|
---|
1365 | [..] This section provides LPTIM Reading functions.
|
---|
1366 | (+) Read the counter value.
|
---|
1367 | (+) Read the period (Auto-reload) value.
|
---|
1368 | (+) Read the pulse (Compare)value.
|
---|
1369 | @endverbatim
|
---|
1370 | * @{
|
---|
1371 | */
|
---|
1372 |
|
---|
1373 | /**
|
---|
1374 | * @brief This function returns the current counter value.
|
---|
1375 | * @param hlptim: LPTIM handle
|
---|
1376 | * @retval Counter value.
|
---|
1377 | */
|
---|
1378 | uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
|
---|
1379 | {
|
---|
1380 | /* Check the parameters */
|
---|
1381 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1382 |
|
---|
1383 | return (hlptim->Instance->CNT);
|
---|
1384 | }
|
---|
1385 |
|
---|
1386 | /**
|
---|
1387 | * @brief This function return the current Autoreload (Period) value.
|
---|
1388 | * @param hlptim: LPTIM handle
|
---|
1389 | * @retval Autoreload value.
|
---|
1390 | */
|
---|
1391 | uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
|
---|
1392 | {
|
---|
1393 | /* Check the parameters */
|
---|
1394 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1395 |
|
---|
1396 | return (hlptim->Instance->ARR);
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | /**
|
---|
1400 | * @brief This function return the current Compare (Pulse) value.
|
---|
1401 | * @param hlptim: LPTIM handle
|
---|
1402 | * @retval Compare value.
|
---|
1403 | */
|
---|
1404 | uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
|
---|
1405 | {
|
---|
1406 | /* Check the parameters */
|
---|
1407 | assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
|
---|
1408 |
|
---|
1409 | return (hlptim->Instance->CMP);
|
---|
1410 | }
|
---|
1411 |
|
---|
1412 | /**
|
---|
1413 | * @}
|
---|
1414 | */
|
---|
1415 |
|
---|
1416 |
|
---|
1417 |
|
---|
1418 | /** @defgroup LPTIM_Group4 LPTIM IRQ handler
|
---|
1419 | * @brief LPTIM IRQ handler.
|
---|
1420 | *
|
---|
1421 | @verbatim
|
---|
1422 | ==============================================================================
|
---|
1423 | ##### LPTIM IRQ handler #####
|
---|
1424 | ==============================================================================
|
---|
1425 | [..] This section provides LPTIM IRQ handler function.
|
---|
1426 |
|
---|
1427 | @endverbatim
|
---|
1428 | * @{
|
---|
1429 | */
|
---|
1430 |
|
---|
1431 | /**
|
---|
1432 | * @brief This function handles LPTIM interrupt request.
|
---|
1433 | * @param hlptim: LPTIM handle
|
---|
1434 | * @retval None
|
---|
1435 | */
|
---|
1436 | void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
|
---|
1437 | {
|
---|
1438 | /* Compare match interrupt */
|
---|
1439 | if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
|
---|
1440 | {
|
---|
1441 | if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) !=RESET)
|
---|
1442 | {
|
---|
1443 | /* Clear Compare match flag */
|
---|
1444 | __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
|
---|
1445 | /* Compare match Callback */
|
---|
1446 | HAL_LPTIM_CompareMatchCallback(hlptim);
|
---|
1447 | }
|
---|
1448 | }
|
---|
1449 |
|
---|
1450 | /* Autoreload match interrupt */
|
---|
1451 | if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
|
---|
1452 | {
|
---|
1453 | if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) !=RESET)
|
---|
1454 | {
|
---|
1455 | /* Clear Autoreload match flag */
|
---|
1456 | __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
|
---|
1457 | /* Autoreload match Callback */
|
---|
1458 | HAL_LPTIM_AutoReloadMatchCallback(hlptim);
|
---|
1459 | }
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | /* Trigger detected interrupt */
|
---|
1463 | if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
|
---|
1464 | {
|
---|
1465 | if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) !=RESET)
|
---|
1466 | {
|
---|
1467 | /* Clear Trigger detected flag */
|
---|
1468 | __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
|
---|
1469 | /* Trigger detected callback */
|
---|
1470 | HAL_LPTIM_TriggerCallback(hlptim);
|
---|
1471 | }
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | /* Compare write interrupt */
|
---|
1475 | if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
|
---|
1476 | {
|
---|
1477 | if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_FLAG_CMPM) !=RESET)
|
---|
1478 | {
|
---|
1479 | /* Clear Compare write flag */
|
---|
1480 | __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
|
---|
1481 | /* Compare write Callback */
|
---|
1482 | HAL_LPTIM_CompareWriteCallback(hlptim);
|
---|
1483 | }
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | /* Autoreload write interrupt */
|
---|
1487 | if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
|
---|
1488 | {
|
---|
1489 | if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) !=RESET)
|
---|
1490 | {
|
---|
1491 | /* Clear Autoreload write flag */
|
---|
1492 | __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
|
---|
1493 | /* Autoreload write Callback */
|
---|
1494 | HAL_LPTIM_AutoReloadWriteCallback(hlptim);
|
---|
1495 | }
|
---|
1496 | }
|
---|
1497 |
|
---|
1498 | /* Direction counter changed from Down to Up interrupt */
|
---|
1499 | if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
|
---|
1500 | {
|
---|
1501 | if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) !=RESET)
|
---|
1502 | {
|
---|
1503 | /* Clear Direction counter changed from Down to Up flag */
|
---|
1504 | __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
|
---|
1505 | /* Direction counter changed from Down to Up Callback */
|
---|
1506 | HAL_LPTIM_DirectionUpCallback(hlptim);
|
---|
1507 | }
|
---|
1508 | }
|
---|
1509 |
|
---|
1510 | /* Direction counter changed from Up to Down interrupt */
|
---|
1511 | if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
|
---|
1512 | {
|
---|
1513 | if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) !=RESET)
|
---|
1514 | {
|
---|
1515 | /* Clear Direction counter changed from Up to Down flag */
|
---|
1516 | __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
|
---|
1517 | /* Direction counter changed from Up to Down Callback */
|
---|
1518 | HAL_LPTIM_DirectionDownCallback(hlptim);
|
---|
1519 | }
|
---|
1520 | }
|
---|
1521 | __HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG();
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | /**
|
---|
1525 | * @brief Compare match callback in non blocking mode
|
---|
1526 | * @param hlptim : LPTIM handle
|
---|
1527 | * @retval None
|
---|
1528 | */
|
---|
1529 | __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
|
---|
1530 | {
|
---|
1531 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
1532 | the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
|
---|
1533 | */
|
---|
1534 | }
|
---|
1535 |
|
---|
1536 | /**
|
---|
1537 | * @brief Autoreload match callback in non blocking mode
|
---|
1538 | * @param hlptim : LPTIM handle
|
---|
1539 | * @retval None
|
---|
1540 | */
|
---|
1541 | __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
|
---|
1542 | {
|
---|
1543 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
1544 | the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
|
---|
1545 | */
|
---|
1546 | }
|
---|
1547 |
|
---|
1548 | /**
|
---|
1549 | * @brief Trigger detected callback in non blocking mode
|
---|
1550 | * @param hlptim : LPTIM handle
|
---|
1551 | * @retval None
|
---|
1552 | */
|
---|
1553 | __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
|
---|
1554 | {
|
---|
1555 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
1556 | the HAL_LPTIM_TriggerCallback could be implemented in the user file
|
---|
1557 | */
|
---|
1558 | }
|
---|
1559 |
|
---|
1560 | /**
|
---|
1561 | * @brief Compare write callback in non blocking mode
|
---|
1562 | * @param hlptim : LPTIM handle
|
---|
1563 | * @retval None
|
---|
1564 | */
|
---|
1565 | __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
|
---|
1566 | {
|
---|
1567 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
1568 | the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
|
---|
1569 | */
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | /**
|
---|
1573 | * @brief Autoreload write callback in non blocking mode
|
---|
1574 | * @param hlptim : LPTIM handle
|
---|
1575 | * @retval None
|
---|
1576 | */
|
---|
1577 | __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
|
---|
1578 | {
|
---|
1579 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
1580 | the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
|
---|
1581 | */
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 | /**
|
---|
1585 | * @brief Direction counter changed from Down to Up callback in non blocking mode
|
---|
1586 | * @param hlptim : LPTIM handle
|
---|
1587 | * @retval None
|
---|
1588 | */
|
---|
1589 | __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
|
---|
1590 | {
|
---|
1591 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
1592 | the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
|
---|
1593 | */
|
---|
1594 | }
|
---|
1595 |
|
---|
1596 | /**
|
---|
1597 | * @brief Direction counter changed from Up to Down callback in non blocking mode
|
---|
1598 | * @param hlptim : LPTIM handle
|
---|
1599 | * @retval None
|
---|
1600 | */
|
---|
1601 | __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
|
---|
1602 | {
|
---|
1603 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
1604 | the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
|
---|
1605 | */
|
---|
1606 | }
|
---|
1607 |
|
---|
1608 | /**
|
---|
1609 | * @}
|
---|
1610 | */
|
---|
1611 |
|
---|
1612 | /** @defgroup LPTIM_Group5 Peripheral State functions
|
---|
1613 | * @brief Peripheral State functions.
|
---|
1614 | *
|
---|
1615 | @verbatim
|
---|
1616 | ==============================================================================
|
---|
1617 | ##### Peripheral State functions #####
|
---|
1618 | ==============================================================================
|
---|
1619 | [..]
|
---|
1620 | This subsection permits to get in run-time the status of the peripheral.
|
---|
1621 |
|
---|
1622 | @endverbatim
|
---|
1623 | * @{
|
---|
1624 | */
|
---|
1625 |
|
---|
1626 | /**
|
---|
1627 | * @brief Returns the LPTIM state.
|
---|
1628 | * @param hlptim: LPTIM handle
|
---|
1629 | * @retval HAL state
|
---|
1630 | */
|
---|
1631 | HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
|
---|
1632 | {
|
---|
1633 | return hlptim->State;
|
---|
1634 | }
|
---|
1635 |
|
---|
1636 | /**
|
---|
1637 | * @}
|
---|
1638 | */
|
---|
1639 |
|
---|
1640 |
|
---|
1641 | /**
|
---|
1642 | * @}
|
---|
1643 | */
|
---|
1644 |
|
---|
1645 | #endif /* STM32F410Tx || STM32F410Cx || STM32F410Rx */
|
---|
1646 | #endif /* HAL_LPTIM_MODULE_ENABLED */
|
---|
1647 | /**
|
---|
1648 | * @}
|
---|
1649 | */
|
---|
1650 |
|
---|
1651 | /**
|
---|
1652 | * @}
|
---|
1653 | */
|
---|
1654 |
|
---|
1655 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|