STM32F439xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_ll_gpio.c 00004 * @author MCD Application Team 00005 * @brief GPIO 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_gpio.h" 00039 #include "stm32f4xx_ll_bus.h" 00040 #ifdef USE_FULL_ASSERT 00041 #include "stm32_assert.h" 00042 #else 00043 #define assert_param(expr) ((void)0U) 00044 #endif 00045 00046 /** @addtogroup STM32F4xx_LL_Driver 00047 * @{ 00048 */ 00049 00050 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) 00051 00052 /** @addtogroup GPIO_LL 00053 * @{ 00054 */ 00055 00056 /* Private types -------------------------------------------------------------*/ 00057 /* Private variables ---------------------------------------------------------*/ 00058 /* Private constants ---------------------------------------------------------*/ 00059 /* Private macros ------------------------------------------------------------*/ 00060 /** @addtogroup GPIO_LL_Private_Macros 00061 * @{ 00062 */ 00063 #define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL))) 00064 00065 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\ 00066 ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\ 00067 ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\ 00068 ((__VALUE__) == LL_GPIO_MODE_ANALOG)) 00069 00070 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\ 00071 ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN)) 00072 00073 #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\ 00074 ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\ 00075 ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\ 00076 ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH)) 00077 00078 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\ 00079 ((__VALUE__) == LL_GPIO_PULL_UP) ||\ 00080 ((__VALUE__) == LL_GPIO_PULL_DOWN)) 00081 00082 #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\ 00083 ((__VALUE__) == LL_GPIO_AF_1 ) ||\ 00084 ((__VALUE__) == LL_GPIO_AF_2 ) ||\ 00085 ((__VALUE__) == LL_GPIO_AF_3 ) ||\ 00086 ((__VALUE__) == LL_GPIO_AF_4 ) ||\ 00087 ((__VALUE__) == LL_GPIO_AF_5 ) ||\ 00088 ((__VALUE__) == LL_GPIO_AF_6 ) ||\ 00089 ((__VALUE__) == LL_GPIO_AF_7 ) ||\ 00090 ((__VALUE__) == LL_GPIO_AF_8 ) ||\ 00091 ((__VALUE__) == LL_GPIO_AF_9 ) ||\ 00092 ((__VALUE__) == LL_GPIO_AF_10 ) ||\ 00093 ((__VALUE__) == LL_GPIO_AF_11 ) ||\ 00094 ((__VALUE__) == LL_GPIO_AF_12 ) ||\ 00095 ((__VALUE__) == LL_GPIO_AF_13 ) ||\ 00096 ((__VALUE__) == LL_GPIO_AF_14 ) ||\ 00097 ((__VALUE__) == LL_GPIO_AF_15 )) 00098 /** 00099 * @} 00100 */ 00101 00102 /* Private function prototypes -----------------------------------------------*/ 00103 00104 /* Exported functions --------------------------------------------------------*/ 00105 /** @addtogroup GPIO_LL_Exported_Functions 00106 * @{ 00107 */ 00108 00109 /** @addtogroup GPIO_LL_EF_Init 00110 * @{ 00111 */ 00112 00113 /** 00114 * @brief De-initialize GPIO registers (Registers restored to their default values). 00115 * @param GPIOx GPIO Port 00116 * @retval An ErrorStatus enumeration value: 00117 * - SUCCESS: GPIO registers are de-initialized 00118 * - ERROR: Wrong GPIO Port 00119 */ 00120 ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx) 00121 { 00122 ErrorStatus status = SUCCESS; 00123 00124 /* Check the parameters */ 00125 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); 00126 00127 /* Force and Release reset on clock of GPIOx Port */ 00128 if (GPIOx == GPIOA) 00129 { 00130 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA); 00131 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA); 00132 } 00133 else if (GPIOx == GPIOB) 00134 { 00135 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB); 00136 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB); 00137 } 00138 else if (GPIOx == GPIOC) 00139 { 00140 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC); 00141 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC); 00142 } 00143 #if defined(GPIOD) 00144 else if (GPIOx == GPIOD) 00145 { 00146 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD); 00147 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD); 00148 } 00149 #endif /* GPIOD */ 00150 #if defined(GPIOE) 00151 else if (GPIOx == GPIOE) 00152 { 00153 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE); 00154 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE); 00155 } 00156 #endif /* GPIOE */ 00157 #if defined(GPIOF) 00158 else if (GPIOx == GPIOF) 00159 { 00160 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF); 00161 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF); 00162 } 00163 #endif /* GPIOF */ 00164 #if defined(GPIOG) 00165 else if (GPIOx == GPIOG) 00166 { 00167 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOG); 00168 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOG); 00169 } 00170 #endif /* GPIOG */ 00171 #if defined(GPIOH) 00172 else if (GPIOx == GPIOH) 00173 { 00174 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOH); 00175 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOH); 00176 } 00177 #endif /* GPIOH */ 00178 #if defined(GPIOI) 00179 else if (GPIOx == GPIOI) 00180 { 00181 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOI); 00182 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOI); 00183 } 00184 #endif /* GPIOI */ 00185 #if defined(GPIOJ) 00186 else if (GPIOx == GPIOJ) 00187 { 00188 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOJ); 00189 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOJ); 00190 } 00191 #endif /* GPIOJ */ 00192 #if defined(GPIOK) 00193 else if (GPIOx == GPIOK) 00194 { 00195 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOK); 00196 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOK); 00197 } 00198 #endif /* GPIOK */ 00199 else 00200 { 00201 status = ERROR; 00202 } 00203 00204 return (status); 00205 } 00206 00207 /** 00208 * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct. 00209 * @param GPIOx GPIO Port 00210 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure 00211 * that contains the configuration information for the specified GPIO peripheral. 00212 * @retval An ErrorStatus enumeration value: 00213 * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content 00214 * - ERROR: Not applicable 00215 */ 00216 ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct) 00217 { 00218 uint32_t pinpos = 0x00000000U; 00219 uint32_t currentpin = 0x00000000U; 00220 00221 /* Check the parameters */ 00222 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); 00223 assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin)); 00224 assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode)); 00225 assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull)); 00226 00227 /* ------------------------- Configure the port pins ---------------- */ 00228 /* Initialize pinpos on first pin set */ 00229 pinpos = POSITION_VAL(GPIO_InitStruct->Pin); 00230 00231 /* Configure the port pins */ 00232 while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U) 00233 { 00234 /* Get current io position */ 00235 currentpin = (GPIO_InitStruct->Pin) & (0x00000001U << pinpos); 00236 00237 if (currentpin) 00238 { 00239 /* Pin Mode configuration */ 00240 LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode); 00241 00242 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)) 00243 { 00244 /* Check Speed mode parameters */ 00245 assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed)); 00246 00247 /* Speed mode configuration */ 00248 LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed); 00249 } 00250 00251 /* Pull-up Pull down resistor configuration*/ 00252 LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull); 00253 00254 if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE) 00255 { 00256 /* Check Alternate parameter */ 00257 assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate)); 00258 00259 /* Speed mode configuration */ 00260 if (POSITION_VAL(currentpin) < 0x00000008U) 00261 { 00262 LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate); 00263 } 00264 else 00265 { 00266 LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate); 00267 } 00268 } 00269 } 00270 pinpos++; 00271 } 00272 00273 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)) 00274 { 00275 /* Check Output mode parameters */ 00276 assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType)); 00277 00278 /* Output mode configuration*/ 00279 LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType); 00280 00281 } 00282 return (SUCCESS); 00283 } 00284 00285 /** 00286 * @brief Set each @ref LL_GPIO_InitTypeDef field to default value. 00287 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure 00288 * whose fields will be set to default values. 00289 * @retval None 00290 */ 00291 00292 void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct) 00293 { 00294 /* Reset GPIO init structure parameters values */ 00295 GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL; 00296 GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG; 00297 GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW; 00298 GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL; 00299 GPIO_InitStruct->Pull = LL_GPIO_PULL_NO; 00300 GPIO_InitStruct->Alternate = LL_GPIO_AF_0; 00301 } 00302 00303 /** 00304 * @} 00305 */ 00306 00307 /** 00308 * @} 00309 */ 00310 00311 /** 00312 * @} 00313 */ 00314 00315 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) */ 00316 00317 /** 00318 * @} 00319 */ 00320 00321 #endif /* USE_FULL_LL_DRIVER */ 00322 00323 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/