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