stm32l4xx_hal_lptim.c 51 KB

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