001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:13413ea9a877 1 /**
ganlikun 0:13413ea9a877 2 ******************************************************************************
ganlikun 0:13413ea9a877 3 * @file stm32f4xx_ll_lptim.c
ganlikun 0:13413ea9a877 4 * @author MCD Application Team
ganlikun 0:13413ea9a877 5 * @version V1.7.1
ganlikun 0:13413ea9a877 6 * @date 14-April-2017
ganlikun 0:13413ea9a877 7 * @brief LPTIM LL module driver.
ganlikun 0:13413ea9a877 8 ******************************************************************************
ganlikun 0:13413ea9a877 9 * @attention
ganlikun 0:13413ea9a877 10 *
ganlikun 0:13413ea9a877 11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
ganlikun 0:13413ea9a877 12 *
ganlikun 0:13413ea9a877 13 * Redistribution and use in source and binary forms, with or without modification,
ganlikun 0:13413ea9a877 14 * are permitted provided that the following conditions are met:
ganlikun 0:13413ea9a877 15 * 1. Redistributions of source code must retain the above copyright notice,
ganlikun 0:13413ea9a877 16 * this list of conditions and the following disclaimer.
ganlikun 0:13413ea9a877 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
ganlikun 0:13413ea9a877 18 * this list of conditions and the following disclaimer in the documentation
ganlikun 0:13413ea9a877 19 * and/or other materials provided with the distribution.
ganlikun 0:13413ea9a877 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
ganlikun 0:13413ea9a877 21 * may be used to endorse or promote products derived from this software
ganlikun 0:13413ea9a877 22 * without specific prior written permission.
ganlikun 0:13413ea9a877 23 *
ganlikun 0:13413ea9a877 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:13413ea9a877 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:13413ea9a877 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ganlikun 0:13413ea9a877 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
ganlikun 0:13413ea9a877 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ganlikun 0:13413ea9a877 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
ganlikun 0:13413ea9a877 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ganlikun 0:13413ea9a877 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ganlikun 0:13413ea9a877 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ganlikun 0:13413ea9a877 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:13413ea9a877 34 *
ganlikun 0:13413ea9a877 35 ******************************************************************************
ganlikun 0:13413ea9a877 36 */
ganlikun 0:13413ea9a877 37 #if defined(USE_FULL_LL_DRIVER)
ganlikun 0:13413ea9a877 38
ganlikun 0:13413ea9a877 39 /* Includes ------------------------------------------------------------------*/
ganlikun 0:13413ea9a877 40 #include "stm32f4xx_ll_lptim.h"
ganlikun 0:13413ea9a877 41 #include "stm32f4xx_ll_bus.h"
ganlikun 0:13413ea9a877 42
ganlikun 0:13413ea9a877 43 #ifdef USE_FULL_ASSERT
ganlikun 0:13413ea9a877 44 #include "stm32_assert.h"
ganlikun 0:13413ea9a877 45 #else
ganlikun 0:13413ea9a877 46 #define assert_param(expr) ((void)0U)
ganlikun 0:13413ea9a877 47 #endif
ganlikun 0:13413ea9a877 48
ganlikun 0:13413ea9a877 49 /** @addtogroup STM32F4xx_LL_Driver
ganlikun 0:13413ea9a877 50 * @{
ganlikun 0:13413ea9a877 51 */
ganlikun 0:13413ea9a877 52
ganlikun 0:13413ea9a877 53 #if defined (LPTIM1) || defined (LPTIM2)
ganlikun 0:13413ea9a877 54
ganlikun 0:13413ea9a877 55 /** @addtogroup LPTIM_LL
ganlikun 0:13413ea9a877 56 * @{
ganlikun 0:13413ea9a877 57 */
ganlikun 0:13413ea9a877 58
ganlikun 0:13413ea9a877 59 /* Private types -------------------------------------------------------------*/
ganlikun 0:13413ea9a877 60 /* Private variables ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 61 /* Private constants ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 62 /* Private macros ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 63 /** @addtogroup LPTIM_LL_Private_Macros
ganlikun 0:13413ea9a877 64 * @{
ganlikun 0:13413ea9a877 65 */
ganlikun 0:13413ea9a877 66 #define IS_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \
ganlikun 0:13413ea9a877 67 || ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL))
ganlikun 0:13413ea9a877 68
ganlikun 0:13413ea9a877 69 #define IS_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \
ganlikun 0:13413ea9a877 70 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \
ganlikun 0:13413ea9a877 71 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \
ganlikun 0:13413ea9a877 72 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \
ganlikun 0:13413ea9a877 73 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \
ganlikun 0:13413ea9a877 74 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \
ganlikun 0:13413ea9a877 75 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \
ganlikun 0:13413ea9a877 76 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128))
ganlikun 0:13413ea9a877 77
ganlikun 0:13413ea9a877 78 #define IS_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \
ganlikun 0:13413ea9a877 79 || ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE))
ganlikun 0:13413ea9a877 80
ganlikun 0:13413ea9a877 81 #define IS_LPTIM_OUTPUT_POLARITY(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_REGULAR) \
ganlikun 0:13413ea9a877 82 || ((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_INVERSE))
ganlikun 0:13413ea9a877 83 /**
ganlikun 0:13413ea9a877 84 * @}
ganlikun 0:13413ea9a877 85 */
ganlikun 0:13413ea9a877 86
ganlikun 0:13413ea9a877 87
ganlikun 0:13413ea9a877 88 /* Private function prototypes -----------------------------------------------*/
ganlikun 0:13413ea9a877 89 /* Exported functions --------------------------------------------------------*/
ganlikun 0:13413ea9a877 90 /** @addtogroup LPTIM_LL_Exported_Functions
ganlikun 0:13413ea9a877 91 * @{
ganlikun 0:13413ea9a877 92 */
ganlikun 0:13413ea9a877 93
ganlikun 0:13413ea9a877 94 /** @addtogroup LPTIM_LL_EF_Init
ganlikun 0:13413ea9a877 95 * @{
ganlikun 0:13413ea9a877 96 */
ganlikun 0:13413ea9a877 97
ganlikun 0:13413ea9a877 98 /**
ganlikun 0:13413ea9a877 99 * @brief Set LPTIMx registers to their reset values.
ganlikun 0:13413ea9a877 100 * @param LPTIMx LP Timer instance
ganlikun 0:13413ea9a877 101 * @retval An ErrorStatus enumeration value:
ganlikun 0:13413ea9a877 102 * - SUCCESS: LPTIMx registers are de-initialized
ganlikun 0:13413ea9a877 103 * - ERROR: invalid LPTIMx instance
ganlikun 0:13413ea9a877 104 */
ganlikun 0:13413ea9a877 105 ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef* LPTIMx)
ganlikun 0:13413ea9a877 106 {
ganlikun 0:13413ea9a877 107 ErrorStatus result = SUCCESS;
ganlikun 0:13413ea9a877 108
ganlikun 0:13413ea9a877 109 /* Check the parameters */
ganlikun 0:13413ea9a877 110 assert_param(IS_LPTIM_INSTANCE(LPTIMx));
ganlikun 0:13413ea9a877 111
ganlikun 0:13413ea9a877 112 if (LPTIMx == LPTIM1)
ganlikun 0:13413ea9a877 113 {
ganlikun 0:13413ea9a877 114 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1);
ganlikun 0:13413ea9a877 115 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1);
ganlikun 0:13413ea9a877 116 }
ganlikun 0:13413ea9a877 117 #if defined(LPTIM2)
ganlikun 0:13413ea9a877 118 else if (LPTIMx == LPTIM2)
ganlikun 0:13413ea9a877 119 {
ganlikun 0:13413ea9a877 120 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM2);
ganlikun 0:13413ea9a877 121 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM2);
ganlikun 0:13413ea9a877 122 }
ganlikun 0:13413ea9a877 123 #endif
ganlikun 0:13413ea9a877 124 else
ganlikun 0:13413ea9a877 125 {
ganlikun 0:13413ea9a877 126 result = ERROR;
ganlikun 0:13413ea9a877 127 }
ganlikun 0:13413ea9a877 128
ganlikun 0:13413ea9a877 129 return result;
ganlikun 0:13413ea9a877 130 }
ganlikun 0:13413ea9a877 131
ganlikun 0:13413ea9a877 132 /**
ganlikun 0:13413ea9a877 133 * @brief Set each fields of the LPTIM_InitStruct structure to its default
ganlikun 0:13413ea9a877 134 * value.
ganlikun 0:13413ea9a877 135 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
ganlikun 0:13413ea9a877 136 * @retval None
ganlikun 0:13413ea9a877 137 */
ganlikun 0:13413ea9a877 138 void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef* LPTIM_InitStruct)
ganlikun 0:13413ea9a877 139 {
ganlikun 0:13413ea9a877 140 /* Set the default configuration */
ganlikun 0:13413ea9a877 141 LPTIM_InitStruct->ClockSource = LL_LPTIM_CLK_SOURCE_INTERNAL;
ganlikun 0:13413ea9a877 142 LPTIM_InitStruct->Prescaler = LL_LPTIM_PRESCALER_DIV1;
ganlikun 0:13413ea9a877 143 LPTIM_InitStruct->Waveform = LL_LPTIM_OUTPUT_WAVEFORM_PWM;
ganlikun 0:13413ea9a877 144 LPTIM_InitStruct->Polarity = LL_LPTIM_OUTPUT_POLARITY_REGULAR;
ganlikun 0:13413ea9a877 145 }
ganlikun 0:13413ea9a877 146
ganlikun 0:13413ea9a877 147 /**
ganlikun 0:13413ea9a877 148 * @brief Configure the LPTIMx peripheral according to the specified parameters.
ganlikun 0:13413ea9a877 149 * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled.
ganlikun 0:13413ea9a877 150 * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable().
ganlikun 0:13413ea9a877 151 * @param LPTIMx LP Timer Instance
ganlikun 0:13413ea9a877 152 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure
ganlikun 0:13413ea9a877 153 * @retval An ErrorStatus enumeration value:
ganlikun 0:13413ea9a877 154 * - SUCCESS: LPTIMx instance has been initialized
ganlikun 0:13413ea9a877 155 * - ERROR: LPTIMx instance hasn't been initialized
ganlikun 0:13413ea9a877 156 */
ganlikun 0:13413ea9a877 157 ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef * LPTIMx, LL_LPTIM_InitTypeDef* LPTIM_InitStruct)
ganlikun 0:13413ea9a877 158 {
ganlikun 0:13413ea9a877 159 ErrorStatus result = SUCCESS;
ganlikun 0:13413ea9a877 160
ganlikun 0:13413ea9a877 161 /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled
ganlikun 0:13413ea9a877 162 (ENABLE bit is reset to 0).
ganlikun 0:13413ea9a877 163 */
ganlikun 0:13413ea9a877 164 if (LL_LPTIM_IsEnabled(LPTIMx))
ganlikun 0:13413ea9a877 165 {
ganlikun 0:13413ea9a877 166 result = ERROR;
ganlikun 0:13413ea9a877 167 }
ganlikun 0:13413ea9a877 168 else
ganlikun 0:13413ea9a877 169 {
ganlikun 0:13413ea9a877 170 /* Check the parameters */
ganlikun 0:13413ea9a877 171 assert_param(IS_LPTIM_INSTANCE(LPTIMx));
ganlikun 0:13413ea9a877 172 assert_param(IS_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource));
ganlikun 0:13413ea9a877 173 assert_param(IS_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler));
ganlikun 0:13413ea9a877 174 assert_param(IS_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform));
ganlikun 0:13413ea9a877 175 assert_param(IS_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->Polarity));
ganlikun 0:13413ea9a877 176
ganlikun 0:13413ea9a877 177 /* Set CKSEL bitfield according to ClockSource value */
ganlikun 0:13413ea9a877 178 /* Set PRESC bitfield according to Prescaler value */
ganlikun 0:13413ea9a877 179 /* Set WAVE bitfield according to Waveform value */
ganlikun 0:13413ea9a877 180 /* Set WAVEPOL bitfield according to Polarity value */
ganlikun 0:13413ea9a877 181 MODIFY_REG(LPTIMx->CFGR,
ganlikun 0:13413ea9a877 182 (LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE| LPTIM_CFGR_WAVPOL),
ganlikun 0:13413ea9a877 183 LPTIM_InitStruct->ClockSource | \
ganlikun 0:13413ea9a877 184 LPTIM_InitStruct->Prescaler | \
ganlikun 0:13413ea9a877 185 LPTIM_InitStruct->Waveform | \
ganlikun 0:13413ea9a877 186 LPTIM_InitStruct->Polarity);
ganlikun 0:13413ea9a877 187 }
ganlikun 0:13413ea9a877 188
ganlikun 0:13413ea9a877 189 return result;
ganlikun 0:13413ea9a877 190 }
ganlikun 0:13413ea9a877 191
ganlikun 0:13413ea9a877 192 /**
ganlikun 0:13413ea9a877 193 * @}
ganlikun 0:13413ea9a877 194 */
ganlikun 0:13413ea9a877 195
ganlikun 0:13413ea9a877 196 /**
ganlikun 0:13413ea9a877 197 * @}
ganlikun 0:13413ea9a877 198 */
ganlikun 0:13413ea9a877 199
ganlikun 0:13413ea9a877 200 /**
ganlikun 0:13413ea9a877 201 * @}
ganlikun 0:13413ea9a877 202 */
ganlikun 0:13413ea9a877 203
ganlikun 0:13413ea9a877 204 #endif /* defined (LPTIM1) || defined (LPTIM2) */
ganlikun 0:13413ea9a877 205
ganlikun 0:13413ea9a877 206 /**
ganlikun 0:13413ea9a877 207 * @}
ganlikun 0:13413ea9a877 208 */
ganlikun 0:13413ea9a877 209
ganlikun 0:13413ea9a877 210 #endif /* USE_FULL_LL_DRIVER */
ganlikun 0:13413ea9a877 211
ganlikun 0:13413ea9a877 212 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ganlikun 0:13413ea9a877 213