STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_hal_lptim.c 00004 * @author MCD Application Team 00005 * @brief LPTIM HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Low Power Timer (LPTIM) peripheral: 00008 * + Initialization and de-initialization functions. 00009 * + Start/Stop operation functions in polling mode. 00010 * + Start/Stop operation functions in interrupt mode. 00011 * + Reading operation functions. 00012 * + Peripheral State functions. 00013 * 00014 ****************************************************************************** 00015 * @attention 00016 * 00017 * Copyright (c) 2017 STMicroelectronics. 00018 * All rights reserved. 00019 * 00020 * This software is licensed under terms that can be found in the LICENSE file 00021 * in the root directory of this software component. 00022 * If no LICENSE file comes with this software, it is provided AS-IS. 00023 * 00024 ****************************************************************************** 00025 @verbatim 00026 ============================================================================== 00027 ##### How to use this driver ##### 00028 ============================================================================== 00029 [..] 00030 The LPTIM HAL driver can be used as follows: 00031 00032 (#)Initialize the LPTIM low level resources by implementing the 00033 HAL_LPTIM_MspInit(): 00034 (++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE(). 00035 (++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()): 00036 (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority(). 00037 (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ(). 00038 (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler(). 00039 00040 (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function 00041 configures mainly: 00042 (++) The instance: LPTIM1 or LPTIM2. 00043 (++) Clock: the counter clock. 00044 (+++) Source : it can be either the ULPTIM input (IN1) or one of 00045 the internal clock; (APB, LSE, LSI or MSI). 00046 (+++) Prescaler: select the clock divider. 00047 (++) UltraLowPowerClock : To be used only if the ULPTIM is selected 00048 as counter clock source. 00049 (+++) Polarity: polarity of the active edge for the counter unit 00050 if the ULPTIM input is selected. 00051 (+++) SampleTime: clock sampling time to configure the clock glitch 00052 filter. 00053 (++) Trigger: How the counter start. 00054 (+++) Source: trigger can be software or one of the hardware triggers. 00055 (+++) ActiveEdge : only for hardware trigger. 00056 (+++) SampleTime : trigger sampling time to configure the trigger 00057 glitch filter. 00058 (++) OutputPolarity : 2 opposite polarities are possible. 00059 (++) UpdateMode: specifies whether the update of the autoreload and 00060 the compare values is done immediately or after the end of current 00061 period. 00062 (++) Input1Source: Source selected for input1 (GPIO or comparator output). 00063 (++) Input2Source: Source selected for input2 (GPIO or comparator output). 00064 Input2 is used only for encoder feature so is used only for LPTIM1 instance. 00065 00066 (#)Six modes are available: 00067 00068 (++) PWM Mode: To generate a PWM signal with specified period and pulse, 00069 call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption 00070 mode. 00071 00072 (++) One Pulse Mode: To generate pulse with specified width in response 00073 to a stimulus, call HAL_LPTIM_OnePulse_Start() or 00074 HAL_LPTIM_OnePulse_Start_IT() for interruption mode. 00075 00076 (++) Set once Mode: In this mode, the output changes the level (from 00077 low level to high level if the output polarity is configured high, else 00078 the opposite) when a compare match occurs. To start this mode, call 00079 HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for 00080 interruption mode. 00081 00082 (++) Encoder Mode: To use the encoder interface call 00083 HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for 00084 interruption mode. Only available for LPTIM1 instance. 00085 00086 (++) Time out Mode: an active edge on one selected trigger input rests 00087 the counter. The first trigger event will start the timer, any 00088 successive trigger event will reset the counter and the timer will 00089 restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or 00090 HAL_LPTIM_TimeOut_Start_IT() for interruption mode. 00091 00092 (++) Counter Mode: counter can be used to count external events on 00093 the LPTIM Input1 or it can be used to count internal clock cycles. 00094 To start this mode, call HAL_LPTIM_Counter_Start() or 00095 HAL_LPTIM_Counter_Start_IT() for interruption mode. 00096 00097 00098 (#) User can stop any process by calling the corresponding API: 00099 HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is 00100 already started in interruption mode. 00101 00102 (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit(). 00103 00104 *** Callback registration *** 00105 ============================================= 00106 [..] 00107 The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1 00108 allows the user to configure dynamically the driver callbacks. 00109 [..] 00110 Use Function HAL_LPTIM_RegisterCallback() to register a callback. 00111 HAL_LPTIM_RegisterCallback() takes as parameters the HAL peripheral handle, 00112 the Callback ID and a pointer to the user callback function. 00113 [..] 00114 Use function HAL_LPTIM_UnRegisterCallback() to reset a callback to the 00115 default weak function. 00116 HAL_LPTIM_UnRegisterCallback takes as parameters the HAL peripheral handle, 00117 and the Callback ID. 00118 [..] 00119 These functions allow to register/unregister following callbacks: 00120 00121 (+) MspInitCallback : LPTIM Base Msp Init Callback. 00122 (+) MspDeInitCallback : LPTIM Base Msp DeInit Callback. 00123 (+) CompareMatchCallback : Compare match Callback. 00124 (+) AutoReloadMatchCallback : Auto-reload match Callback. 00125 (+) TriggerCallback : External trigger event detection Callback. 00126 (+) CompareWriteCallback : Compare register write complete Callback. 00127 (+) AutoReloadWriteCallback : Auto-reload register write complete Callback. 00128 (+) DirectionUpCallback : Up-counting direction change Callback. 00129 (+) DirectionDownCallback : Down-counting direction change Callback. 00130 00131 [..] 00132 By default, after the Init and when the state is HAL_LPTIM_STATE_RESET 00133 all interrupt callbacks are set to the corresponding weak functions: 00134 examples HAL_LPTIM_TriggerCallback(), HAL_LPTIM_CompareMatchCallback(). 00135 00136 [..] 00137 Exception done for MspInit and MspDeInit functions that are reset to the legacy weak 00138 functionalities in the Init/DeInit only when these callbacks are null 00139 (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init/DeInit 00140 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) 00141 00142 [..] 00143 Callbacks can be registered/unregistered in HAL_LPTIM_STATE_READY state only. 00144 Exception done MspInit/MspDeInit that can be registered/unregistered 00145 in HAL_LPTIM_STATE_READY or HAL_LPTIM_STATE_RESET state, 00146 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. 00147 In that case first register the MspInit/MspDeInit user callbacks 00148 using HAL_LPTIM_RegisterCallback() before calling DeInit or Init function. 00149 00150 [..] 00151 When The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or 00152 not defined, the callback registration feature is not available and all callbacks 00153 are set to the corresponding weak functions. 00154 00155 @endverbatim 00156 ****************************************************************************** 00157 */ 00158 00159 /* Includes ------------------------------------------------------------------*/ 00160 #include "stm32h7xx_hal.h" 00161 00162 /** @addtogroup STM32H7xx_HAL_Driver 00163 * @{ 00164 */ 00165 00166 /** @defgroup LPTIM LPTIM 00167 * @brief LPTIM HAL module driver. 00168 * @{ 00169 */ 00170 00171 #ifdef HAL_LPTIM_MODULE_ENABLED 00172 00173 #if defined (LPTIM1) || defined (LPTIM2) || defined (LPTIM3) || defined (LPTIM4) || defined (LPTIM5) 00174 00175 /* Private typedef -----------------------------------------------------------*/ 00176 /* Private define ------------------------------------------------------------*/ 00177 /** @addtogroup LPTIM_Private_Constants 00178 * @{ 00179 */ 00180 #define TIMEOUT 1000UL /* Timeout is 1s */ 00181 /** 00182 * @} 00183 */ 00184 00185 /* Private macro -------------------------------------------------------------*/ 00186 /* Private variables ---------------------------------------------------------*/ 00187 /* Private function prototypes -----------------------------------------------*/ 00188 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 00189 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim); 00190 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 00191 static HAL_StatusTypeDef LPTIM_WaitForFlag(LPTIM_HandleTypeDef *hlptim, uint32_t flag); 00192 00193 /* Exported functions --------------------------------------------------------*/ 00194 00195 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions 00196 * @{ 00197 */ 00198 00199 /** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions 00200 * @brief Initialization and Configuration functions. 00201 * 00202 @verbatim 00203 ============================================================================== 00204 ##### Initialization and de-initialization functions ##### 00205 ============================================================================== 00206 [..] This section provides functions allowing to: 00207 (+) Initialize the LPTIM according to the specified parameters in the 00208 LPTIM_InitTypeDef and initialize the associated handle. 00209 (+) DeInitialize the LPTIM peripheral. 00210 (+) Initialize the LPTIM MSP. 00211 (+) DeInitialize the LPTIM MSP. 00212 00213 @endverbatim 00214 * @{ 00215 */ 00216 00217 /** 00218 * @brief Initialize the LPTIM according to the specified parameters in the 00219 * LPTIM_InitTypeDef and initialize the associated handle. 00220 * @param hlptim LPTIM handle 00221 * @retval HAL status 00222 */ 00223 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim) 00224 { 00225 uint32_t tmpcfgr; 00226 00227 /* Check the LPTIM handle allocation */ 00228 if (hlptim == NULL) 00229 { 00230 return HAL_ERROR; 00231 } 00232 00233 /* Check the parameters */ 00234 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00235 00236 assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source)); 00237 assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler)); 00238 if ((hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_ULPTIM) 00239 || (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL)) 00240 { 00241 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity)); 00242 assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime)); 00243 } 00244 assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source)); 00245 if (hlptim->Init.Trigger.Source != LPTIM_TRIGSOURCE_SOFTWARE) 00246 { 00247 assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge)); 00248 assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime)); 00249 } 00250 assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity)); 00251 assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode)); 00252 assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource)); 00253 00254 if (hlptim->State == HAL_LPTIM_STATE_RESET) 00255 { 00256 /* Allocate lock resource and initialize it */ 00257 hlptim->Lock = HAL_UNLOCKED; 00258 00259 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 00260 /* Reset interrupt callbacks to legacy weak callbacks */ 00261 LPTIM_ResetCallback(hlptim); 00262 00263 if (hlptim->MspInitCallback == NULL) 00264 { 00265 hlptim->MspInitCallback = HAL_LPTIM_MspInit; 00266 } 00267 00268 /* Init the low level hardware : GPIO, CLOCK, NVIC */ 00269 hlptim->MspInitCallback(hlptim); 00270 #else 00271 /* Init the low level hardware : GPIO, CLOCK, NVIC */ 00272 HAL_LPTIM_MspInit(hlptim); 00273 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 00274 } 00275 00276 /* Change the LPTIM state */ 00277 hlptim->State = HAL_LPTIM_STATE_BUSY; 00278 00279 /* Get the LPTIMx CFGR value */ 00280 tmpcfgr = hlptim->Instance->CFGR; 00281 00282 if ((hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_ULPTIM) 00283 || (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL)) 00284 { 00285 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT)); 00286 } 00287 if (hlptim->Init.Trigger.Source != LPTIM_TRIGSOURCE_SOFTWARE) 00288 { 00289 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL)); 00290 } 00291 00292 /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */ 00293 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD | 00294 LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE)); 00295 00296 /* Set initialization parameters */ 00297 tmpcfgr |= (hlptim->Init.Clock.Source | 00298 hlptim->Init.Clock.Prescaler | 00299 hlptim->Init.OutputPolarity | 00300 hlptim->Init.UpdateMode | 00301 hlptim->Init.CounterSource); 00302 00303 /* Glitch filters for internal triggers and external inputs are configured 00304 * only if an internal clock source is provided to the LPTIM 00305 */ 00306 if (hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC) 00307 { 00308 tmpcfgr |= (hlptim->Init.Trigger.SampleTime | 00309 hlptim->Init.UltraLowPowerClock.SampleTime); 00310 } 00311 00312 /* Configure LPTIM external clock polarity and digital filter */ 00313 if ((hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_ULPTIM) 00314 || (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL)) 00315 { 00316 tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity | 00317 hlptim->Init.UltraLowPowerClock.SampleTime); 00318 } 00319 00320 /* Configure LPTIM external trigger */ 00321 if (hlptim->Init.Trigger.Source != LPTIM_TRIGSOURCE_SOFTWARE) 00322 { 00323 /* Enable External trigger and set the trigger source */ 00324 tmpcfgr |= (hlptim->Init.Trigger.Source | 00325 hlptim->Init.Trigger.ActiveEdge | 00326 hlptim->Init.Trigger.SampleTime); 00327 } 00328 00329 /* Write to LPTIMx CFGR */ 00330 hlptim->Instance->CFGR = tmpcfgr; 00331 00332 /* Configure LPTIM input sources */ 00333 if ((hlptim->Instance == LPTIM1) || (hlptim->Instance == LPTIM2)) 00334 { 00335 /* Check LPTIM Input1 and Input2 sources */ 00336 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance, hlptim->Init.Input1Source)); 00337 assert_param(IS_LPTIM_INPUT2_SOURCE(hlptim->Instance, hlptim->Init.Input2Source)); 00338 00339 /* Configure LPTIM Input1 and Input2 sources */ 00340 hlptim->Instance->CFGR2 = (hlptim->Init.Input1Source | hlptim->Init.Input2Source); 00341 } 00342 else 00343 { 00344 if (hlptim->Instance == LPTIM3) 00345 { 00346 /* Check LPTIM3 Input1 source */ 00347 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance, hlptim->Init.Input1Source)); 00348 00349 /* Configure LPTIM3 Input1 source */ 00350 hlptim->Instance->CFGR2 = hlptim->Init.Input1Source; 00351 } 00352 } 00353 00354 /* Change the LPTIM state */ 00355 hlptim->State = HAL_LPTIM_STATE_READY; 00356 00357 /* Return function status */ 00358 return HAL_OK; 00359 } 00360 00361 /** 00362 * @brief DeInitialize the LPTIM peripheral. 00363 * @param hlptim LPTIM handle 00364 * @retval HAL status 00365 */ 00366 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim) 00367 { 00368 /* Check the LPTIM handle allocation */ 00369 if (hlptim == NULL) 00370 { 00371 return HAL_ERROR; 00372 } 00373 00374 /* Change the LPTIM state */ 00375 hlptim->State = HAL_LPTIM_STATE_BUSY; 00376 00377 /* Disable the LPTIM Peripheral Clock */ 00378 __HAL_LPTIM_DISABLE(hlptim); 00379 00380 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 00381 { 00382 return HAL_TIMEOUT; 00383 } 00384 00385 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 00386 if (hlptim->MspDeInitCallback == NULL) 00387 { 00388 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; 00389 } 00390 00391 /* DeInit the low level hardware: CLOCK, NVIC.*/ 00392 hlptim->MspDeInitCallback(hlptim); 00393 #else 00394 /* DeInit the low level hardware: CLOCK, NVIC.*/ 00395 HAL_LPTIM_MspDeInit(hlptim); 00396 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 00397 00398 /* Change the LPTIM state */ 00399 hlptim->State = HAL_LPTIM_STATE_RESET; 00400 00401 /* Release Lock */ 00402 __HAL_UNLOCK(hlptim); 00403 00404 /* Return function status */ 00405 return HAL_OK; 00406 } 00407 00408 /** 00409 * @brief Initialize the LPTIM MSP. 00410 * @param hlptim LPTIM handle 00411 * @retval None 00412 */ 00413 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim) 00414 { 00415 /* Prevent unused argument(s) compilation warning */ 00416 UNUSED(hlptim); 00417 00418 /* NOTE : This function should not be modified, when the callback is needed, 00419 the HAL_LPTIM_MspInit could be implemented in the user file 00420 */ 00421 } 00422 00423 /** 00424 * @brief DeInitialize LPTIM MSP. 00425 * @param hlptim LPTIM handle 00426 * @retval None 00427 */ 00428 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim) 00429 { 00430 /* Prevent unused argument(s) compilation warning */ 00431 UNUSED(hlptim); 00432 00433 /* NOTE : This function should not be modified, when the callback is needed, 00434 the HAL_LPTIM_MspDeInit could be implemented in the user file 00435 */ 00436 } 00437 00438 /** 00439 * @} 00440 */ 00441 00442 /** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions 00443 * @brief Start-Stop operation functions. 00444 * 00445 @verbatim 00446 ============================================================================== 00447 ##### LPTIM Start Stop operation functions ##### 00448 ============================================================================== 00449 [..] This section provides functions allowing to: 00450 (+) Start the PWM mode. 00451 (+) Stop the PWM mode. 00452 (+) Start the One pulse mode. 00453 (+) Stop the One pulse mode. 00454 (+) Start the Set once mode. 00455 (+) Stop the Set once mode. 00456 (+) Start the Encoder mode. 00457 (+) Stop the Encoder mode. 00458 (+) Start the Timeout mode. 00459 (+) Stop the Timeout mode. 00460 (+) Start the Counter mode. 00461 (+) Stop the Counter mode. 00462 00463 00464 @endverbatim 00465 * @{ 00466 */ 00467 00468 /** 00469 * @brief Start the LPTIM PWM generation. 00470 * @param hlptim LPTIM handle 00471 * @param Period Specifies the Autoreload value. 00472 * This parameter must be a value between 0x0000 and 0xFFFF. 00473 * @param Pulse Specifies the compare value. 00474 * This parameter must be a value between 0x0000 and 0xFFFF. 00475 * @retval HAL status 00476 */ 00477 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00478 { 00479 /* Check the parameters */ 00480 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00481 assert_param(IS_LPTIM_PERIOD(Period)); 00482 assert_param(IS_LPTIM_PULSE(Pulse)); 00483 00484 /* Set the LPTIM state */ 00485 hlptim->State = HAL_LPTIM_STATE_BUSY; 00486 00487 /* Reset WAVE bit to set PWM mode */ 00488 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE; 00489 00490 /* Enable the Peripheral */ 00491 __HAL_LPTIM_ENABLE(hlptim); 00492 00493 /* Clear flag */ 00494 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 00495 00496 /* Load the period value in the autoreload register */ 00497 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00498 00499 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 00500 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 00501 { 00502 return HAL_TIMEOUT; 00503 } 00504 00505 /* Clear flag */ 00506 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 00507 00508 /* Load the pulse value in the compare register */ 00509 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00510 00511 /* Wait for the completion of the write operation to the LPTIM_CMP register */ 00512 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT) 00513 { 00514 return HAL_TIMEOUT; 00515 } 00516 00517 /* Start timer in continuous mode */ 00518 __HAL_LPTIM_START_CONTINUOUS(hlptim); 00519 00520 /* Change the TIM state*/ 00521 hlptim->State = HAL_LPTIM_STATE_READY; 00522 00523 /* Return function status */ 00524 return HAL_OK; 00525 } 00526 00527 /** 00528 * @brief Stop the LPTIM PWM generation. 00529 * @param hlptim LPTIM handle 00530 * @retval HAL status 00531 */ 00532 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim) 00533 { 00534 /* Check the parameters */ 00535 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00536 00537 /* Set the LPTIM state */ 00538 hlptim->State = HAL_LPTIM_STATE_BUSY; 00539 00540 /* Disable the Peripheral */ 00541 __HAL_LPTIM_DISABLE(hlptim); 00542 00543 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 00544 { 00545 return HAL_TIMEOUT; 00546 } 00547 00548 /* Change the LPTIM state*/ 00549 hlptim->State = HAL_LPTIM_STATE_READY; 00550 00551 /* Return function status */ 00552 return HAL_OK; 00553 } 00554 00555 /** 00556 * @brief Start the LPTIM PWM generation in interrupt mode. 00557 * @param hlptim LPTIM handle 00558 * @param Period Specifies the Autoreload value. 00559 * This parameter must be a value between 0x0000 and 0xFFFF 00560 * @param Pulse Specifies the compare value. 00561 * This parameter must be a value between 0x0000 and 0xFFFF 00562 * @retval HAL status 00563 */ 00564 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00565 { 00566 /* Check the parameters */ 00567 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00568 assert_param(IS_LPTIM_PERIOD(Period)); 00569 assert_param(IS_LPTIM_PULSE(Pulse)); 00570 00571 /* Set the LPTIM state */ 00572 hlptim->State = HAL_LPTIM_STATE_BUSY; 00573 00574 /* Reset WAVE bit to set PWM mode */ 00575 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE; 00576 00577 /* Enable the Peripheral */ 00578 __HAL_LPTIM_ENABLE(hlptim); 00579 00580 /* Clear flag */ 00581 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 00582 00583 /* Load the period value in the autoreload register */ 00584 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00585 00586 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 00587 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 00588 { 00589 return HAL_TIMEOUT; 00590 } 00591 00592 /* Clear flag */ 00593 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 00594 00595 /* Load the pulse value in the compare register */ 00596 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00597 00598 /* Wait for the completion of the write operation to the LPTIM_CMP register */ 00599 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT) 00600 { 00601 return HAL_TIMEOUT; 00602 } 00603 00604 /* Disable the Peripheral */ 00605 __HAL_LPTIM_DISABLE(hlptim); 00606 00607 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 00608 { 00609 return HAL_TIMEOUT; 00610 } 00611 00612 /* Enable Autoreload write complete interrupt */ 00613 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK); 00614 00615 /* Enable Compare write complete interrupt */ 00616 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK); 00617 00618 /* Enable Autoreload match interrupt */ 00619 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM); 00620 00621 /* Enable Compare match interrupt */ 00622 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM); 00623 00624 /* If external trigger source is used, then enable external trigger interrupt */ 00625 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00626 { 00627 /* Enable external trigger interrupt */ 00628 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00629 } 00630 00631 /* Enable the Peripheral */ 00632 __HAL_LPTIM_ENABLE(hlptim); 00633 00634 /* Start timer in continuous mode */ 00635 __HAL_LPTIM_START_CONTINUOUS(hlptim); 00636 00637 /* Change the TIM state*/ 00638 hlptim->State = HAL_LPTIM_STATE_READY; 00639 00640 /* Return function status */ 00641 return HAL_OK; 00642 } 00643 00644 /** 00645 * @brief Stop the LPTIM PWM generation in interrupt mode. 00646 * @param hlptim LPTIM handle 00647 * @retval HAL status 00648 */ 00649 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim) 00650 { 00651 /* Check the parameters */ 00652 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00653 00654 /* Set the LPTIM state */ 00655 hlptim->State = HAL_LPTIM_STATE_BUSY; 00656 00657 /* Disable the Peripheral */ 00658 __HAL_LPTIM_DISABLE(hlptim); 00659 00660 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 00661 { 00662 return HAL_TIMEOUT; 00663 } 00664 00665 /* Disable Autoreload write complete interrupt */ 00666 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK); 00667 00668 /* Disable Compare write complete interrupt */ 00669 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK); 00670 00671 /* Disable Autoreload match interrupt */ 00672 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM); 00673 00674 /* Disable Compare match interrupt */ 00675 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM); 00676 00677 /* If external trigger source is used, then disable external trigger interrupt */ 00678 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00679 { 00680 /* Disable external trigger interrupt */ 00681 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00682 } 00683 00684 /* Change the LPTIM state*/ 00685 hlptim->State = HAL_LPTIM_STATE_READY; 00686 00687 /* Return function status */ 00688 return HAL_OK; 00689 } 00690 00691 /** 00692 * @brief Start the LPTIM One pulse generation. 00693 * @param hlptim LPTIM handle 00694 * @param Period Specifies the Autoreload value. 00695 * This parameter must be a value between 0x0000 and 0xFFFF. 00696 * @param Pulse Specifies the compare value. 00697 * This parameter must be a value between 0x0000 and 0xFFFF. 00698 * @retval HAL status 00699 */ 00700 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00701 { 00702 /* Check the parameters */ 00703 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00704 assert_param(IS_LPTIM_PERIOD(Period)); 00705 assert_param(IS_LPTIM_PULSE(Pulse)); 00706 00707 /* Set the LPTIM state */ 00708 hlptim->State = HAL_LPTIM_STATE_BUSY; 00709 00710 /* Reset WAVE bit to set one pulse mode */ 00711 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE; 00712 00713 /* Enable the Peripheral */ 00714 __HAL_LPTIM_ENABLE(hlptim); 00715 00716 /* Clear flag */ 00717 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 00718 00719 /* Load the period value in the autoreload register */ 00720 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00721 00722 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 00723 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 00724 { 00725 return HAL_TIMEOUT; 00726 } 00727 00728 /* Clear flag */ 00729 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 00730 00731 /* Load the pulse value in the compare register */ 00732 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00733 00734 /* Wait for the completion of the write operation to the LPTIM_CMP register */ 00735 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT) 00736 { 00737 return HAL_TIMEOUT; 00738 } 00739 00740 /* Start timer in single (one shot) mode */ 00741 __HAL_LPTIM_START_SINGLE(hlptim); 00742 00743 /* Change the TIM state*/ 00744 hlptim->State = HAL_LPTIM_STATE_READY; 00745 00746 /* Return function status */ 00747 return HAL_OK; 00748 } 00749 00750 /** 00751 * @brief Stop the LPTIM One pulse generation. 00752 * @param hlptim LPTIM handle 00753 * @retval HAL status 00754 */ 00755 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim) 00756 { 00757 /* Check the parameters */ 00758 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00759 00760 /* Set the LPTIM state */ 00761 hlptim->State = HAL_LPTIM_STATE_BUSY; 00762 00763 /* Disable the Peripheral */ 00764 __HAL_LPTIM_DISABLE(hlptim); 00765 00766 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 00767 { 00768 return HAL_TIMEOUT; 00769 } 00770 00771 /* Change the LPTIM state*/ 00772 hlptim->State = HAL_LPTIM_STATE_READY; 00773 00774 /* Return function status */ 00775 return HAL_OK; 00776 } 00777 00778 /** 00779 * @brief Start the LPTIM One pulse generation in interrupt mode. 00780 * @param hlptim LPTIM handle 00781 * @param Period Specifies the Autoreload value. 00782 * This parameter must be a value between 0x0000 and 0xFFFF. 00783 * @param Pulse Specifies the compare value. 00784 * This parameter must be a value between 0x0000 and 0xFFFF. 00785 * @retval HAL status 00786 */ 00787 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00788 { 00789 /* Check the parameters */ 00790 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00791 assert_param(IS_LPTIM_PERIOD(Period)); 00792 assert_param(IS_LPTIM_PULSE(Pulse)); 00793 00794 /* Set the LPTIM state */ 00795 hlptim->State = HAL_LPTIM_STATE_BUSY; 00796 00797 /* Reset WAVE bit to set one pulse mode */ 00798 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE; 00799 00800 /* Enable the Peripheral */ 00801 __HAL_LPTIM_ENABLE(hlptim); 00802 00803 /* Clear flag */ 00804 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 00805 00806 /* Load the period value in the autoreload register */ 00807 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00808 00809 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 00810 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 00811 { 00812 return HAL_TIMEOUT; 00813 } 00814 00815 /* Clear flag */ 00816 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 00817 00818 /* Load the pulse value in the compare register */ 00819 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00820 00821 /* Wait for the completion of the write operation to the LPTIM_CMP register */ 00822 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT) 00823 { 00824 return HAL_TIMEOUT; 00825 } 00826 00827 /* Disable the Peripheral */ 00828 __HAL_LPTIM_DISABLE(hlptim); 00829 00830 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 00831 { 00832 return HAL_TIMEOUT; 00833 } 00834 00835 /* Enable Autoreload write complete interrupt */ 00836 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK); 00837 00838 /* Enable Compare write complete interrupt */ 00839 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK); 00840 00841 /* Enable Autoreload match interrupt */ 00842 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM); 00843 00844 /* Enable Compare match interrupt */ 00845 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM); 00846 00847 /* If external trigger source is used, then enable external trigger interrupt */ 00848 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00849 { 00850 /* Enable external trigger interrupt */ 00851 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00852 } 00853 00854 /* Enable the Peripheral */ 00855 __HAL_LPTIM_ENABLE(hlptim); 00856 00857 /* Start timer in single (one shot) mode */ 00858 __HAL_LPTIM_START_SINGLE(hlptim); 00859 00860 /* Change the TIM state*/ 00861 hlptim->State = HAL_LPTIM_STATE_READY; 00862 00863 /* Return function status */ 00864 return HAL_OK; 00865 } 00866 00867 /** 00868 * @brief Stop the LPTIM One pulse generation in interrupt mode. 00869 * @param hlptim LPTIM handle 00870 * @retval HAL status 00871 */ 00872 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim) 00873 { 00874 /* Check the parameters */ 00875 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00876 00877 /* Set the LPTIM state */ 00878 hlptim->State = HAL_LPTIM_STATE_BUSY; 00879 00880 /* Disable the Peripheral */ 00881 __HAL_LPTIM_DISABLE(hlptim); 00882 00883 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 00884 { 00885 return HAL_TIMEOUT; 00886 } 00887 00888 /* Disable Autoreload write complete interrupt */ 00889 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK); 00890 00891 /* Disable Compare write complete interrupt */ 00892 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK); 00893 00894 /* Disable Autoreload match interrupt */ 00895 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM); 00896 00897 /* Disable Compare match interrupt */ 00898 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM); 00899 00900 /* If external trigger source is used, then disable external trigger interrupt */ 00901 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00902 { 00903 /* Disable external trigger interrupt */ 00904 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00905 } 00906 00907 /* Change the LPTIM state*/ 00908 hlptim->State = HAL_LPTIM_STATE_READY; 00909 00910 /* Return function status */ 00911 return HAL_OK; 00912 } 00913 00914 /** 00915 * @brief Start the LPTIM in Set once mode. 00916 * @param hlptim LPTIM handle 00917 * @param Period Specifies the Autoreload value. 00918 * This parameter must be a value between 0x0000 and 0xFFFF. 00919 * @param Pulse Specifies the compare value. 00920 * This parameter must be a value between 0x0000 and 0xFFFF. 00921 * @retval HAL status 00922 */ 00923 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00924 { 00925 /* Check the parameters */ 00926 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00927 assert_param(IS_LPTIM_PERIOD(Period)); 00928 assert_param(IS_LPTIM_PULSE(Pulse)); 00929 00930 /* Set the LPTIM state */ 00931 hlptim->State = HAL_LPTIM_STATE_BUSY; 00932 00933 /* Set WAVE bit to enable the set once mode */ 00934 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE; 00935 00936 /* Enable the Peripheral */ 00937 __HAL_LPTIM_ENABLE(hlptim); 00938 00939 /* Clear flag */ 00940 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 00941 00942 /* Load the period value in the autoreload register */ 00943 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00944 00945 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 00946 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 00947 { 00948 return HAL_TIMEOUT; 00949 } 00950 00951 /* Clear flag */ 00952 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 00953 00954 /* Load the pulse value in the compare register */ 00955 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00956 00957 /* Wait for the completion of the write operation to the LPTIM_CMP register */ 00958 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT) 00959 { 00960 return HAL_TIMEOUT; 00961 } 00962 00963 /* Start timer in single (one shot) mode */ 00964 __HAL_LPTIM_START_SINGLE(hlptim); 00965 00966 /* Change the TIM state*/ 00967 hlptim->State = HAL_LPTIM_STATE_READY; 00968 00969 /* Return function status */ 00970 return HAL_OK; 00971 } 00972 00973 /** 00974 * @brief Stop the LPTIM Set once mode. 00975 * @param hlptim LPTIM handle 00976 * @retval HAL status 00977 */ 00978 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim) 00979 { 00980 /* Check the parameters */ 00981 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00982 00983 /* Set the LPTIM state */ 00984 hlptim->State = HAL_LPTIM_STATE_BUSY; 00985 00986 /* Disable the Peripheral */ 00987 __HAL_LPTIM_DISABLE(hlptim); 00988 00989 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 00990 { 00991 return HAL_TIMEOUT; 00992 } 00993 00994 /* Change the LPTIM state*/ 00995 hlptim->State = HAL_LPTIM_STATE_READY; 00996 00997 /* Return function status */ 00998 return HAL_OK; 00999 } 01000 01001 /** 01002 * @brief Start the LPTIM Set once mode in interrupt mode. 01003 * @param hlptim LPTIM handle 01004 * @param Period Specifies the Autoreload value. 01005 * This parameter must be a value between 0x0000 and 0xFFFF. 01006 * @param Pulse Specifies the compare value. 01007 * This parameter must be a value between 0x0000 and 0xFFFF. 01008 * @retval HAL status 01009 */ 01010 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 01011 { 01012 /* Check the parameters */ 01013 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01014 assert_param(IS_LPTIM_PERIOD(Period)); 01015 assert_param(IS_LPTIM_PULSE(Pulse)); 01016 01017 /* Set the LPTIM state */ 01018 hlptim->State = HAL_LPTIM_STATE_BUSY; 01019 01020 /* Set WAVE bit to enable the set once mode */ 01021 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE; 01022 01023 /* Enable the Peripheral */ 01024 __HAL_LPTIM_ENABLE(hlptim); 01025 01026 /* Clear flag */ 01027 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 01028 01029 /* Load the period value in the autoreload register */ 01030 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01031 01032 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 01033 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 01034 { 01035 return HAL_TIMEOUT; 01036 } 01037 01038 /* Clear flag */ 01039 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 01040 01041 /* Load the pulse value in the compare register */ 01042 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 01043 01044 /* Wait for the completion of the write operation to the LPTIM_CMP register */ 01045 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT) 01046 { 01047 return HAL_TIMEOUT; 01048 } 01049 01050 /* Disable the Peripheral */ 01051 __HAL_LPTIM_DISABLE(hlptim); 01052 01053 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01054 { 01055 return HAL_TIMEOUT; 01056 } 01057 01058 /* Enable Autoreload write complete interrupt */ 01059 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK); 01060 01061 /* Enable Compare write complete interrupt */ 01062 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK); 01063 01064 /* Enable Autoreload match interrupt */ 01065 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM); 01066 01067 /* Enable Compare match interrupt */ 01068 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM); 01069 01070 /* If external trigger source is used, then enable external trigger interrupt */ 01071 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 01072 { 01073 /* Enable external trigger interrupt */ 01074 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 01075 } 01076 01077 /* Enable the Peripheral */ 01078 __HAL_LPTIM_ENABLE(hlptim); 01079 01080 /* Start timer in single (one shot) mode */ 01081 __HAL_LPTIM_START_SINGLE(hlptim); 01082 01083 /* Change the TIM state*/ 01084 hlptim->State = HAL_LPTIM_STATE_READY; 01085 01086 /* Return function status */ 01087 return HAL_OK; 01088 } 01089 01090 /** 01091 * @brief Stop the LPTIM Set once mode in interrupt mode. 01092 * @param hlptim LPTIM handle 01093 * @retval HAL status 01094 */ 01095 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim) 01096 { 01097 /* Check the parameters */ 01098 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01099 01100 /* Set the LPTIM state */ 01101 hlptim->State = HAL_LPTIM_STATE_BUSY; 01102 01103 /* Disable the Peripheral */ 01104 __HAL_LPTIM_DISABLE(hlptim); 01105 01106 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01107 { 01108 return HAL_TIMEOUT; 01109 } 01110 01111 /* Disable Autoreload write complete interrupt */ 01112 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK); 01113 01114 /* Disable Compare write complete interrupt */ 01115 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK); 01116 01117 /* Disable Autoreload match interrupt */ 01118 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM); 01119 01120 /* Disable Compare match interrupt */ 01121 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM); 01122 01123 /* If external trigger source is used, then disable external trigger interrupt */ 01124 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 01125 { 01126 /* Disable external trigger interrupt */ 01127 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 01128 } 01129 01130 /* Change the LPTIM state*/ 01131 hlptim->State = HAL_LPTIM_STATE_READY; 01132 01133 /* Return function status */ 01134 return HAL_OK; 01135 } 01136 01137 /** 01138 * @brief Start the Encoder interface. 01139 * @param hlptim LPTIM handle 01140 * @param Period Specifies the Autoreload value. 01141 * This parameter must be a value between 0x0000 and 0xFFFF. 01142 * @retval HAL status 01143 */ 01144 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period) 01145 { 01146 uint32_t tmpcfgr; 01147 01148 /* Check the parameters */ 01149 assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance)); 01150 assert_param(IS_LPTIM_PERIOD(Period)); 01151 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC); 01152 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1); 01153 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity)); 01154 01155 /* Set the LPTIM state */ 01156 hlptim->State = HAL_LPTIM_STATE_BUSY; 01157 01158 /* Get the LPTIMx CFGR value */ 01159 tmpcfgr = hlptim->Instance->CFGR; 01160 01161 /* Clear CKPOL bits */ 01162 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL); 01163 01164 /* Set Input polarity */ 01165 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity; 01166 01167 /* Write to LPTIMx CFGR */ 01168 hlptim->Instance->CFGR = tmpcfgr; 01169 01170 /* Set ENC bit to enable the encoder interface */ 01171 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC; 01172 01173 /* Enable the Peripheral */ 01174 __HAL_LPTIM_ENABLE(hlptim); 01175 01176 /* Clear flag */ 01177 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 01178 01179 /* Load the period value in the autoreload register */ 01180 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01181 01182 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 01183 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 01184 { 01185 return HAL_TIMEOUT; 01186 } 01187 01188 /* Start timer in continuous mode */ 01189 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01190 01191 /* Change the TIM state*/ 01192 hlptim->State = HAL_LPTIM_STATE_READY; 01193 01194 /* Return function status */ 01195 return HAL_OK; 01196 } 01197 01198 /** 01199 * @brief Stop the Encoder interface. 01200 * @param hlptim LPTIM handle 01201 * @retval HAL status 01202 */ 01203 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim) 01204 { 01205 /* Check the parameters */ 01206 assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance)); 01207 01208 /* Set the LPTIM state */ 01209 hlptim->State = HAL_LPTIM_STATE_BUSY; 01210 01211 /* Disable the Peripheral */ 01212 __HAL_LPTIM_DISABLE(hlptim); 01213 01214 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01215 { 01216 return HAL_TIMEOUT; 01217 } 01218 01219 /* Reset ENC bit to disable the encoder interface */ 01220 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC; 01221 01222 /* Change the TIM state*/ 01223 hlptim->State = HAL_LPTIM_STATE_READY; 01224 01225 /* Return function status */ 01226 return HAL_OK; 01227 } 01228 01229 /** 01230 * @brief Start the Encoder interface in interrupt mode. 01231 * @param hlptim LPTIM handle 01232 * @param Period Specifies the Autoreload value. 01233 * This parameter must be a value between 0x0000 and 0xFFFF. 01234 * @retval HAL status 01235 */ 01236 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period) 01237 { 01238 uint32_t tmpcfgr; 01239 01240 /* Check the parameters */ 01241 assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance)); 01242 assert_param(IS_LPTIM_PERIOD(Period)); 01243 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC); 01244 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1); 01245 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity)); 01246 01247 /* Set the LPTIM state */ 01248 hlptim->State = HAL_LPTIM_STATE_BUSY; 01249 01250 /* Configure edge sensitivity for encoder mode */ 01251 /* Get the LPTIMx CFGR value */ 01252 tmpcfgr = hlptim->Instance->CFGR; 01253 01254 /* Clear CKPOL bits */ 01255 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL); 01256 01257 /* Set Input polarity */ 01258 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity; 01259 01260 /* Write to LPTIMx CFGR */ 01261 hlptim->Instance->CFGR = tmpcfgr; 01262 01263 /* Set ENC bit to enable the encoder interface */ 01264 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC; 01265 01266 /* Enable the Peripheral */ 01267 __HAL_LPTIM_ENABLE(hlptim); 01268 01269 /* Clear flag */ 01270 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 01271 01272 /* Load the period value in the autoreload register */ 01273 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01274 01275 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 01276 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 01277 { 01278 return HAL_TIMEOUT; 01279 } 01280 01281 /* Disable the Peripheral */ 01282 __HAL_LPTIM_DISABLE(hlptim); 01283 01284 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01285 { 01286 return HAL_TIMEOUT; 01287 } 01288 01289 /* Enable "switch to down direction" interrupt */ 01290 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN); 01291 01292 /* Enable "switch to up direction" interrupt */ 01293 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP); 01294 01295 /* Enable the Peripheral */ 01296 __HAL_LPTIM_ENABLE(hlptim); 01297 01298 /* Start timer in continuous mode */ 01299 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01300 01301 /* Change the TIM state*/ 01302 hlptim->State = HAL_LPTIM_STATE_READY; 01303 01304 /* Return function status */ 01305 return HAL_OK; 01306 } 01307 01308 /** 01309 * @brief Stop the Encoder interface in interrupt mode. 01310 * @param hlptim LPTIM handle 01311 * @retval HAL status 01312 */ 01313 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim) 01314 { 01315 /* Check the parameters */ 01316 assert_param(IS_LPTIM_ENCODER_INTERFACE_INSTANCE(hlptim->Instance)); 01317 01318 /* Set the LPTIM state */ 01319 hlptim->State = HAL_LPTIM_STATE_BUSY; 01320 01321 /* Disable the Peripheral */ 01322 __HAL_LPTIM_DISABLE(hlptim); 01323 01324 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01325 { 01326 return HAL_TIMEOUT; 01327 } 01328 01329 /* Reset ENC bit to disable the encoder interface */ 01330 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC; 01331 01332 /* Disable "switch to down direction" interrupt */ 01333 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN); 01334 01335 /* Disable "switch to up direction" interrupt */ 01336 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP); 01337 01338 /* Change the TIM state*/ 01339 hlptim->State = HAL_LPTIM_STATE_READY; 01340 01341 /* Return function status */ 01342 return HAL_OK; 01343 } 01344 01345 /** 01346 * @brief Start the Timeout function. 01347 * @note The first trigger event will start the timer, any successive 01348 * trigger event will reset the counter and the timer restarts. 01349 * @param hlptim LPTIM handle 01350 * @param Period Specifies the Autoreload value. 01351 * This parameter must be a value between 0x0000 and 0xFFFF. 01352 * @param Timeout Specifies the TimeOut value to reset the counter. 01353 * This parameter must be a value between 0x0000 and 0xFFFF. 01354 * @retval HAL status 01355 */ 01356 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout) 01357 { 01358 /* Check the parameters */ 01359 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01360 assert_param(IS_LPTIM_PERIOD(Period)); 01361 assert_param(IS_LPTIM_PULSE(Timeout)); 01362 01363 /* Set the LPTIM state */ 01364 hlptim->State = HAL_LPTIM_STATE_BUSY; 01365 01366 /* Set TIMOUT bit to enable the timeout function */ 01367 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT; 01368 01369 /* Enable the Peripheral */ 01370 __HAL_LPTIM_ENABLE(hlptim); 01371 01372 /* Clear flag */ 01373 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 01374 01375 /* Load the period value in the autoreload register */ 01376 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01377 01378 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 01379 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 01380 { 01381 return HAL_TIMEOUT; 01382 } 01383 01384 /* Clear flag */ 01385 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 01386 01387 /* Load the Timeout value in the compare register */ 01388 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout); 01389 01390 /* Wait for the completion of the write operation to the LPTIM_CMP register */ 01391 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT) 01392 { 01393 return HAL_TIMEOUT; 01394 } 01395 01396 /* Start timer in continuous mode */ 01397 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01398 01399 /* Change the TIM state*/ 01400 hlptim->State = HAL_LPTIM_STATE_READY; 01401 01402 /* Return function status */ 01403 return HAL_OK; 01404 } 01405 01406 /** 01407 * @brief Stop the Timeout function. 01408 * @param hlptim LPTIM handle 01409 * @retval HAL status 01410 */ 01411 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim) 01412 { 01413 /* Check the parameters */ 01414 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01415 01416 /* Set the LPTIM state */ 01417 hlptim->State = HAL_LPTIM_STATE_BUSY; 01418 01419 /* Disable the Peripheral */ 01420 __HAL_LPTIM_DISABLE(hlptim); 01421 01422 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01423 { 01424 return HAL_TIMEOUT; 01425 } 01426 01427 /* Reset TIMOUT bit to enable the timeout function */ 01428 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT; 01429 01430 /* Change the TIM state*/ 01431 hlptim->State = HAL_LPTIM_STATE_READY; 01432 01433 /* Return function status */ 01434 return HAL_OK; 01435 } 01436 01437 /** 01438 * @brief Start the Timeout function in interrupt mode. 01439 * @note The first trigger event will start the timer, any successive 01440 * trigger event will reset the counter and the timer restarts. 01441 * @param hlptim LPTIM handle 01442 * @param Period Specifies the Autoreload value. 01443 * This parameter must be a value between 0x0000 and 0xFFFF. 01444 * @param Timeout Specifies the TimeOut value to reset the counter. 01445 * This parameter must be a value between 0x0000 and 0xFFFF. 01446 * @retval HAL status 01447 */ 01448 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout) 01449 { 01450 /* Check the parameters */ 01451 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01452 assert_param(IS_LPTIM_PERIOD(Period)); 01453 assert_param(IS_LPTIM_PULSE(Timeout)); 01454 01455 /* Set the LPTIM state */ 01456 hlptim->State = HAL_LPTIM_STATE_BUSY; 01457 01458 /* Set TIMOUT bit to enable the timeout function */ 01459 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT; 01460 01461 /* Enable the Peripheral */ 01462 __HAL_LPTIM_ENABLE(hlptim); 01463 01464 /* Clear flag */ 01465 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 01466 01467 /* Load the period value in the autoreload register */ 01468 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01469 01470 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 01471 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 01472 { 01473 return HAL_TIMEOUT; 01474 } 01475 01476 /* Clear flag */ 01477 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 01478 01479 /* Load the Timeout value in the compare register */ 01480 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout); 01481 01482 /* Wait for the completion of the write operation to the LPTIM_CMP register */ 01483 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT) 01484 { 01485 return HAL_TIMEOUT; 01486 } 01487 01488 /* Disable the Peripheral */ 01489 __HAL_LPTIM_DISABLE(hlptim); 01490 01491 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01492 { 01493 return HAL_TIMEOUT; 01494 } 01495 01496 /* Enable Compare match interrupt */ 01497 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM); 01498 01499 /* Enable the Peripheral */ 01500 __HAL_LPTIM_ENABLE(hlptim); 01501 01502 /* Start timer in continuous mode */ 01503 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01504 01505 /* Change the TIM state*/ 01506 hlptim->State = HAL_LPTIM_STATE_READY; 01507 01508 /* Return function status */ 01509 return HAL_OK; 01510 } 01511 01512 /** 01513 * @brief Stop the Timeout function in interrupt mode. 01514 * @param hlptim LPTIM handle 01515 * @retval HAL status 01516 */ 01517 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim) 01518 { 01519 /* Check the parameters */ 01520 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01521 01522 /* Set the LPTIM state */ 01523 hlptim->State = HAL_LPTIM_STATE_BUSY; 01524 01525 /* Disable the Peripheral */ 01526 __HAL_LPTIM_DISABLE(hlptim); 01527 01528 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01529 { 01530 return HAL_TIMEOUT; 01531 } 01532 01533 /* Reset TIMOUT bit to enable the timeout function */ 01534 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT; 01535 01536 /* Disable Compare match interrupt */ 01537 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM); 01538 01539 /* Change the TIM state*/ 01540 hlptim->State = HAL_LPTIM_STATE_READY; 01541 01542 /* Return function status */ 01543 return HAL_OK; 01544 } 01545 01546 /** 01547 * @brief Start the Counter mode. 01548 * @param hlptim LPTIM handle 01549 * @param Period Specifies the Autoreload value. 01550 * This parameter must be a value between 0x0000 and 0xFFFF. 01551 * @retval HAL status 01552 */ 01553 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period) 01554 { 01555 /* Check the parameters */ 01556 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01557 assert_param(IS_LPTIM_PERIOD(Period)); 01558 01559 /* Set the LPTIM state */ 01560 hlptim->State = HAL_LPTIM_STATE_BUSY; 01561 01562 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */ 01563 if ((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) 01564 && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL)) 01565 { 01566 /* Check if clock is prescaled */ 01567 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler)); 01568 /* Set clock prescaler to 0 */ 01569 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC; 01570 } 01571 01572 /* Enable the Peripheral */ 01573 __HAL_LPTIM_ENABLE(hlptim); 01574 01575 /* Clear flag */ 01576 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 01577 01578 /* Load the period value in the autoreload register */ 01579 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01580 01581 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 01582 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 01583 { 01584 return HAL_TIMEOUT; 01585 } 01586 01587 /* Start timer in continuous mode */ 01588 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01589 01590 /* Change the TIM state*/ 01591 hlptim->State = HAL_LPTIM_STATE_READY; 01592 01593 /* Return function status */ 01594 return HAL_OK; 01595 } 01596 01597 /** 01598 * @brief Stop the Counter mode. 01599 * @param hlptim LPTIM handle 01600 * @retval HAL status 01601 */ 01602 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim) 01603 { 01604 /* Check the parameters */ 01605 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01606 01607 /* Set the LPTIM state */ 01608 hlptim->State = HAL_LPTIM_STATE_BUSY; 01609 01610 /* Disable the Peripheral */ 01611 __HAL_LPTIM_DISABLE(hlptim); 01612 01613 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01614 { 01615 return HAL_TIMEOUT; 01616 } 01617 01618 /* Change the TIM state*/ 01619 hlptim->State = HAL_LPTIM_STATE_READY; 01620 01621 /* Return function status */ 01622 return HAL_OK; 01623 } 01624 01625 /** 01626 * @brief Start the Counter mode in interrupt mode. 01627 * @param hlptim LPTIM handle 01628 * @param Period Specifies the Autoreload value. 01629 * This parameter must be a value between 0x0000 and 0xFFFF. 01630 * @retval HAL status 01631 */ 01632 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period) 01633 { 01634 /* Check the parameters */ 01635 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01636 assert_param(IS_LPTIM_PERIOD(Period)); 01637 01638 /* Set the LPTIM state */ 01639 hlptim->State = HAL_LPTIM_STATE_BUSY; 01640 01641 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */ 01642 if ((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) 01643 && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL)) 01644 { 01645 /* Check if clock is prescaled */ 01646 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler)); 01647 /* Set clock prescaler to 0 */ 01648 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC; 01649 } 01650 01651 /* Enable the Peripheral */ 01652 __HAL_LPTIM_ENABLE(hlptim); 01653 01654 /* Clear flag */ 01655 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 01656 01657 /* Load the period value in the autoreload register */ 01658 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01659 01660 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 01661 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 01662 { 01663 return HAL_TIMEOUT; 01664 } 01665 01666 /* Disable the Peripheral */ 01667 __HAL_LPTIM_DISABLE(hlptim); 01668 01669 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01670 { 01671 return HAL_TIMEOUT; 01672 } 01673 01674 /* Enable Autoreload write complete interrupt */ 01675 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK); 01676 01677 /* Enable Autoreload match interrupt */ 01678 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM); 01679 01680 /* Enable the Peripheral */ 01681 __HAL_LPTIM_ENABLE(hlptim); 01682 01683 /* Start timer in continuous mode */ 01684 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01685 01686 /* Change the TIM state*/ 01687 hlptim->State = HAL_LPTIM_STATE_READY; 01688 01689 /* Return function status */ 01690 return HAL_OK; 01691 } 01692 01693 /** 01694 * @brief Stop the Counter mode in interrupt mode. 01695 * @param hlptim LPTIM handle 01696 * @retval HAL status 01697 */ 01698 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim) 01699 { 01700 /* Check the parameters */ 01701 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01702 01703 /* Set the LPTIM state */ 01704 hlptim->State = HAL_LPTIM_STATE_BUSY; 01705 01706 /* Disable the Peripheral */ 01707 __HAL_LPTIM_DISABLE(hlptim); 01708 01709 if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT) 01710 { 01711 return HAL_TIMEOUT; 01712 } 01713 01714 /* Disable Autoreload write complete interrupt */ 01715 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK); 01716 01717 /* Disable Autoreload match interrupt */ 01718 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM); 01719 /* Change the TIM state*/ 01720 hlptim->State = HAL_LPTIM_STATE_READY; 01721 01722 /* Return function status */ 01723 return HAL_OK; 01724 } 01725 01726 /** 01727 * @} 01728 */ 01729 01730 /** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions 01731 * @brief Read operation functions. 01732 * 01733 @verbatim 01734 ============================================================================== 01735 ##### LPTIM Read operation functions ##### 01736 ============================================================================== 01737 [..] This section provides LPTIM Reading functions. 01738 (+) Read the counter value. 01739 (+) Read the period (Auto-reload) value. 01740 (+) Read the pulse (Compare)value. 01741 @endverbatim 01742 * @{ 01743 */ 01744 01745 /** 01746 * @brief Return the current counter value. 01747 * @param hlptim LPTIM handle 01748 * @retval Counter value. 01749 */ 01750 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim) 01751 { 01752 /* Check the parameters */ 01753 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01754 01755 return (hlptim->Instance->CNT); 01756 } 01757 01758 /** 01759 * @brief Return the current Autoreload (Period) value. 01760 * @param hlptim LPTIM handle 01761 * @retval Autoreload value. 01762 */ 01763 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim) 01764 { 01765 /* Check the parameters */ 01766 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01767 01768 return (hlptim->Instance->ARR); 01769 } 01770 01771 /** 01772 * @brief Return the current Compare (Pulse) value. 01773 * @param hlptim LPTIM handle 01774 * @retval Compare value. 01775 */ 01776 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim) 01777 { 01778 /* Check the parameters */ 01779 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01780 01781 return (hlptim->Instance->CMP); 01782 } 01783 01784 /** 01785 * @} 01786 */ 01787 01788 /** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks 01789 * @brief LPTIM IRQ handler. 01790 * 01791 @verbatim 01792 ============================================================================== 01793 ##### LPTIM IRQ handler and callbacks ##### 01794 ============================================================================== 01795 [..] This section provides LPTIM IRQ handler and callback functions called within 01796 the IRQ handler: 01797 (+) LPTIM interrupt request handler 01798 (+) Compare match Callback 01799 (+) Auto-reload match Callback 01800 (+) External trigger event detection Callback 01801 (+) Compare register write complete Callback 01802 (+) Auto-reload register write complete Callback 01803 (+) Up-counting direction change Callback 01804 (+) Down-counting direction change Callback 01805 01806 @endverbatim 01807 * @{ 01808 */ 01809 01810 /** 01811 * @brief Handle LPTIM interrupt request. 01812 * @param hlptim LPTIM handle 01813 * @retval None 01814 */ 01815 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim) 01816 { 01817 /* Compare match interrupt */ 01818 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET) 01819 { 01820 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) != RESET) 01821 { 01822 /* Clear Compare match flag */ 01823 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM); 01824 01825 /* Compare match Callback */ 01826 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01827 hlptim->CompareMatchCallback(hlptim); 01828 #else 01829 HAL_LPTIM_CompareMatchCallback(hlptim); 01830 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01831 } 01832 } 01833 01834 /* Autoreload match interrupt */ 01835 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET) 01836 { 01837 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET) 01838 { 01839 /* Clear Autoreload match flag */ 01840 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM); 01841 01842 /* Autoreload match Callback */ 01843 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01844 hlptim->AutoReloadMatchCallback(hlptim); 01845 #else 01846 HAL_LPTIM_AutoReloadMatchCallback(hlptim); 01847 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01848 } 01849 } 01850 01851 /* Trigger detected interrupt */ 01852 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET) 01853 { 01854 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) != RESET) 01855 { 01856 /* Clear Trigger detected flag */ 01857 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG); 01858 01859 /* Trigger detected callback */ 01860 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01861 hlptim->TriggerCallback(hlptim); 01862 #else 01863 HAL_LPTIM_TriggerCallback(hlptim); 01864 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01865 } 01866 } 01867 01868 /* Compare write interrupt */ 01869 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET) 01870 { 01871 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) != RESET) 01872 { 01873 /* Clear Compare write flag */ 01874 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 01875 01876 /* Compare write Callback */ 01877 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01878 hlptim->CompareWriteCallback(hlptim); 01879 #else 01880 HAL_LPTIM_CompareWriteCallback(hlptim); 01881 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01882 } 01883 } 01884 01885 /* Autoreload write interrupt */ 01886 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET) 01887 { 01888 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET) 01889 { 01890 /* Clear Autoreload write flag */ 01891 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 01892 01893 /* Autoreload write Callback */ 01894 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01895 hlptim->AutoReloadWriteCallback(hlptim); 01896 #else 01897 HAL_LPTIM_AutoReloadWriteCallback(hlptim); 01898 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01899 } 01900 } 01901 01902 /* Direction counter changed from Down to Up interrupt */ 01903 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET) 01904 { 01905 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) != RESET) 01906 { 01907 /* Clear Direction counter changed from Down to Up flag */ 01908 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP); 01909 01910 /* Direction counter changed from Down to Up Callback */ 01911 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01912 hlptim->DirectionUpCallback(hlptim); 01913 #else 01914 HAL_LPTIM_DirectionUpCallback(hlptim); 01915 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01916 } 01917 } 01918 01919 /* Direction counter changed from Up to Down interrupt */ 01920 if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET) 01921 { 01922 if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) != RESET) 01923 { 01924 /* Clear Direction counter changed from Up to Down flag */ 01925 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN); 01926 01927 /* Direction counter changed from Up to Down Callback */ 01928 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01929 hlptim->DirectionDownCallback(hlptim); 01930 #else 01931 HAL_LPTIM_DirectionDownCallback(hlptim); 01932 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01933 } 01934 } 01935 } 01936 01937 /** 01938 * @brief Compare match callback in non-blocking mode. 01939 * @param hlptim LPTIM handle 01940 * @retval None 01941 */ 01942 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) 01943 { 01944 /* Prevent unused argument(s) compilation warning */ 01945 UNUSED(hlptim); 01946 01947 /* NOTE : This function should not be modified, when the callback is needed, 01948 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file 01949 */ 01950 } 01951 01952 /** 01953 * @brief Autoreload match callback in non-blocking mode. 01954 * @param hlptim LPTIM handle 01955 * @retval None 01956 */ 01957 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim) 01958 { 01959 /* Prevent unused argument(s) compilation warning */ 01960 UNUSED(hlptim); 01961 01962 /* NOTE : This function should not be modified, when the callback is needed, 01963 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file 01964 */ 01965 } 01966 01967 /** 01968 * @brief Trigger detected callback in non-blocking mode. 01969 * @param hlptim LPTIM handle 01970 * @retval None 01971 */ 01972 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim) 01973 { 01974 /* Prevent unused argument(s) compilation warning */ 01975 UNUSED(hlptim); 01976 01977 /* NOTE : This function should not be modified, when the callback is needed, 01978 the HAL_LPTIM_TriggerCallback could be implemented in the user file 01979 */ 01980 } 01981 01982 /** 01983 * @brief Compare write callback in non-blocking mode. 01984 * @param hlptim LPTIM handle 01985 * @retval None 01986 */ 01987 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim) 01988 { 01989 /* Prevent unused argument(s) compilation warning */ 01990 UNUSED(hlptim); 01991 01992 /* NOTE : This function should not be modified, when the callback is needed, 01993 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file 01994 */ 01995 } 01996 01997 /** 01998 * @brief Autoreload write callback in non-blocking mode. 01999 * @param hlptim LPTIM handle 02000 * @retval None 02001 */ 02002 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim) 02003 { 02004 /* Prevent unused argument(s) compilation warning */ 02005 UNUSED(hlptim); 02006 02007 /* NOTE : This function should not be modified, when the callback is needed, 02008 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file 02009 */ 02010 } 02011 02012 /** 02013 * @brief Direction counter changed from Down to Up callback in non-blocking mode. 02014 * @param hlptim LPTIM handle 02015 * @retval None 02016 */ 02017 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim) 02018 { 02019 /* Prevent unused argument(s) compilation warning */ 02020 UNUSED(hlptim); 02021 02022 /* NOTE : This function should not be modified, when the callback is needed, 02023 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file 02024 */ 02025 } 02026 02027 /** 02028 * @brief Direction counter changed from Up to Down callback in non-blocking mode. 02029 * @param hlptim LPTIM handle 02030 * @retval None 02031 */ 02032 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim) 02033 { 02034 /* Prevent unused argument(s) compilation warning */ 02035 UNUSED(hlptim); 02036 02037 /* NOTE : This function should not be modified, when the callback is needed, 02038 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file 02039 */ 02040 } 02041 02042 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 02043 /** 02044 * @brief Register a User LPTIM callback to be used instead of the weak predefined callback 02045 * @param hlptim LPTIM handle 02046 * @param CallbackID ID of the callback to be registered 02047 * This parameter can be one of the following values: 02048 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID 02049 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID 02050 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID 02051 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID 02052 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID 02053 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID 02054 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID 02055 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID 02056 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID 02057 * @param pCallback pointer to the callback function 02058 * @retval status 02059 */ 02060 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *hlptim, 02061 HAL_LPTIM_CallbackIDTypeDef CallbackID, 02062 pLPTIM_CallbackTypeDef pCallback) 02063 { 02064 HAL_StatusTypeDef status = HAL_OK; 02065 02066 if (pCallback == NULL) 02067 { 02068 return HAL_ERROR; 02069 } 02070 02071 /* Process locked */ 02072 __HAL_LOCK(hlptim); 02073 02074 if (hlptim->State == HAL_LPTIM_STATE_READY) 02075 { 02076 switch (CallbackID) 02077 { 02078 case HAL_LPTIM_MSPINIT_CB_ID : 02079 hlptim->MspInitCallback = pCallback; 02080 break; 02081 02082 case HAL_LPTIM_MSPDEINIT_CB_ID : 02083 hlptim->MspDeInitCallback = pCallback; 02084 break; 02085 02086 case HAL_LPTIM_COMPARE_MATCH_CB_ID : 02087 hlptim->CompareMatchCallback = pCallback; 02088 break; 02089 02090 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID : 02091 hlptim->AutoReloadMatchCallback = pCallback; 02092 break; 02093 02094 case HAL_LPTIM_TRIGGER_CB_ID : 02095 hlptim->TriggerCallback = pCallback; 02096 break; 02097 02098 case HAL_LPTIM_COMPARE_WRITE_CB_ID : 02099 hlptim->CompareWriteCallback = pCallback; 02100 break; 02101 02102 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID : 02103 hlptim->AutoReloadWriteCallback = pCallback; 02104 break; 02105 02106 case HAL_LPTIM_DIRECTION_UP_CB_ID : 02107 hlptim->DirectionUpCallback = pCallback; 02108 break; 02109 02110 case HAL_LPTIM_DIRECTION_DOWN_CB_ID : 02111 hlptim->DirectionDownCallback = pCallback; 02112 break; 02113 02114 default : 02115 /* Return error status */ 02116 status = HAL_ERROR; 02117 break; 02118 } 02119 } 02120 else if (hlptim->State == HAL_LPTIM_STATE_RESET) 02121 { 02122 switch (CallbackID) 02123 { 02124 case HAL_LPTIM_MSPINIT_CB_ID : 02125 hlptim->MspInitCallback = pCallback; 02126 break; 02127 02128 case HAL_LPTIM_MSPDEINIT_CB_ID : 02129 hlptim->MspDeInitCallback = pCallback; 02130 break; 02131 02132 default : 02133 /* Return error status */ 02134 status = HAL_ERROR; 02135 break; 02136 } 02137 } 02138 else 02139 { 02140 /* Return error status */ 02141 status = HAL_ERROR; 02142 } 02143 02144 /* Release Lock */ 02145 __HAL_UNLOCK(hlptim); 02146 02147 return status; 02148 } 02149 02150 /** 02151 * @brief Unregister a LPTIM callback 02152 * LLPTIM callback is redirected to the weak predefined callback 02153 * @param hlptim LPTIM handle 02154 * @param CallbackID ID of the callback to be unregistered 02155 * This parameter can be one of the following values: 02156 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID 02157 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID 02158 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID 02159 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID 02160 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID 02161 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID 02162 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID 02163 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID 02164 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID 02165 * @retval status 02166 */ 02167 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *hlptim, 02168 HAL_LPTIM_CallbackIDTypeDef CallbackID) 02169 { 02170 HAL_StatusTypeDef status = HAL_OK; 02171 02172 /* Process locked */ 02173 __HAL_LOCK(hlptim); 02174 02175 if (hlptim->State == HAL_LPTIM_STATE_READY) 02176 { 02177 switch (CallbackID) 02178 { 02179 case HAL_LPTIM_MSPINIT_CB_ID : 02180 /* Legacy weak MspInit Callback */ 02181 hlptim->MspInitCallback = HAL_LPTIM_MspInit; 02182 break; 02183 02184 case HAL_LPTIM_MSPDEINIT_CB_ID : 02185 /* Legacy weak Msp DeInit Callback */ 02186 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; 02187 break; 02188 02189 case HAL_LPTIM_COMPARE_MATCH_CB_ID : 02190 /* Legacy weak Compare match Callback */ 02191 hlptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback; 02192 break; 02193 02194 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID : 02195 /* Legacy weak Auto-reload match Callback */ 02196 hlptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; 02197 break; 02198 02199 case HAL_LPTIM_TRIGGER_CB_ID : 02200 /* Legacy weak External trigger event detection Callback */ 02201 hlptim->TriggerCallback = HAL_LPTIM_TriggerCallback; 02202 break; 02203 02204 case HAL_LPTIM_COMPARE_WRITE_CB_ID : 02205 /* Legacy weak Compare register write complete Callback */ 02206 hlptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback; 02207 break; 02208 02209 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID : 02210 /* Legacy weak Auto-reload register write complete Callback */ 02211 hlptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback; 02212 break; 02213 02214 case HAL_LPTIM_DIRECTION_UP_CB_ID : 02215 /* Legacy weak Up-counting direction change Callback */ 02216 hlptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback; 02217 break; 02218 02219 case HAL_LPTIM_DIRECTION_DOWN_CB_ID : 02220 /* Legacy weak Down-counting direction change Callback */ 02221 hlptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback; 02222 break; 02223 02224 default : 02225 /* Return error status */ 02226 status = HAL_ERROR; 02227 break; 02228 } 02229 } 02230 else if (hlptim->State == HAL_LPTIM_STATE_RESET) 02231 { 02232 switch (CallbackID) 02233 { 02234 case HAL_LPTIM_MSPINIT_CB_ID : 02235 /* Legacy weak MspInit Callback */ 02236 hlptim->MspInitCallback = HAL_LPTIM_MspInit; 02237 break; 02238 02239 case HAL_LPTIM_MSPDEINIT_CB_ID : 02240 /* Legacy weak Msp DeInit Callback */ 02241 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; 02242 break; 02243 02244 default : 02245 /* Return error status */ 02246 status = HAL_ERROR; 02247 break; 02248 } 02249 } 02250 else 02251 { 02252 /* Return error status */ 02253 status = HAL_ERROR; 02254 } 02255 02256 /* Release Lock */ 02257 __HAL_UNLOCK(hlptim); 02258 02259 return status; 02260 } 02261 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 02262 02263 /** 02264 * @} 02265 */ 02266 02267 /** @defgroup LPTIM_Group5 Peripheral State functions 02268 * @brief Peripheral State functions. 02269 * 02270 @verbatim 02271 ============================================================================== 02272 ##### Peripheral State functions ##### 02273 ============================================================================== 02274 [..] 02275 This subsection permits to get in run-time the status of the peripheral. 02276 02277 @endverbatim 02278 * @{ 02279 */ 02280 02281 /** 02282 * @brief Return the LPTIM handle state. 02283 * @param hlptim LPTIM handle 02284 * @retval HAL state 02285 */ 02286 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim) 02287 { 02288 /* Return LPTIM handle state */ 02289 return hlptim->State; 02290 } 02291 02292 /** 02293 * @} 02294 */ 02295 02296 02297 /** 02298 * @} 02299 */ 02300 02301 /* Private functions ---------------------------------------------------------*/ 02302 02303 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions 02304 * @{ 02305 */ 02306 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 02307 /** 02308 * @brief Reset interrupt callbacks to the legacy weak callbacks. 02309 * @param lptim pointer to a LPTIM_HandleTypeDef structure that contains 02310 * the configuration information for LPTIM module. 02311 * @retval None 02312 */ 02313 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim) 02314 { 02315 /* Reset the LPTIM callback to the legacy weak callbacks */ 02316 lptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback; 02317 lptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; 02318 lptim->TriggerCallback = HAL_LPTIM_TriggerCallback; 02319 lptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback; 02320 lptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback; 02321 lptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback; 02322 lptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback; 02323 } 02324 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 02325 02326 /** 02327 * @brief LPTimer Wait for flag set 02328 * @param hlptim pointer to a LPTIM_HandleTypeDef structure that contains 02329 * the configuration information for LPTIM module. 02330 * @param flag The lptim flag 02331 * @retval HAL status 02332 */ 02333 static HAL_StatusTypeDef LPTIM_WaitForFlag(LPTIM_HandleTypeDef *hlptim, uint32_t flag) 02334 { 02335 HAL_StatusTypeDef result = HAL_OK; 02336 uint32_t count = TIMEOUT * (SystemCoreClock / 20UL / 1000UL); 02337 do 02338 { 02339 count--; 02340 if (count == 0UL) 02341 { 02342 result = HAL_TIMEOUT; 02343 } 02344 } while ((!(__HAL_LPTIM_GET_FLAG((hlptim), (flag)))) && (count != 0UL)); 02345 02346 return result; 02347 } 02348 02349 /** 02350 * @brief Disable LPTIM HW instance. 02351 * @param hlptim pointer to a LPTIM_HandleTypeDef structure that contains 02352 * the configuration information for LPTIM module. 02353 * @note The following sequence is required to solve LPTIM disable HW limitation. 02354 * Please check Errata Sheet ES0335 for more details under "MCU may remain 02355 * stuck in LPTIM interrupt when entering Stop mode" section. 02356 * @retval None 02357 */ 02358 void LPTIM_Disable(LPTIM_HandleTypeDef *hlptim) 02359 { 02360 uint32_t tmpclksource = 0; 02361 uint32_t tmpIER; 02362 uint32_t tmpCFGR; 02363 uint32_t tmpCMP; 02364 uint32_t tmpARR; 02365 uint32_t primask_bit; 02366 uint32_t tmpCFGR2; 02367 02368 /* Enter critical section */ 02369 primask_bit = __get_PRIMASK(); 02370 __set_PRIMASK(1) ; 02371 02372 /*********** Save LPTIM Config ***********/ 02373 /* Save LPTIM source clock */ 02374 switch ((uint32_t)hlptim->Instance) 02375 { 02376 case LPTIM1_BASE: 02377 tmpclksource = __HAL_RCC_GET_LPTIM1_SOURCE(); 02378 break; 02379 case LPTIM2_BASE: 02380 tmpclksource = __HAL_RCC_GET_LPTIM2_SOURCE(); 02381 break; 02382 #if defined(LPTIM3) 02383 case LPTIM3_BASE: 02384 tmpclksource = __HAL_RCC_GET_LPTIM3_SOURCE(); 02385 break; 02386 #endif /* LPTIM3 */ 02387 #if defined(LPTIM4) 02388 case LPTIM4_BASE: 02389 tmpclksource = __HAL_RCC_GET_LPTIM4_SOURCE(); 02390 break; 02391 #endif /* LPTIM4 */ 02392 #if defined(LPTIM5) 02393 case LPTIM5_BASE: 02394 tmpclksource = __HAL_RCC_GET_LPTIM5_SOURCE(); 02395 break; 02396 #endif /* LPTIM5 */ 02397 default: 02398 break; 02399 } 02400 02401 /* Save LPTIM configuration registers */ 02402 tmpIER = hlptim->Instance->IER; 02403 tmpCFGR = hlptim->Instance->CFGR; 02404 tmpCMP = hlptim->Instance->CMP; 02405 tmpARR = hlptim->Instance->ARR; 02406 tmpCFGR2 = hlptim->Instance->CFGR2; 02407 02408 /*********** Reset LPTIM ***********/ 02409 switch ((uint32_t)hlptim->Instance) 02410 { 02411 case LPTIM1_BASE: 02412 __HAL_RCC_LPTIM1_FORCE_RESET(); 02413 __HAL_RCC_LPTIM1_RELEASE_RESET(); 02414 break; 02415 case LPTIM2_BASE: 02416 __HAL_RCC_LPTIM2_FORCE_RESET(); 02417 __HAL_RCC_LPTIM2_RELEASE_RESET(); 02418 break; 02419 #if defined(LPTIM3) 02420 case LPTIM3_BASE: 02421 __HAL_RCC_LPTIM3_FORCE_RESET(); 02422 __HAL_RCC_LPTIM3_RELEASE_RESET(); 02423 break; 02424 #endif /* LPTIM3 */ 02425 #if defined(LPTIM4) 02426 case LPTIM4_BASE: 02427 __HAL_RCC_LPTIM4_FORCE_RESET(); 02428 __HAL_RCC_LPTIM4_RELEASE_RESET(); 02429 break; 02430 #endif /* LPTIM4 */ 02431 #if defined(LPTIM5) 02432 case LPTIM5_BASE: 02433 __HAL_RCC_LPTIM5_FORCE_RESET(); 02434 __HAL_RCC_LPTIM5_RELEASE_RESET(); 02435 break; 02436 #endif /* LPTIM5 */ 02437 default: 02438 break; 02439 } 02440 02441 /*********** Restore LPTIM Config ***********/ 02442 if ((tmpCMP != 0UL) || (tmpARR != 0UL)) 02443 { 02444 /* Force LPTIM source kernel clock from APB */ 02445 switch ((uint32_t)hlptim->Instance) 02446 { 02447 case LPTIM1_BASE: 02448 __HAL_RCC_LPTIM1_CONFIG(RCC_LPTIM1CLKSOURCE_D2PCLK1); 02449 break; 02450 case LPTIM2_BASE: 02451 __HAL_RCC_LPTIM2_CONFIG(RCC_LPTIM2CLKSOURCE_D3PCLK1); 02452 break; 02453 #if defined(LPTIM3) 02454 case LPTIM3_BASE: 02455 __HAL_RCC_LPTIM3_CONFIG(RCC_LPTIM3CLKSOURCE_D3PCLK1); 02456 break; 02457 #endif /* LPTIM3 */ 02458 #if defined(LPTIM4) 02459 case LPTIM4_BASE: 02460 __HAL_RCC_LPTIM4_CONFIG(RCC_LPTIM4CLKSOURCE_D3PCLK1); 02461 break; 02462 #endif /* LPTIM4 */ 02463 #if defined(LPTIM5) 02464 case LPTIM5_BASE: 02465 __HAL_RCC_LPTIM5_CONFIG(RCC_LPTIM5CLKSOURCE_D3PCLK1); 02466 break; 02467 #endif /* LPTIM5 */ 02468 default: 02469 break; 02470 } 02471 02472 if (tmpCMP != 0UL) 02473 { 02474 /* Restore CMP register (LPTIM should be enabled first) */ 02475 hlptim->Instance->CR |= LPTIM_CR_ENABLE; 02476 hlptim->Instance->CMP = tmpCMP; 02477 02478 /* Wait for the completion of the write operation to the LPTIM_CMP register */ 02479 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT) 02480 { 02481 hlptim->State = HAL_LPTIM_STATE_TIMEOUT; 02482 } 02483 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 02484 } 02485 02486 if (tmpARR != 0UL) 02487 { 02488 /* Restore ARR register (LPTIM should be enabled first) */ 02489 hlptim->Instance->CR |= LPTIM_CR_ENABLE; 02490 hlptim->Instance->ARR = tmpARR; 02491 02492 /* Wait for the completion of the write operation to the LPTIM_ARR register */ 02493 if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT) 02494 { 02495 hlptim->State = HAL_LPTIM_STATE_TIMEOUT; 02496 } 02497 02498 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 02499 } 02500 02501 /* Restore LPTIM source kernel clock */ 02502 switch ((uint32_t)hlptim->Instance) 02503 { 02504 case LPTIM1_BASE: 02505 __HAL_RCC_LPTIM1_CONFIG(tmpclksource); 02506 break; 02507 case LPTIM2_BASE: 02508 __HAL_RCC_LPTIM2_CONFIG(tmpclksource); 02509 break; 02510 #if defined(LPTIM3) 02511 case LPTIM3_BASE: 02512 __HAL_RCC_LPTIM3_CONFIG(tmpclksource); 02513 break; 02514 #endif /* LPTIM3 */ 02515 #if defined(LPTIM4) 02516 case LPTIM4_BASE: 02517 __HAL_RCC_LPTIM4_CONFIG(tmpclksource); 02518 break; 02519 #endif /* LPTIM4 */ 02520 #if defined(LPTIM5) 02521 case LPTIM5_BASE: 02522 __HAL_RCC_LPTIM5_CONFIG(tmpclksource); 02523 break; 02524 #endif /* LPTIM5 */ 02525 default: 02526 break; 02527 } 02528 } 02529 02530 /* Restore configuration registers (LPTIM should be disabled first) */ 02531 hlptim->Instance->CR &= ~(LPTIM_CR_ENABLE); 02532 hlptim->Instance->IER = tmpIER; 02533 hlptim->Instance->CFGR = tmpCFGR; 02534 hlptim->Instance->CFGR2 = tmpCFGR2; 02535 02536 /* Exit critical section: restore previous priority mask */ 02537 __set_PRIMASK(primask_bit); 02538 } 02539 /** 02540 * @} 02541 */ 02542 #endif /* LPTIM1 || LPTIM2 || LPTIM3 || LPTIM4 || LPTIM5 */ 02543 02544 #endif /* HAL_LPTIM_MODULE_ENABLED */ 02545 /** 02546 * @} 02547 */ 02548 02549 /** 02550 * @} 02551 */