stm32f7xx_hal_lptim.c 62 KB

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