Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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