2460 lines
73 KiB
C
Raw Normal View History

2019-04-29 14:39:56 +01:00
/**
******************************************************************************
* @file stm32f7xx_hal_lptim.c
* @author MCD Application Team
* @brief LPTIM HAL module driver.
2020-02-27 17:03:12 +01:00
* This file provides firmware functions to manage the following
2019-04-29 14:39:56 +01:00
* functionalities of the Low Power Timer (LPTIM) peripheral:
* + Initialization and de-initialization functions.
* + Start/Stop operation functions in polling mode.
* + Start/Stop operation functions in interrupt mode.
* + Reading operation functions.
* + Peripheral State functions.
2020-02-27 17:03:12 +01:00
*
2021-12-14 09:25:05 +01:00
******************************************************************************
* @attention
*
* Copyright (c) 2017 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
2019-04-29 14:39:56 +01:00
@verbatim
==============================================================================
##### How to use this driver #####
==============================================================================
[..]
The LPTIM HAL driver can be used as follows:
(#)Initialize the LPTIM low level resources by implementing the
HAL_LPTIM_MspInit():
2020-02-27 17:03:12 +01:00
(++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE().
(++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
2019-04-29 14:39:56 +01:00
(+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
(+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
(+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
(#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
configures mainly:
2020-02-27 17:03:12 +01:00
(++) The instance: LPTIM1.
(++) Clock: the counter clock.
(+++) Source : it can be either the ULPTIM input (IN1) or one of
2019-04-29 14:39:56 +01:00
the internal clock; (APB, LSE, LSI or MSI).
2020-02-27 17:03:12 +01:00
(+++) Prescaler: select the clock divider.
(++) UltraLowPowerClock : To be used only if the ULPTIM is selected
2019-04-29 14:39:56 +01:00
as counter clock source.
2020-02-27 17:03:12 +01:00
(+++) Polarity: polarity of the active edge for the counter unit
2019-04-29 14:39:56 +01:00
if the ULPTIM input is selected.
2020-02-27 17:03:12 +01:00
(+++) SampleTime: clock sampling time to configure the clock glitch
filter.
(++) Trigger: How the counter start.
(+++) Source: trigger can be software or one of the hardware triggers.
(+++) ActiveEdge : only for hardware trigger.
(+++) SampleTime : trigger sampling time to configure the trigger
2019-04-29 14:39:56 +01:00
glitch filter.
2020-02-27 17:03:12 +01:00
(++) OutputPolarity : 2 opposite polarities are possible.
(++) UpdateMode: specifies whether the update of the autoreload and
2019-04-29 14:39:56 +01:00
the compare values is done immediately or after the end of current
2020-02-27 17:03:12 +01:00
period.
2019-04-29 14:39:56 +01:00
(#)Six modes are available:
2020-02-27 17:03:12 +01:00
(++) PWM Mode: To generate a PWM signal with specified period and pulse,
2019-04-29 14:39:56 +01:00
call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
mode.
2020-02-27 17:03:12 +01:00
(++) One Pulse Mode: To generate pulse with specified width in response
2019-04-29 14:39:56 +01:00
to a stimulus, call HAL_LPTIM_OnePulse_Start() or
HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
2020-02-27 17:03:12 +01:00
(++) Set once Mode: In this mode, the output changes the level (from
2019-04-29 14:39:56 +01:00
low level to high level if the output polarity is configured high, else
2020-02-27 17:03:12 +01:00
the opposite) when a compare match occurs. To start this mode, call
2019-04-29 14:39:56 +01:00
HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
interruption mode.
2020-02-27 17:03:12 +01:00
(++) Encoder Mode: To use the encoder interface call
HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
interruption mode. Only available for LPTIM1 instance.
(++) Time out Mode: an active edge on one selected trigger input rests
2019-04-29 14:39:56 +01:00
the counter. The first trigger event will start the timer, any
successive trigger event will reset the counter and the timer will
2020-02-27 17:03:12 +01:00
restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or
2019-04-29 14:39:56 +01:00
HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
2020-02-27 17:03:12 +01:00
(++) Counter Mode: counter can be used to count external events on
2019-04-29 14:39:56 +01:00
the LPTIM Input1 or it can be used to count internal clock cycles.
2020-02-27 17:03:12 +01:00
To start this mode, call HAL_LPTIM_Counter_Start() or
HAL_LPTIM_Counter_Start_IT() for interruption mode.
2019-04-29 14:39:56 +01:00
(#) User can stop any process by calling the corresponding API:
HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
already started in interruption mode.
2020-02-27 17:03:12 +01:00
(#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit().
2019-04-29 14:39:56 +01:00
2020-02-27 17:03:12 +01:00
*** Callback registration ***
=============================================
[..]
The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1
2019-04-29 14:39:56 +01:00
allows the user to configure dynamically the driver callbacks.
2020-02-27 17:03:12 +01:00
[..]
2021-12-14 09:25:05 +01:00
Use Function HAL_LPTIM_RegisterCallback() to register a callback.
HAL_LPTIM_RegisterCallback() takes as parameters the HAL peripheral handle,
2019-04-29 14:39:56 +01:00
the Callback ID and a pointer to the user callback function.
2020-02-27 17:03:12 +01:00
[..]
2021-12-14 09:25:05 +01:00
Use function HAL_LPTIM_UnRegisterCallback() to reset a callback to the
2020-02-27 17:03:12 +01:00
default weak function.
2021-12-14 09:25:05 +01:00
HAL_LPTIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
2019-04-29 14:39:56 +01:00
and the Callback ID.
2020-02-27 17:03:12 +01:00
[..]
2019-04-29 14:39:56 +01:00
These functions allow to register/unregister following callbacks:
2020-02-27 17:03:12 +01:00
(+) MspInitCallback : LPTIM Base Msp Init Callback.
(+) MspDeInitCallback : LPTIM Base Msp DeInit Callback.
(+) CompareMatchCallback : Compare match Callback.
(+) AutoReloadMatchCallback : Auto-reload match Callback.
(+) TriggerCallback : External trigger event detection Callback.
(+) CompareWriteCallback : Compare register write complete Callback.
(+) AutoReloadWriteCallback : Auto-reload register write complete Callback.
(+) DirectionUpCallback : Up-counting direction change Callback.
(+) DirectionDownCallback : Down-counting direction change Callback.
[..]
By default, after the Init and when the state is HAL_LPTIM_STATE_RESET
2019-04-29 14:39:56 +01:00
all interrupt callbacks are set to the corresponding weak functions:
2021-12-14 09:25:05 +01:00
examples HAL_LPTIM_TriggerCallback(), HAL_LPTIM_CompareMatchCallback().
2019-04-29 14:39:56 +01:00
2020-02-27 17:03:12 +01:00
[..]
2019-04-29 14:39:56 +01:00
Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
2020-02-27 17:03:12 +01:00
functionalities in the Init/DeInit only when these callbacks are null
(not registered beforehand). If not, MspInit or MspDeInit are not null, the Init/DeInit
keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
2019-04-29 14:39:56 +01:00
2020-02-27 17:03:12 +01:00
[..]
2019-04-29 14:39:56 +01:00
Callbacks can be registered/unregistered in HAL_LPTIM_STATE_READY state only.
Exception done MspInit/MspDeInit that can be registered/unregistered
2020-02-27 17:03:12 +01:00
in HAL_LPTIM_STATE_READY or HAL_LPTIM_STATE_RESET state,
thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
In that case first register the MspInit/MspDeInit user callbacks
2021-12-14 09:25:05 +01:00
using HAL_LPTIM_RegisterCallback() before calling DeInit or Init function.
2019-04-29 14:39:56 +01:00
2020-02-27 17:03:12 +01:00
[..]
2019-04-29 14:39:56 +01:00
When The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or
not defined, the callback registration feature is not available and all callbacks
are set to the corresponding weak functions.
@endverbatim
******************************************************************************
2020-02-27 17:03:12 +01:00
*/
2019-04-29 14:39:56 +01:00
/* Includes ------------------------------------------------------------------*/
#include "stm32f7xx_hal.h"
/** @addtogroup STM32F7xx_HAL_Driver
* @{
*/
/** @defgroup LPTIM LPTIM
* @brief LPTIM HAL module driver.
* @{
*/
#ifdef HAL_LPTIM_MODULE_ENABLED
2020-02-27 17:03:12 +01:00
#if defined (LPTIM1)
2019-04-29 14:39:56 +01:00
2020-02-27 17:03:12 +01:00
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/** @addtogroup LPTIM_Private_Constants
2019-04-29 14:39:56 +01:00
* @{
*/
2020-02-27 17:03:12 +01:00
#define TIMEOUT 1000UL /* Timeout is 1s */
2019-04-29 14:39:56 +01:00
/**
* @}
*/
2020-02-27 17:03:12 +01:00
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
2019-04-29 14:39:56 +01:00
/* Private function prototypes -----------------------------------------------*/
2020-02-27 17:03:12 +01:00
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim);
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
static HAL_StatusTypeDef LPTIM_WaitForFlag(LPTIM_HandleTypeDef *hlptim, uint32_t flag);
2019-04-29 14:39:56 +01:00
2020-02-27 17:03:12 +01:00
/* Exported functions --------------------------------------------------------*/
2019-04-29 14:39:56 +01:00
/** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
* @{
*/
2020-02-27 17:03:12 +01:00
/** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions
2021-03-03 17:35:52 +01:00
* @brief Initialization and Configuration functions.
*
2020-02-27 17:03:12 +01:00
@verbatim
2019-04-29 14:39:56 +01:00
==============================================================================
##### Initialization and de-initialization functions #####
==============================================================================
[..] This section provides functions allowing to:
(+) Initialize the LPTIM according to the specified parameters in the
2020-02-27 17:03:12 +01:00
LPTIM_InitTypeDef and initialize the associated handle.
2019-04-29 14:39:56 +01:00
(+) DeInitialize the LPTIM peripheral.
(+) Initialize the LPTIM MSP.
2020-02-27 17:03:12 +01:00
(+) DeInitialize the LPTIM MSP.
2019-04-29 14:39:56 +01:00
@endverbatim
* @{
*/
/**
2020-02-27 17:03:12 +01:00
* @brief Initialize the LPTIM according to the specified parameters in the
* LPTIM_InitTypeDef and initialize the associated handle.
2019-04-29 14:39:56 +01:00
* @param hlptim LPTIM handle
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
{
2020-02-27 17:03:12 +01:00
uint32_t tmpcfgr;
2019-04-29 14:39:56 +01:00
/* Check the LPTIM handle allocation */
2020-02-27 17:03:12 +01:00
if (hlptim == NULL)
2019-04-29 14:39:56 +01:00
{
return HAL_ERROR;
}
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
2020-02-27 17:03:12 +01:00
assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));
2021-12-14 09:25:05 +01:00
if ((hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_ULPTIM)
|| (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
2019-04-29 14:39:56 +01:00
{
assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
2021-03-03 17:35:52 +01:00
assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
2020-02-27 17:03:12 +01:00
}
2019-04-29 14:39:56 +01:00
assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
2020-02-27 17:03:12 +01:00
if (hlptim->Init.Trigger.Source != LPTIM_TRIGSOURCE_SOFTWARE)
2019-04-29 14:39:56 +01:00
{
assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
2020-02-27 17:03:12 +01:00
assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
}
assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));
2019-04-29 14:39:56 +01:00
assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
2020-02-27 17:03:12 +01:00
if (hlptim->State == HAL_LPTIM_STATE_RESET)
2019-04-29 14:39:56 +01:00
{
/* Allocate lock resource and initialize it */
hlptim->Lock = HAL_UNLOCKED;
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
2020-02-27 17:03:12 +01:00
/* Reset interrupt callbacks to legacy weak callbacks */
LPTIM_ResetCallback(hlptim);
if (hlptim->MspInitCallback == NULL)
2019-04-29 14:39:56 +01:00
{
hlptim->MspInitCallback = HAL_LPTIM_MspInit;
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Init the low level hardware : GPIO, CLOCK, NVIC */
hlptim->MspInitCallback(hlptim);
#else
2020-02-27 17:03:12 +01:00
/* Init the low level hardware : GPIO, CLOCK, NVIC */
2019-04-29 14:39:56 +01:00
HAL_LPTIM_MspInit(hlptim);
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Change the LPTIM state */
hlptim->State = HAL_LPTIM_STATE_BUSY;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Get the LPTIMx CFGR value */
tmpcfgr = hlptim->Instance->CFGR;
2020-02-27 17:03:12 +01:00
2021-12-14 09:25:05 +01:00
if ((hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_ULPTIM)
|| (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
2020-02-27 17:03:12 +01:00
{
2021-03-03 17:35:52 +01:00
tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
2020-02-27 17:03:12 +01:00
}
if (hlptim->Init.Trigger.Source != LPTIM_TRIGSOURCE_SOFTWARE)
2019-04-29 14:39:56 +01:00
{
2021-03-03 17:35:52 +01:00
tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
2019-04-29 14:39:56 +01:00
}
2020-02-27 17:03:12 +01:00
2021-03-03 17:35:52 +01:00
/* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
2020-02-27 17:03:12 +01:00
LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE));
2019-04-29 14:39:56 +01:00
/* Set initialization parameters */
tmpcfgr |= (hlptim->Init.Clock.Source |
hlptim->Init.Clock.Prescaler |
hlptim->Init.OutputPolarity |
hlptim->Init.UpdateMode |
hlptim->Init.CounterSource);
2020-02-27 17:03:12 +01:00
/* Glitch filters for internal triggers and external inputs are configured
* only if an internal clock source is provided to the LPTIM
*/
if (hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC)
2019-04-29 14:39:56 +01:00
{
2020-02-27 17:03:12 +01:00
tmpcfgr |= (hlptim->Init.Trigger.SampleTime |
2019-04-29 14:39:56 +01:00
hlptim->Init.UltraLowPowerClock.SampleTime);
2020-02-27 17:03:12 +01:00
}
2021-03-03 17:35:52 +01:00
/* Configure LPTIM external clock polarity and digital filter */
2021-12-14 09:25:05 +01:00
if ((hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_ULPTIM)
|| (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
2020-02-27 17:03:12 +01:00
{
2021-03-03 17:35:52 +01:00
tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
hlptim->Init.UltraLowPowerClock.SampleTime);
2020-02-27 17:03:12 +01:00
}
2021-03-03 17:35:52 +01:00
/* Configure LPTIM external trigger */
2020-02-27 17:03:12 +01:00
if (hlptim->Init.Trigger.Source != LPTIM_TRIGSOURCE_SOFTWARE)
2019-04-29 14:39:56 +01:00
{
/* Enable External trigger and set the trigger source */
2021-03-03 17:35:52 +01:00
tmpcfgr |= (hlptim->Init.Trigger.Source |
hlptim->Init.Trigger.ActiveEdge |
hlptim->Init.Trigger.SampleTime);
2019-04-29 14:39:56 +01:00
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Write to LPTIMx CFGR */
hlptim->Instance->CFGR = tmpcfgr;
/* Change the LPTIM state */
hlptim->State = HAL_LPTIM_STATE_READY;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief DeInitialize the LPTIM peripheral.
2019-04-29 14:39:56 +01:00
* @param hlptim LPTIM handle
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
{
/* Check the LPTIM handle allocation */
2020-02-27 17:03:12 +01:00
if (hlptim == NULL)
2019-04-29 14:39:56 +01:00
{
return HAL_ERROR;
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Change the LPTIM state */
hlptim->State = HAL_LPTIM_STATE_BUSY;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable the LPTIM Peripheral Clock */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
2020-02-27 17:03:12 +01:00
if (hlptim->MspDeInitCallback == NULL)
2019-04-29 14:39:56 +01:00
{
hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
}
2020-02-27 17:03:12 +01:00
/* DeInit the low level hardware: CLOCK, NVIC.*/
2019-04-29 14:39:56 +01:00
hlptim->MspDeInitCallback(hlptim);
#else
/* DeInit the low level hardware: CLOCK, NVIC.*/
HAL_LPTIM_MspDeInit(hlptim);
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
/* Change the LPTIM state */
hlptim->State = HAL_LPTIM_STATE_RESET;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Release Lock */
__HAL_UNLOCK(hlptim);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Initialize the LPTIM MSP.
2019-04-29 14:39:56 +01:00
* @param hlptim LPTIM handle
* @retval None
*/
__weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hlptim);
2020-02-27 17:03:12 +01:00
/* NOTE : This function should not be modified, when the callback is needed,
2019-04-29 14:39:56 +01:00
the HAL_LPTIM_MspInit could be implemented in the user file
*/
}
/**
2020-02-27 17:03:12 +01:00
* @brief DeInitialize LPTIM MSP.
2019-04-29 14:39:56 +01:00
* @param hlptim LPTIM handle
* @retval None
*/
__weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hlptim);
2020-02-27 17:03:12 +01:00
/* NOTE : This function should not be modified, when the callback is needed,
2019-04-29 14:39:56 +01:00
the HAL_LPTIM_MspDeInit could be implemented in the user file
*/
}
/**
* @}
*/
2020-02-27 17:03:12 +01:00
/** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions
2021-03-03 17:35:52 +01:00
* @brief Start-Stop operation functions.
*
2020-02-27 17:03:12 +01:00
@verbatim
2019-04-29 14:39:56 +01:00
==============================================================================
##### LPTIM Start Stop operation functions #####
2020-02-27 17:03:12 +01:00
==============================================================================
2019-04-29 14:39:56 +01:00
[..] This section provides functions allowing to:
(+) Start the PWM mode.
(+) Stop the PWM mode.
(+) Start the One pulse mode.
(+) Stop the One pulse mode.
(+) Start the Set once mode.
(+) Stop the Set once mode.
(+) Start the Encoder mode.
(+) Stop the Encoder mode.
(+) Start the Timeout mode.
2020-02-27 17:03:12 +01:00
(+) Stop the Timeout mode.
2019-04-29 14:39:56 +01:00
(+) Start the Counter mode.
(+) Stop the Counter mode.
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
@endverbatim
* @{
*/
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/**
2020-02-27 17:03:12 +01:00
* @brief Start the LPTIM PWM generation.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF.
2020-02-27 17:03:12 +01:00
* @param Pulse Specifies the compare value.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(IS_LPTIM_PULSE(Pulse));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Reset WAVE bit to set PWM mode */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
2019-04-29 14:39:56 +01:00
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
2019-04-29 14:39:56 +01:00
/* Load the pulse value in the compare register */
__HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_CMP register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Start timer in continuous mode */
__HAL_LPTIM_START_CONTINUOUS(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the LPTIM PWM generation.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the LPTIM PWM generation in interrupt mode.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF
2020-02-27 17:03:12 +01:00
* @param Pulse Specifies the compare value.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(IS_LPTIM_PULSE(Pulse));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Reset WAVE bit to set PWM mode */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
2020-02-27 17:03:12 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
/* Load the pulse value in the compare register */
__HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
/* Wait for the completion of the write operation to the LPTIM_CMP register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Enable Autoreload write complete interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Compare write complete interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Autoreload match interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Compare match interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* If external trigger source is used, then enable external trigger interrupt */
2020-02-27 17:03:12 +01:00
if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
2019-04-29 14:39:56 +01:00
{
/* Enable external trigger interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
2020-02-27 17:03:12 +01:00
}
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Start timer in continuous mode */
__HAL_LPTIM_START_CONTINUOUS(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the LPTIM PWM generation in interrupt mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Disable Autoreload write complete interrupt */
2019-04-29 14:39:56 +01:00
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Compare write complete interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Autoreload match interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Compare match interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* If external trigger source is used, then disable external trigger interrupt */
2020-02-27 17:03:12 +01:00
if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
2019-04-29 14:39:56 +01:00
{
/* Disable external trigger interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
2020-02-27 17:03:12 +01:00
}
2019-04-29 14:39:56 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the LPTIM One pulse generation.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF.
2020-02-27 17:03:12 +01:00
* @param Pulse Specifies the compare value.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(IS_LPTIM_PULSE(Pulse));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Reset WAVE bit to set one pulse mode */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
2019-04-29 14:39:56 +01:00
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
2019-04-29 14:39:56 +01:00
/* Load the pulse value in the compare register */
__HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_CMP register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Start timer in single (one shot) mode */
2019-04-29 14:39:56 +01:00
__HAL_LPTIM_START_SINGLE(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the LPTIM One pulse generation.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the LPTIM One pulse generation in interrupt mode.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF.
2020-02-27 17:03:12 +01:00
* @param Pulse Specifies the compare value.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(IS_LPTIM_PULSE(Pulse));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Reset WAVE bit to set one pulse mode */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
2020-02-27 17:03:12 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
/* Load the pulse value in the compare register */
__HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
/* Wait for the completion of the write operation to the LPTIM_CMP register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Enable Autoreload write complete interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Compare write complete interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Autoreload match interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Compare match interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* If external trigger source is used, then enable external trigger interrupt */
2020-02-27 17:03:12 +01:00
if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
2019-04-29 14:39:56 +01:00
{
/* Enable external trigger interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
/* Start timer in single (one shot) mode */
2019-04-29 14:39:56 +01:00
__HAL_LPTIM_START_SINGLE(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the LPTIM One pulse generation in interrupt mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2022-07-01 20:55:22 +01:00
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Disable Autoreload write complete interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Compare write complete interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Autoreload match interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Compare match interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* If external trigger source is used, then disable external trigger interrupt */
2020-02-27 17:03:12 +01:00
if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
2019-04-29 14:39:56 +01:00
{
/* Disable external trigger interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
}
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the LPTIM in Set once mode.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF.
2020-02-27 17:03:12 +01:00
* @param Pulse Specifies the compare value.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(IS_LPTIM_PULSE(Pulse));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Set WAVE bit to enable the set once mode */
hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
2019-04-29 14:39:56 +01:00
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
2019-04-29 14:39:56 +01:00
/* Load the pulse value in the compare register */
__HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_CMP register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Start timer in single (one shot) mode */
2019-04-29 14:39:56 +01:00
__HAL_LPTIM_START_SINGLE(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the LPTIM Set once mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the LPTIM Set once mode in interrupt mode.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF.
2020-02-27 17:03:12 +01:00
* @param Pulse Specifies the compare value.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(IS_LPTIM_PULSE(Pulse));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Set WAVE bit to enable the set once mode */
hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
2020-02-27 17:03:12 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
/* Load the pulse value in the compare register */
__HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
/* Wait for the completion of the write operation to the LPTIM_CMP register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Enable Autoreload write complete interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Compare write complete interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Autoreload match interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Compare match interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* If external trigger source is used, then enable external trigger interrupt */
2020-02-27 17:03:12 +01:00
if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
2019-04-29 14:39:56 +01:00
{
/* Enable external trigger interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
2020-02-27 17:03:12 +01:00
}
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
/* Start timer in single (one shot) mode */
2019-04-29 14:39:56 +01:00
__HAL_LPTIM_START_SINGLE(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the LPTIM Set once mode in interrupt mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Disable Autoreload write complete interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Compare write complete interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Autoreload match interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Compare match interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* If external trigger source is used, then disable external trigger interrupt */
2020-02-27 17:03:12 +01:00
if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
2019-04-29 14:39:56 +01:00
{
/* Disable external trigger interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
2020-02-27 17:03:12 +01:00
}
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the Encoder interface.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF.
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
{
2020-02-27 17:03:12 +01:00
uint32_t tmpcfgr;
2019-04-29 14:39:56 +01:00
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Get the LPTIMx CFGR value */
tmpcfgr = hlptim->Instance->CFGR;
/* Clear CKPOL bits */
tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
/* Set Input polarity */
tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
/* Write to LPTIMx CFGR */
hlptim->Instance->CFGR = tmpcfgr;
/* Set ENC bit to enable the encoder interface */
hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
2019-04-29 14:39:56 +01:00
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Start timer in continuous mode */
__HAL_LPTIM_START_CONTINUOUS(hlptim);
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the Encoder interface.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Reset ENC bit to disable the encoder interface */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the Encoder interface in interrupt mode.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
{
2020-02-27 17:03:12 +01:00
uint32_t tmpcfgr;
2019-04-29 14:39:56 +01:00
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Configure edge sensitivity for encoder mode */
/* Get the LPTIMx CFGR value */
tmpcfgr = hlptim->Instance->CFGR;
/* Clear CKPOL bits */
tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
/* Set Input polarity */
tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
/* Write to LPTIMx CFGR */
hlptim->Instance->CFGR = tmpcfgr;
/* Set ENC bit to enable the encoder interface */
hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
2020-02-27 17:03:12 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Enable "switch to down direction" interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
/* Enable "switch to up direction" interrupt */
2020-02-27 17:03:12 +01:00
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
/* Start timer in continuous mode */
__HAL_LPTIM_START_CONTINUOUS(hlptim);
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the Encoder interface in interrupt mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Reset ENC bit to disable the encoder interface */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable "switch to down direction" interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable "switch to up direction" interrupt */
2020-02-27 17:03:12 +01:00
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the Timeout function.
* @note The first trigger event will start the timer, any successive
* trigger event will reset the counter and the timer restarts.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF.
2020-02-27 17:03:12 +01:00
* @param Timeout Specifies the TimeOut value to reset the counter.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(IS_LPTIM_PULSE(Timeout));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Set TIMOUT bit to enable the timeout function */
hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
2019-04-29 14:39:56 +01:00
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
2019-04-29 14:39:56 +01:00
/* Load the Timeout value in the compare register */
__HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_CMP register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Start timer in continuous mode */
__HAL_LPTIM_START_CONTINUOUS(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the Timeout function.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Reset TIMOUT bit to enable the timeout function */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the Timeout function in interrupt mode.
* @note The first trigger event will start the timer, any successive
* trigger event will reset the counter and the timer restarts.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF.
2020-02-27 17:03:12 +01:00
* @param Timeout Specifies the TimeOut value to reset the counter.
2019-04-29 14:39:56 +01:00
* This parameter must be a value between 0x0000 and 0xFFFF.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
assert_param(IS_LPTIM_PULSE(Timeout));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Enable EXTI Line interrupt on the LPTIM Wake-up Timer */
2020-02-27 17:03:12 +01:00
__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT();
2019-04-29 14:39:56 +01:00
/* Enable rising edge trigger on the LPTIM Wake-up Timer Exti line */
__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set TIMOUT bit to enable the timeout function */
hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
2019-04-29 14:39:56 +01:00
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
2019-04-29 14:39:56 +01:00
/* Load the Timeout value in the compare register */
__HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_CMP register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Enable Compare match interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2019-04-29 14:39:56 +01:00
/* Start timer in continuous mode */
__HAL_LPTIM_START_CONTINUOUS(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the Timeout function in interrupt mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
/* Disable rising edge trigger on the LPTIM Wake-up Timer Exti line */
2019-04-29 14:39:56 +01:00
__HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable EXTI Line interrupt on the LPTIM Wake-up Timer */
2020-02-27 17:03:12 +01:00
__HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT();
2022-07-01 20:55:22 +01:00
/* Set the LPTIM state */
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Reset TIMOUT bit to enable the timeout function */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Compare match interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the Counter mode.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF.
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
2021-03-03 17:35:52 +01:00
if ((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM)
&& (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
2019-04-29 14:39:56 +01:00
{
/* Check if clock is prescaled */
assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
/* Set clock prescaler to 0 */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
}
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
2019-04-29 14:39:56 +01:00
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
2020-02-27 17:03:12 +01:00
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Start timer in continuous mode */
__HAL_LPTIM_START_CONTINUOUS(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the Counter mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Start the Counter mode in interrupt mode.
* @param hlptim LPTIM handle
* @param Period Specifies the Autoreload value.
2022-07-01 20:55:22 +01:00
* This parameter must be a value between 0x0001 and 0xFFFF.
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
assert_param(IS_LPTIM_PERIOD(Period));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Set the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Enable EXTI Line interrupt on the LPTIM Wake-up Timer */
2020-02-27 17:03:12 +01:00
__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT();
2019-04-29 14:39:56 +01:00
/* Enable rising edge trigger on the LPTIM Wake-up Timer Exti line */
2020-02-27 17:03:12 +01:00
__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
2019-04-29 14:39:56 +01:00
/* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
2021-03-03 17:35:52 +01:00
if ((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM)
&& (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
2019-04-29 14:39:56 +01:00
{
/* Check if clock is prescaled */
assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
/* Set clock prescaler to 0 */
hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
}
2020-02-27 17:03:12 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
/* Clear flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
/* Load the period value in the autoreload register */
__HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
return HAL_TIMEOUT;
}
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Enable Autoreload write complete interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable Autoreload match interrupt */
__HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Enable the Peripheral */
__HAL_LPTIM_ENABLE(hlptim);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Start timer in continuous mode */
__HAL_LPTIM_START_CONTINUOUS(hlptim);
2020-02-27 17:03:12 +01:00
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Stop the Counter mode in interrupt mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval HAL status
*/
HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
{
/* Check the parameters */
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
/* Disable rising edge trigger on the LPTIM Wake-up Timer Exti line */
2019-04-29 14:39:56 +01:00
__HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable EXTI Line interrupt on the LPTIM Wake-up Timer */
2020-02-27 17:03:12 +01:00
__HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT();
2022-07-01 20:55:22 +01:00
/* Set the LPTIM state */
hlptim->State = HAL_LPTIM_STATE_BUSY;
2019-04-29 14:39:56 +01:00
/* Disable the Peripheral */
__HAL_LPTIM_DISABLE(hlptim);
2020-02-27 17:03:12 +01:00
if (HAL_LPTIM_GetState(hlptim) == HAL_LPTIM_STATE_TIMEOUT)
{
return HAL_TIMEOUT;
}
2019-04-29 14:39:56 +01:00
/* Disable Autoreload write complete interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Disable Autoreload match interrupt */
__HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
2022-07-01 20:55:22 +01:00
/* Change the LPTIM state */
2020-02-27 17:03:12 +01:00
hlptim->State = HAL_LPTIM_STATE_READY;
2019-04-29 14:39:56 +01:00
/* Return function status */
return HAL_OK;
}
/**
* @}
*/
2020-02-27 17:03:12 +01:00
/** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions
2021-03-03 17:35:52 +01:00
* @brief Read operation functions.
*
2020-02-27 17:03:12 +01:00
@verbatim
2019-04-29 14:39:56 +01:00
==============================================================================
##### LPTIM Read operation functions #####
2020-02-27 17:03:12 +01:00
==============================================================================
2019-04-29 14:39:56 +01:00
[..] This section provides LPTIM Reading functions.
(+) Read the counter value.
(+) Read the period (Auto-reload) value.
(+) Read the pulse (Compare)value.
@endverbatim
* @{
*/
/**
2020-02-27 17:03:12 +01:00
* @brief Return the current counter value.
2019-04-29 14:39:56 +01:00
* @param hlptim LPTIM handle
* @retval Counter value.
*/
2022-07-01 20:55:22 +01:00
uint32_t HAL_LPTIM_ReadCounter(const LPTIM_HandleTypeDef *hlptim)
2019-04-29 14:39:56 +01:00
{
2020-02-27 17:03:12 +01:00
/* Check the parameters */
2019-04-29 14:39:56 +01:00
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
return (hlptim->Instance->CNT);
}
/**
2020-02-27 17:03:12 +01:00
* @brief Return the current Autoreload (Period) value.
2019-04-29 14:39:56 +01:00
* @param hlptim LPTIM handle
* @retval Autoreload value.
*/
2022-07-01 20:55:22 +01:00
uint32_t HAL_LPTIM_ReadAutoReload(const LPTIM_HandleTypeDef *hlptim)
2019-04-29 14:39:56 +01:00
{
2020-02-27 17:03:12 +01:00
/* Check the parameters */
2019-04-29 14:39:56 +01:00
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
return (hlptim->Instance->ARR);
}
/**
2020-02-27 17:03:12 +01:00
* @brief Return the current Compare (Pulse) value.
2019-04-29 14:39:56 +01:00
* @param hlptim LPTIM handle
* @retval Compare value.
*/
2022-07-01 20:55:22 +01:00
uint32_t HAL_LPTIM_ReadCompare(const LPTIM_HandleTypeDef *hlptim)
2019-04-29 14:39:56 +01:00
{
2020-02-27 17:03:12 +01:00
/* Check the parameters */
2019-04-29 14:39:56 +01:00
assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
return (hlptim->Instance->CMP);
}
/**
* @}
*/
2020-02-27 17:03:12 +01:00
/** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks
2021-03-03 17:35:52 +01:00
* @brief LPTIM IRQ handler.
*
2020-02-27 17:03:12 +01:00
@verbatim
==============================================================================
##### LPTIM IRQ handler and callbacks #####
2019-04-29 14:39:56 +01:00
==============================================================================
2020-02-27 17:03:12 +01:00
[..] This section provides LPTIM IRQ handler and callback functions called within
the IRQ handler:
(+) LPTIM interrupt request handler
(+) Compare match Callback
(+) Auto-reload match Callback
(+) External trigger event detection Callback
(+) Compare register write complete Callback
(+) Auto-reload register write complete Callback
(+) Up-counting direction change Callback
(+) Down-counting direction change Callback
2019-04-29 14:39:56 +01:00
@endverbatim
* @{
*/
/**
2020-02-27 17:03:12 +01:00
* @brief Handle LPTIM interrupt request.
2019-04-29 14:39:56 +01:00
* @param hlptim LPTIM handle
* @retval None
*/
void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
{
/* Compare match interrupt */
2020-02-27 17:03:12 +01:00
if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
{
if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) != RESET)
{
2019-04-29 14:39:56 +01:00
/* Clear Compare match flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Compare match Callback */
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
hlptim->CompareMatchCallback(hlptim);
#else
2020-02-27 17:03:12 +01:00
HAL_LPTIM_CompareMatchCallback(hlptim);
2019-04-29 14:39:56 +01:00
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
}
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Autoreload match interrupt */
2020-02-27 17:03:12 +01:00
if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
{
if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET)
{
2019-04-29 14:39:56 +01:00
/* Clear Autoreload match flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Autoreload match Callback */
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
hlptim->AutoReloadMatchCallback(hlptim);
#else
2020-02-27 17:03:12 +01:00
HAL_LPTIM_AutoReloadMatchCallback(hlptim);
2019-04-29 14:39:56 +01:00
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
}
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Trigger detected interrupt */
2020-02-27 17:03:12 +01:00
if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
{
if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) != RESET)
{
2019-04-29 14:39:56 +01:00
/* Clear Trigger detected flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Trigger detected callback */
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
hlptim->TriggerCallback(hlptim);
#else
2020-02-27 17:03:12 +01:00
HAL_LPTIM_TriggerCallback(hlptim);
2019-04-29 14:39:56 +01:00
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
}
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Compare write interrupt */
2020-02-27 17:03:12 +01:00
if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
{
if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) != RESET)
{
2019-04-29 14:39:56 +01:00
/* Clear Compare write flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Compare write Callback */
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
hlptim->CompareWriteCallback(hlptim);
#else
2020-02-27 17:03:12 +01:00
HAL_LPTIM_CompareWriteCallback(hlptim);
2019-04-29 14:39:56 +01:00
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
}
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Autoreload write interrupt */
2020-02-27 17:03:12 +01:00
if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
{
if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET)
{
2019-04-29 14:39:56 +01:00
/* Clear Autoreload write flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Autoreload write Callback */
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
hlptim->AutoReloadWriteCallback(hlptim);
#else
2020-02-27 17:03:12 +01:00
HAL_LPTIM_AutoReloadWriteCallback(hlptim);
2019-04-29 14:39:56 +01:00
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
}
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Direction counter changed from Down to Up interrupt */
2020-02-27 17:03:12 +01:00
if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
{
if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) != RESET)
{
2019-04-29 14:39:56 +01:00
/* Clear Direction counter changed from Down to Up flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Direction counter changed from Down to Up Callback */
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
hlptim->DirectionUpCallback(hlptim);
#else
2020-02-27 17:03:12 +01:00
HAL_LPTIM_DirectionUpCallback(hlptim);
2019-04-29 14:39:56 +01:00
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
}
}
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Direction counter changed from Up to Down interrupt */
2020-02-27 17:03:12 +01:00
if (__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
{
if (__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) != RESET)
{
2019-04-29 14:39:56 +01:00
/* Clear Direction counter changed from Up to Down flag */
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
2020-02-27 17:03:12 +01:00
2019-04-29 14:39:56 +01:00
/* Direction counter changed from Up to Down Callback */
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
hlptim->DirectionDownCallback(hlptim);
#else
2020-02-27 17:03:12 +01:00
HAL_LPTIM_DirectionDownCallback(hlptim);
2019-04-29 14:39:56 +01:00
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
}
}
__HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG();
}
/**
2020-02-27 17:03:12 +01:00
* @brief Compare match callback in non-blocking mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval None
*/
__weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hlptim);
2020-02-27 17:03:12 +01:00
/* NOTE : This function should not be modified, when the callback is needed,
2019-04-29 14:39:56 +01:00
the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
2020-02-27 17:03:12 +01:00
*/
2019-04-29 14:39:56 +01:00
}
/**
2020-02-27 17:03:12 +01:00
* @brief Autoreload match callback in non-blocking mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval None
*/
__weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hlptim);
2020-02-27 17:03:12 +01:00
/* NOTE : This function should not be modified, when the callback is needed,
2019-04-29 14:39:56 +01:00
the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
2020-02-27 17:03:12 +01:00
*/
2019-04-29 14:39:56 +01:00
}
/**
2020-02-27 17:03:12 +01:00
* @brief Trigger detected callback in non-blocking mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval None
*/
__weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hlptim);
2020-02-27 17:03:12 +01:00
/* NOTE : This function should not be modified, when the callback is needed,
2019-04-29 14:39:56 +01:00
the HAL_LPTIM_TriggerCallback could be implemented in the user file
2020-02-27 17:03:12 +01:00
*/
2019-04-29 14:39:56 +01:00
}
/**
2020-02-27 17:03:12 +01:00
* @brief Compare write callback in non-blocking mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval None
*/
__weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hlptim);
2020-02-27 17:03:12 +01:00
/* NOTE : This function should not be modified, when the callback is needed,
2019-04-29 14:39:56 +01:00
the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
2020-02-27 17:03:12 +01:00
*/
2019-04-29 14:39:56 +01:00
}
/**
2020-02-27 17:03:12 +01:00
* @brief Autoreload write callback in non-blocking mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval None
*/
__weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hlptim);
2020-02-27 17:03:12 +01:00
/* NOTE : This function should not be modified, when the callback is needed,
2019-04-29 14:39:56 +01:00
the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
2020-02-27 17:03:12 +01:00
*/
2019-04-29 14:39:56 +01:00
}
/**
2020-02-27 17:03:12 +01:00
* @brief Direction counter changed from Down to Up callback in non-blocking mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval None
*/
__weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hlptim);
2020-02-27 17:03:12 +01:00
/* NOTE : This function should not be modified, when the callback is needed,
2019-04-29 14:39:56 +01:00
the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
2020-02-27 17:03:12 +01:00
*/
2019-04-29 14:39:56 +01:00
}
/**
2020-02-27 17:03:12 +01:00
* @brief Direction counter changed from Up to Down callback in non-blocking mode.
* @param hlptim LPTIM handle
2019-04-29 14:39:56 +01:00
* @retval None
*/
__weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hlptim);
2020-02-27 17:03:12 +01:00
/* NOTE : This function should not be modified, when the callback is needed,
2019-04-29 14:39:56 +01:00
the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
2020-02-27 17:03:12 +01:00
*/
2019-04-29 14:39:56 +01:00
}
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
/**
2020-02-27 17:03:12 +01:00
* @brief Register a User LPTIM callback to be used instead of the weak predefined callback
* @param hlptim LPTIM handle
* @param CallbackID ID of the callback to be registered
* This parameter can be one of the following values:
* @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
* @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
* @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID
* @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
* @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID
* @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID
* @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
* @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID
* @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID
2019-04-29 14:39:56 +01:00
* @param pCallback pointer to the callback function
* @retval status
*/
2020-02-27 17:03:12 +01:00
HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *hlptim,
HAL_LPTIM_CallbackIDTypeDef CallbackID,
pLPTIM_CallbackTypeDef pCallback)
2019-04-29 14:39:56 +01:00
{
HAL_StatusTypeDef status = HAL_OK;
2020-02-27 17:03:12 +01:00
if (pCallback == NULL)
2019-04-29 14:39:56 +01:00
{
return HAL_ERROR;
}
2020-02-27 17:03:12 +01:00
if (hlptim->State == HAL_LPTIM_STATE_READY)
2019-04-29 14:39:56 +01:00
{
switch (CallbackID)
{
2020-02-27 17:03:12 +01:00
case HAL_LPTIM_MSPINIT_CB_ID :
hlptim->MspInitCallback = pCallback;
break;
case HAL_LPTIM_MSPDEINIT_CB_ID :
hlptim->MspDeInitCallback = pCallback;
break;
case HAL_LPTIM_COMPARE_MATCH_CB_ID :
hlptim->CompareMatchCallback = pCallback;
break;
case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
hlptim->AutoReloadMatchCallback = pCallback;
break;
case HAL_LPTIM_TRIGGER_CB_ID :
hlptim->TriggerCallback = pCallback;
break;
case HAL_LPTIM_COMPARE_WRITE_CB_ID :
hlptim->CompareWriteCallback = pCallback;
break;
case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID :
hlptim->AutoReloadWriteCallback = pCallback;
break;
case HAL_LPTIM_DIRECTION_UP_CB_ID :
hlptim->DirectionUpCallback = pCallback;
break;
case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
hlptim->DirectionDownCallback = pCallback;
break;
default :
/* Return error status */
status = HAL_ERROR;
break;
2019-04-29 14:39:56 +01:00
}
}
2020-02-27 17:03:12 +01:00
else if (hlptim->State == HAL_LPTIM_STATE_RESET)
2019-04-29 14:39:56 +01:00
{
switch (CallbackID)
{
2020-02-27 17:03:12 +01:00
case HAL_LPTIM_MSPINIT_CB_ID :
hlptim->MspInitCallback = pCallback;
break;
case HAL_LPTIM_MSPDEINIT_CB_ID :
hlptim->MspDeInitCallback = pCallback;
break;
default :
/* Return error status */
status = HAL_ERROR;
break;
2019-04-29 14:39:56 +01:00
}
}
else
{
/* Return error status */
status = HAL_ERROR;
}
return status;
}
/**
2020-02-27 17:03:12 +01:00
* @brief Unregister a LPTIM callback
* LLPTIM callback is redirected to the weak predefined callback
* @param hlptim LPTIM handle
* @param CallbackID ID of the callback to be unregistered
* This parameter can be one of the following values:
* @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
* @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
* @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID
* @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
* @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID
* @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID
* @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
* @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID
* @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID
2019-04-29 14:39:56 +01:00
* @retval status
*/
2020-02-27 17:03:12 +01:00
HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *hlptim,
HAL_LPTIM_CallbackIDTypeDef CallbackID)
2019-04-29 14:39:56 +01:00
{
HAL_StatusTypeDef status = HAL_OK;
2020-02-27 17:03:12 +01:00
if (hlptim->State == HAL_LPTIM_STATE_READY)
2019-04-29 14:39:56 +01:00
{
switch (CallbackID)
{
2020-02-27 17:03:12 +01:00
case HAL_LPTIM_MSPINIT_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak MspInit Callback */
hlptim->MspInitCallback = HAL_LPTIM_MspInit;
2020-02-27 17:03:12 +01:00
break;
case HAL_LPTIM_MSPDEINIT_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak Msp DeInit Callback */
hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
2020-02-27 17:03:12 +01:00
break;
case HAL_LPTIM_COMPARE_MATCH_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak Compare match Callback */
hlptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback;
2020-02-27 17:03:12 +01:00
break;
case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak Auto-reload match Callback */
hlptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback;
2020-02-27 17:03:12 +01:00
break;
case HAL_LPTIM_TRIGGER_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak External trigger event detection Callback */
hlptim->TriggerCallback = HAL_LPTIM_TriggerCallback;
2020-02-27 17:03:12 +01:00
break;
case HAL_LPTIM_COMPARE_WRITE_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak Compare register write complete Callback */
hlptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback;
2020-02-27 17:03:12 +01:00
break;
case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak Auto-reload register write complete Callback */
hlptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback;
2020-02-27 17:03:12 +01:00
break;
case HAL_LPTIM_DIRECTION_UP_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak Up-counting direction change Callback */
hlptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback;
2020-02-27 17:03:12 +01:00
break;
case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak Down-counting direction change Callback */
hlptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback;
2020-02-27 17:03:12 +01:00
break;
default :
/* Return error status */
status = HAL_ERROR;
break;
2019-04-29 14:39:56 +01:00
}
}
2020-02-27 17:03:12 +01:00
else if (hlptim->State == HAL_LPTIM_STATE_RESET)
2019-04-29 14:39:56 +01:00
{
switch (CallbackID)
{
2020-02-27 17:03:12 +01:00
case HAL_LPTIM_MSPINIT_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak MspInit Callback */
hlptim->MspInitCallback = HAL_LPTIM_MspInit;
2020-02-27 17:03:12 +01:00
break;
case HAL_LPTIM_MSPDEINIT_CB_ID :
2021-12-14 09:25:05 +01:00
/* Legacy weak Msp DeInit Callback */
hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
2020-02-27 17:03:12 +01:00
break;
default :
/* Return error status */
status = HAL_ERROR;
break;
2019-04-29 14:39:56 +01:00
}
}
else
{
/* Return error status */
status = HAL_ERROR;
}
return status;
}
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
/**
* @}
*/
2020-02-27 17:03:12 +01:00
/** @defgroup LPTIM_Group5 Peripheral State functions
2021-03-03 17:35:52 +01:00
* @brief Peripheral State functions.
*
2020-02-27 17:03:12 +01:00
@verbatim
2019-04-29 14:39:56 +01:00
==============================================================================
##### Peripheral State functions #####
2020-02-27 17:03:12 +01:00
==============================================================================
2019-04-29 14:39:56 +01:00
[..]
This subsection permits to get in run-time the status of the peripheral.
@endverbatim
* @{
*/
/**
2020-02-27 17:03:12 +01:00
* @brief Return the LPTIM handle state.
2019-04-29 14:39:56 +01:00
* @param hlptim LPTIM handle
* @retval HAL state
*/
HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
{
2020-02-27 17:03:12 +01:00
/* Return LPTIM handle state */
2019-04-29 14:39:56 +01:00
return hlptim->State;
}
/**
* @}
*/
/**
* @}
*/
2020-02-27 17:03:12 +01:00
/* Private functions ---------------------------------------------------------*/
/** @defgroup LPTIM_Private_Functions LPTIM Private Functions
* @{
*/
#if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
/**
* @brief Reset interrupt callbacks to the legacy weak callbacks.
* @param lptim pointer to a LPTIM_HandleTypeDef structure that contains
* the configuration information for LPTIM module.
* @retval None
*/
static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim)
{
/* Reset the LPTIM callback to the legacy weak callbacks */
2021-12-14 09:25:05 +01:00
lptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback;
lptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback;
lptim->TriggerCallback = HAL_LPTIM_TriggerCallback;
lptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback;
lptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback;
lptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback;
lptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback;
2020-02-27 17:03:12 +01:00
}
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
/**
* @brief LPTimer Wait for flag set
* @param hlptim pointer to a LPTIM_HandleTypeDef structure that contains
* the configuration information for LPTIM module.
* @param flag The lptim flag
* @retval HAL status
*/
static HAL_StatusTypeDef LPTIM_WaitForFlag(LPTIM_HandleTypeDef *hlptim, uint32_t flag)
{
HAL_StatusTypeDef result = HAL_OK;
uint32_t count = TIMEOUT * (SystemCoreClock / 20UL / 1000UL);
do
{
count--;
if (count == 0UL)
{
result = HAL_TIMEOUT;
}
2021-03-03 17:35:52 +01:00
} while ((!(__HAL_LPTIM_GET_FLAG((hlptim), (flag)))) && (count != 0UL));
2020-02-27 17:03:12 +01:00
return result;
}
/**
* @brief Disable LPTIM HW instance.
* @param hlptim pointer to a LPTIM_HandleTypeDef structure that contains
* the configuration information for LPTIM module.
* @note The following sequence is required to solve LPTIM disable HW limitation.
* Please check Errata Sheet ES0335 for more details under "MCU may remain
* stuck in LPTIM interrupt when entering Stop mode" section.
* @retval None
*/
void LPTIM_Disable(LPTIM_HandleTypeDef *hlptim)
{
uint32_t tmpclksource = 0;
uint32_t tmpIER;
uint32_t tmpCFGR;
uint32_t tmpCMP;
uint32_t tmpARR;
2021-12-14 09:25:05 +01:00
uint32_t primask_bit;
2020-02-27 17:03:12 +01:00
2021-12-14 09:25:05 +01:00
/* Enter critical section */
primask_bit = __get_PRIMASK();
__set_PRIMASK(1) ;
2020-02-27 17:03:12 +01:00
/*********** Save LPTIM Config ***********/
/* Save LPTIM source clock */
switch ((uint32_t)hlptim->Instance)
{
case LPTIM1_BASE:
tmpclksource = __HAL_RCC_GET_LPTIM1_SOURCE();
break;
default:
break;
}
/* Save LPTIM configuration registers */
tmpIER = hlptim->Instance->IER;
tmpCFGR = hlptim->Instance->CFGR;
tmpCMP = hlptim->Instance->CMP;
tmpARR = hlptim->Instance->ARR;
/*********** Reset LPTIM ***********/
switch ((uint32_t)hlptim->Instance)
{
case LPTIM1_BASE:
__HAL_RCC_LPTIM1_FORCE_RESET();
__HAL_RCC_LPTIM1_RELEASE_RESET();
break;
default:
break;
}
/*********** Restore LPTIM Config ***********/
if ((tmpCMP != 0UL) || (tmpARR != 0UL))
{
/* Force LPTIM source kernel clock from APB */
switch ((uint32_t)hlptim->Instance)
{
case LPTIM1_BASE:
__HAL_RCC_LPTIM1_CONFIG(RCC_LPTIM1CLKSOURCE_PCLK1);
break;
default:
break;
}
if (tmpCMP != 0UL)
{
/* Restore CMP register (LPTIM should be enabled first) */
hlptim->Instance->CR |= LPTIM_CR_ENABLE;
hlptim->Instance->CMP = tmpCMP;
/* Wait for the completion of the write operation to the LPTIM_CMP register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_CMPOK) == HAL_TIMEOUT)
{
hlptim->State = HAL_LPTIM_STATE_TIMEOUT;
}
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
}
if (tmpARR != 0UL)
{
/* Restore ARR register (LPTIM should be enabled first) */
hlptim->Instance->CR |= LPTIM_CR_ENABLE;
hlptim->Instance->ARR = tmpARR;
/* Wait for the completion of the write operation to the LPTIM_ARR register */
if (LPTIM_WaitForFlag(hlptim, LPTIM_FLAG_ARROK) == HAL_TIMEOUT)
{
hlptim->State = HAL_LPTIM_STATE_TIMEOUT;
}
__HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
}
/* Restore LPTIM source kernel clock */
switch ((uint32_t)hlptim->Instance)
{
case LPTIM1_BASE:
__HAL_RCC_LPTIM1_CONFIG(tmpclksource);
break;
default:
break;
}
}
/* Restore configuration registers (LPTIM should be disabled first) */
hlptim->Instance->CR &= ~(LPTIM_CR_ENABLE);
hlptim->Instance->IER = tmpIER;
hlptim->Instance->CFGR = tmpCFGR;
2021-12-14 09:25:05 +01:00
/* Exit critical section: restore previous priority mask */
__set_PRIMASK(primask_bit);
2020-02-27 17:03:12 +01:00
}
/**
* @}
*/
#endif /* LPTIM1 */
2019-04-29 14:39:56 +01:00
#endif /* HAL_LPTIM_MODULE_ENABLED */
/**
* @}
*/
/**
* @}
*/