STM32F439xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_ll_lptim.c 00004 * @author MCD Application Team 00005 * @brief LPTIM LL module driver. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 #if defined(USE_FULL_LL_DRIVER) 00036 00037 /* Includes ------------------------------------------------------------------*/ 00038 #include "stm32f4xx_ll_lptim.h" 00039 #include "stm32f4xx_ll_bus.h" 00040 00041 #ifdef USE_FULL_ASSERT 00042 #include "stm32_assert.h" 00043 #else 00044 #define assert_param(expr) ((void)0U) 00045 #endif 00046 00047 /** @addtogroup STM32F4xx_LL_Driver 00048 * @{ 00049 */ 00050 00051 #if defined (LPTIM1) || defined (LPTIM2) 00052 00053 /** @addtogroup LPTIM_LL 00054 * @{ 00055 */ 00056 00057 /* Private types -------------------------------------------------------------*/ 00058 /* Private variables ---------------------------------------------------------*/ 00059 /* Private constants ---------------------------------------------------------*/ 00060 /* Private macros ------------------------------------------------------------*/ 00061 /** @addtogroup LPTIM_LL_Private_Macros 00062 * @{ 00063 */ 00064 #define IS_LPTIM_CLOCK_SOURCE(__VALUE__) (((__VALUE__) == LL_LPTIM_CLK_SOURCE_INTERNAL) \ 00065 || ((__VALUE__) == LL_LPTIM_CLK_SOURCE_EXTERNAL)) 00066 00067 #define IS_LPTIM_CLOCK_PRESCALER(__VALUE__) (((__VALUE__) == LL_LPTIM_PRESCALER_DIV1) \ 00068 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV2) \ 00069 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV4) \ 00070 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV8) \ 00071 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV16) \ 00072 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV32) \ 00073 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV64) \ 00074 || ((__VALUE__) == LL_LPTIM_PRESCALER_DIV128)) 00075 00076 #define IS_LPTIM_WAVEFORM(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_PWM) \ 00077 || ((__VALUE__) == LL_LPTIM_OUTPUT_WAVEFORM_SETONCE)) 00078 00079 #define IS_LPTIM_OUTPUT_POLARITY(__VALUE__) (((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_REGULAR) \ 00080 || ((__VALUE__) == LL_LPTIM_OUTPUT_POLARITY_INVERSE)) 00081 /** 00082 * @} 00083 */ 00084 00085 00086 /* Private function prototypes -----------------------------------------------*/ 00087 /* Exported functions --------------------------------------------------------*/ 00088 /** @addtogroup LPTIM_LL_Exported_Functions 00089 * @{ 00090 */ 00091 00092 /** @addtogroup LPTIM_LL_EF_Init 00093 * @{ 00094 */ 00095 00096 /** 00097 * @brief Set LPTIMx registers to their reset values. 00098 * @param LPTIMx LP Timer instance 00099 * @retval An ErrorStatus enumeration value: 00100 * - SUCCESS: LPTIMx registers are de-initialized 00101 * - ERROR: invalid LPTIMx instance 00102 */ 00103 ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef* LPTIMx) 00104 { 00105 ErrorStatus result = SUCCESS; 00106 00107 /* Check the parameters */ 00108 assert_param(IS_LPTIM_INSTANCE(LPTIMx)); 00109 00110 if (LPTIMx == LPTIM1) 00111 { 00112 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1); 00113 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_LPTIM1); 00114 } 00115 #if defined(LPTIM2) 00116 else if (LPTIMx == LPTIM2) 00117 { 00118 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_LPTIM2); 00119 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_LPTIM2); 00120 } 00121 #endif 00122 else 00123 { 00124 result = ERROR; 00125 } 00126 00127 return result; 00128 } 00129 00130 /** 00131 * @brief Set each fields of the LPTIM_InitStruct structure to its default 00132 * value. 00133 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure 00134 * @retval None 00135 */ 00136 void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef* LPTIM_InitStruct) 00137 { 00138 /* Set the default configuration */ 00139 LPTIM_InitStruct->ClockSource = LL_LPTIM_CLK_SOURCE_INTERNAL; 00140 LPTIM_InitStruct->Prescaler = LL_LPTIM_PRESCALER_DIV1; 00141 LPTIM_InitStruct->Waveform = LL_LPTIM_OUTPUT_WAVEFORM_PWM; 00142 LPTIM_InitStruct->Polarity = LL_LPTIM_OUTPUT_POLARITY_REGULAR; 00143 } 00144 00145 /** 00146 * @brief Configure the LPTIMx peripheral according to the specified parameters. 00147 * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled. 00148 * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable(). 00149 * @param LPTIMx LP Timer Instance 00150 * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure 00151 * @retval An ErrorStatus enumeration value: 00152 * - SUCCESS: LPTIMx instance has been initialized 00153 * - ERROR: LPTIMx instance hasn't been initialized 00154 */ 00155 ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef * LPTIMx, LL_LPTIM_InitTypeDef* LPTIM_InitStruct) 00156 { 00157 ErrorStatus result = SUCCESS; 00158 00159 /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled 00160 (ENABLE bit is reset to 0). 00161 */ 00162 if (LL_LPTIM_IsEnabled(LPTIMx)) 00163 { 00164 result = ERROR; 00165 } 00166 else 00167 { 00168 /* Check the parameters */ 00169 assert_param(IS_LPTIM_INSTANCE(LPTIMx)); 00170 assert_param(IS_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource)); 00171 assert_param(IS_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler)); 00172 assert_param(IS_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform)); 00173 assert_param(IS_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->Polarity)); 00174 00175 /* Set CKSEL bitfield according to ClockSource value */ 00176 /* Set PRESC bitfield according to Prescaler value */ 00177 /* Set WAVE bitfield according to Waveform value */ 00178 /* Set WAVEPOL bitfield according to Polarity value */ 00179 MODIFY_REG(LPTIMx->CFGR, 00180 (LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE| LPTIM_CFGR_WAVPOL), 00181 LPTIM_InitStruct->ClockSource | \ 00182 LPTIM_InitStruct->Prescaler | \ 00183 LPTIM_InitStruct->Waveform | \ 00184 LPTIM_InitStruct->Polarity); 00185 } 00186 00187 return result; 00188 } 00189 00190 /** 00191 * @} 00192 */ 00193 00194 /** 00195 * @} 00196 */ 00197 00198 /** 00199 * @} 00200 */ 00201 00202 #endif /* defined (LPTIM1) || defined (LPTIM2) */ 00203 00204 /** 00205 * @} 00206 */ 00207 00208 #endif /* USE_FULL_LL_DRIVER */ 00209 00210 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/