1 /** 2 ****************************************************************************** 3 * @file stm32h5xx_ll_lptim.c 4 * @author MCD Application Team 5 * @brief LPTIM LL module driver. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 #if defined(USE_FULL_LL_DRIVER) 19 20 /* Includes ------------------------------------------------------------------*/ 21 #include "stm32h5xx_ll_lptim.h" 22 #include "stm32h5xx_ll_bus.h" 23 #include "stm32h5xx_ll_rcc.h" 24 25 26 #ifdef USE_FULL_ASSERT 27 #include "stm32_assert.h" 28 #else 29 #define assert_param(expr) ((void)0U) 30 #endif /* USE_FULL_ASSERT */ 31 32 /** @addtogroup STM32H5xx_LL_Driver 33 * @{ 34 */ 35 36 #if defined (LPTIM1) || defined (LPTIM2) || defined (LPTIM3) || defined (LPTIM4) || defined (LPTIM5) || defined (LPTIM6) 37 38 /** @addtogroup LPTIM_LL 39 * @{ 40 */ 41 42 /* Private types -------------------------------------------------------------*/ 43 /* Private variables ---------------------------------------------------------*/ 44 /* Private constants ---------------------------------------------------------*/ 45 /* Private macros ------------------------------------------------------------*/ 46 /** @addtogroup LPTIM_LL_Private_Macros 47 * @{ 48 */ 49 #define IS_LL_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \ 50 || ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL)) 51 52 #define IS_LL_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \ 53 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \ 54 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \ 55 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \ 56 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \ 57 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \ 58 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \ 59 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128)) 60 61 #define IS_LL_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \ 62 || ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE)) 63 64 /** 65 * @} 66 */ 67 68 69 /* Private function prototypes -----------------------------------------------*/ 70 /* Private functions ---------------------------------------------------------*/ 71 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions 72 * @{ 73 */ 74 /** 75 * @} 76 */ 77 /* Exported functions --------------------------------------------------------*/ 78 /** @addtogroup LPTIM_LL_Exported_Functions 79 * @{ 80 */ 81 82 /** @addtogroup LPTIM_LL_EF_Init 83 * @{ 84 */ 85 86 /** 87 * @brief Set LPTIMx registers to their reset values. 88 * @param LPTIMx LP Timer instance 89 * @retval An ErrorStatus enumeration value: 90 * - SUCCESS: LPTIMx registers are de-initialized 91 * - ERROR: invalid LPTIMx instance 92 */ LL_LPTIM_DeInit(LPTIM_TypeDef * LPTIMx)93ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef *LPTIMx) 94 { 95 ErrorStatus result = SUCCESS; 96 97 /* Check the parameters */ 98 assert_param(IS_LPTIM_INSTANCE(LPTIMx)); 99 100 if (LPTIMx == LPTIM1) 101 { 102 LL_APB3_GRP1_ForceReset(LL_APB3_GRP1_PERIPH_LPTIM1); 103 LL_APB3_GRP1_ReleaseReset(LL_APB3_GRP1_PERIPH_LPTIM1); 104 } 105 else if (LPTIMx == LPTIM2) 106 { 107 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM2); 108 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM2); 109 } 110 #if defined(LPTIM3) 111 else if (LPTIMx == LPTIM3) 112 { 113 LL_APB3_GRP1_ForceReset(LL_APB3_GRP1_PERIPH_LPTIM3); 114 LL_APB3_GRP1_ReleaseReset(LL_APB3_GRP1_PERIPH_LPTIM3); 115 } 116 #endif /* LPTIM3 */ 117 #if defined(LPTIM4) 118 else if (LPTIMx == LPTIM4) 119 { 120 LL_APB3_GRP1_ForceReset(LL_APB3_GRP1_PERIPH_LPTIM4); 121 LL_APB3_GRP1_ReleaseReset(LL_APB3_GRP1_PERIPH_LPTIM4); 122 } 123 #endif /* LPTIM4 */ 124 #if defined(LPTIM5) 125 else if (LPTIMx == LPTIM5) 126 { 127 LL_APB3_GRP1_ForceReset(LL_APB3_GRP1_PERIPH_LPTIM5); 128 LL_APB3_GRP1_ReleaseReset(LL_APB3_GRP1_PERIPH_LPTIM5); 129 } 130 #endif /* LPTIM5 */ 131 #if defined(LPTIM6) 132 else if (LPTIMx == LPTIM6) 133 { 134 LL_APB3_GRP1_ForceReset(LL_APB3_GRP1_PERIPH_LPTIM6); 135 LL_APB3_GRP1_ReleaseReset(LL_APB3_GRP1_PERIPH_LPTIM6); 136 } 137 #endif /* LPTIM6 */ 138 else 139 { 140 result = ERROR; 141 } 142 143 return result; 144 } 145 146 /** 147 * @brief Set each fields of the LPTIM_InitStruct structure to its default 148 * value. 149 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure 150 * @retval None 151 */ LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef * LPTIM_InitStruct)152void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef *LPTIM_InitStruct) 153 { 154 /* Set the default configuration */ 155 LPTIM_InitStruct->ClockSource = LL_LPTIM_CLK_SOURCE_INTERNAL; 156 LPTIM_InitStruct->Prescaler = LL_LPTIM_PRESCALER_DIV1; 157 LPTIM_InitStruct->Waveform = LL_LPTIM_OUTPUT_WAVEFORM_PWM; 158 } 159 160 /** 161 * @brief Configure the LPTIMx peripheral according to the specified parameters. 162 * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled. 163 * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable(). 164 * @param LPTIMx LP Timer Instance 165 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure 166 * @retval An ErrorStatus enumeration value: 167 * - SUCCESS: LPTIMx instance has been initialized 168 * - ERROR: LPTIMx instance hasn't been initialized 169 */ LL_LPTIM_Init(LPTIM_TypeDef * LPTIMx,const LL_LPTIM_InitTypeDef * LPTIM_InitStruct)170ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef *LPTIMx, const LL_LPTIM_InitTypeDef *LPTIM_InitStruct) 171 { 172 ErrorStatus result = SUCCESS; 173 /* Check the parameters */ 174 assert_param(IS_LPTIM_INSTANCE(LPTIMx)); 175 assert_param(IS_LL_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource)); 176 assert_param(IS_LL_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler)); 177 assert_param(IS_LL_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform)); 178 179 /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled 180 (ENABLE bit is reset to 0). 181 */ 182 if (LL_LPTIM_IsEnabled(LPTIMx) == 1UL) 183 { 184 result = ERROR; 185 } 186 else 187 { 188 /* Set CKSEL bitfield according to ClockSource value */ 189 /* Set PRESC bitfield according to Prescaler value */ 190 /* Set WAVE bitfield according to Waveform value */ 191 MODIFY_REG(LPTIMx->CFGR, 192 (LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE), 193 LPTIM_InitStruct->ClockSource | \ 194 LPTIM_InitStruct->Prescaler | \ 195 LPTIM_InitStruct->Waveform); 196 } 197 198 return result; 199 } 200 201 /** 202 * @} 203 */ 204 205 /** 206 * @} 207 */ 208 209 /** 210 * @} 211 */ 212 213 #endif /* LPTIM1 || LPTIM2 || LPTIM3 || LPTIM4 || LPTIM5 || LPTIM6 */ 214 215 /** 216 * @} 217 */ 218 219 #endif /* USE_FULL_LL_DRIVER */ 220