stm32l4xx_hal_lptim.c 53 KB

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