stm32h7xx_hal_lptim.c 51 KB

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