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