STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_ll_gpio.c 00004 * @author MCD Application Team 00005 * @brief GPIO LL module driver. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 #if defined(USE_FULL_LL_DRIVER) 00020 00021 /* Includes ------------------------------------------------------------------*/ 00022 #include "stm32h7xx_ll_gpio.h" 00023 #include "stm32h7xx_ll_bus.h" 00024 #ifdef USE_FULL_ASSERT 00025 #include "stm32_assert.h" 00026 #else 00027 #define assert_param(expr) ((void)0U) 00028 #endif 00029 00030 /** @addtogroup STM32H7xx_LL_Driver 00031 * @{ 00032 */ 00033 00034 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) 00035 00036 /** @addtogroup GPIO_LL 00037 * @{ 00038 */ 00039 00040 /* Private types -------------------------------------------------------------*/ 00041 /* Private variables ---------------------------------------------------------*/ 00042 /* Private constants ---------------------------------------------------------*/ 00043 /* Private macros ------------------------------------------------------------*/ 00044 /** @addtogroup GPIO_LL_Private_Macros 00045 * @{ 00046 */ 00047 #define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL))) 00048 00049 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\ 00050 ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\ 00051 ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\ 00052 ((__VALUE__) == LL_GPIO_MODE_ANALOG)) 00053 00054 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\ 00055 ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN)) 00056 00057 #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\ 00058 ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\ 00059 ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\ 00060 ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH)) 00061 00062 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\ 00063 ((__VALUE__) == LL_GPIO_PULL_UP) ||\ 00064 ((__VALUE__) == LL_GPIO_PULL_DOWN)) 00065 00066 #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\ 00067 ((__VALUE__) == LL_GPIO_AF_1 ) ||\ 00068 ((__VALUE__) == LL_GPIO_AF_2 ) ||\ 00069 ((__VALUE__) == LL_GPIO_AF_3 ) ||\ 00070 ((__VALUE__) == LL_GPIO_AF_4 ) ||\ 00071 ((__VALUE__) == LL_GPIO_AF_5 ) ||\ 00072 ((__VALUE__) == LL_GPIO_AF_6 ) ||\ 00073 ((__VALUE__) == LL_GPIO_AF_7 ) ||\ 00074 ((__VALUE__) == LL_GPIO_AF_8 ) ||\ 00075 ((__VALUE__) == LL_GPIO_AF_9 ) ||\ 00076 ((__VALUE__) == LL_GPIO_AF_10 ) ||\ 00077 ((__VALUE__) == LL_GPIO_AF_11 ) ||\ 00078 ((__VALUE__) == LL_GPIO_AF_12 ) ||\ 00079 ((__VALUE__) == LL_GPIO_AF_13 ) ||\ 00080 ((__VALUE__) == LL_GPIO_AF_14 ) ||\ 00081 ((__VALUE__) == LL_GPIO_AF_15 )) 00082 /** 00083 * @} 00084 */ 00085 00086 /* Private function prototypes -----------------------------------------------*/ 00087 00088 /* Exported functions --------------------------------------------------------*/ 00089 /** @addtogroup GPIO_LL_Exported_Functions 00090 * @{ 00091 */ 00092 00093 /** @addtogroup GPIO_LL_EF_Init 00094 * @{ 00095 */ 00096 00097 /** 00098 * @brief De-initialize GPIO registers (Registers restored to their default values). 00099 * @param GPIOx GPIO Port 00100 * @retval An ErrorStatus enumeration value: 00101 * - SUCCESS: GPIO registers are de-initialized 00102 * - ERROR: Wrong GPIO Port 00103 */ 00104 ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx) 00105 { 00106 ErrorStatus status = SUCCESS; 00107 00108 /* Check the parameters */ 00109 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); 00110 00111 /* Force and Release reset on clock of GPIOx Port */ 00112 if (GPIOx == GPIOA) 00113 { 00114 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOA); 00115 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOA); 00116 } 00117 else if (GPIOx == GPIOB) 00118 { 00119 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOB); 00120 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOB); 00121 } 00122 else if (GPIOx == GPIOC) 00123 { 00124 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOC); 00125 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOC); 00126 } 00127 #if defined(GPIOD) 00128 else if (GPIOx == GPIOD) 00129 { 00130 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOD); 00131 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOD); 00132 } 00133 #endif /* GPIOD */ 00134 #if defined(GPIOE) 00135 else if (GPIOx == GPIOE) 00136 { 00137 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOE); 00138 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOE); 00139 } 00140 #endif /* GPIOE */ 00141 #if defined(GPIOF) 00142 else if (GPIOx == GPIOF) 00143 { 00144 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOF); 00145 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOF); 00146 } 00147 #endif /* GPIOF */ 00148 #if defined(GPIOG) 00149 else if (GPIOx == GPIOG) 00150 { 00151 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOG); 00152 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOG); 00153 } 00154 #endif /* GPIOG */ 00155 #if defined(GPIOH) 00156 else if (GPIOx == GPIOH) 00157 { 00158 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOH); 00159 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOH); 00160 } 00161 #endif /* GPIOH */ 00162 #if defined(GPIOI) 00163 else if (GPIOx == GPIOI) 00164 { 00165 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOI); 00166 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOI); 00167 } 00168 #endif /* GPIOI */ 00169 #if defined(GPIOJ) 00170 else if (GPIOx == GPIOJ) 00171 { 00172 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOJ); 00173 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOJ); 00174 } 00175 #endif /* GPIOJ */ 00176 #if defined(GPIOK) 00177 else if (GPIOx == GPIOK) 00178 { 00179 LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOK); 00180 LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOK); 00181 } 00182 #endif /* GPIOK */ 00183 else 00184 { 00185 status = ERROR; 00186 } 00187 00188 return (status); 00189 } 00190 00191 /** 00192 * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct. 00193 * @param GPIOx GPIO Port 00194 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure 00195 * that contains the configuration information for the specified GPIO peripheral. 00196 * @retval An ErrorStatus enumeration value: 00197 * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content 00198 * - ERROR: Not applicable 00199 */ 00200 ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct) 00201 { 00202 uint32_t pinpos, currentpin; 00203 00204 /* Check the parameters */ 00205 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); 00206 assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin)); 00207 assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode)); 00208 assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull)); 00209 00210 /* ------------------------- Configure the port pins ---------------- */ 00211 /* Initialize pinpos on first pin set */ 00212 pinpos = POSITION_VAL(GPIO_InitStruct->Pin); 00213 00214 /* Configure the port pins */ 00215 while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U) 00216 { 00217 /* Get current io position */ 00218 currentpin = (GPIO_InitStruct->Pin) & (0x00000001UL << pinpos); 00219 00220 if (currentpin != 0x00000000U) 00221 { 00222 00223 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)) 00224 { 00225 /* Check Speed mode parameters */ 00226 assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed)); 00227 00228 /* Speed mode configuration */ 00229 LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed); 00230 00231 /* Check Output mode parameters */ 00232 assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType)); 00233 00234 /* Output mode configuration*/ 00235 LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType); 00236 00237 } 00238 00239 /* Pull-up Pull down resistor configuration*/ 00240 LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull); 00241 00242 if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE) 00243 { 00244 /* Check Alternate parameter */ 00245 assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate)); 00246 00247 /* Alternate function configuration */ 00248 if (currentpin < LL_GPIO_PIN_8) 00249 { 00250 LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate); 00251 } 00252 else 00253 { 00254 LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate); 00255 } 00256 } 00257 00258 /* Pin Mode configuration */ 00259 LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode); 00260 } 00261 pinpos++; 00262 } 00263 00264 return (SUCCESS); 00265 } 00266 00267 /** 00268 * @brief Set each @ref LL_GPIO_InitTypeDef field to default value. 00269 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure 00270 * whose fields will be set to default values. 00271 * @retval None 00272 */ 00273 00274 void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct) 00275 { 00276 /* Reset GPIO init structure parameters values */ 00277 GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL; 00278 GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG; 00279 GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW; 00280 GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL; 00281 GPIO_InitStruct->Pull = LL_GPIO_PULL_NO; 00282 GPIO_InitStruct->Alternate = LL_GPIO_AF_0; 00283 } 00284 00285 /** 00286 * @} 00287 */ 00288 00289 /** 00290 * @} 00291 */ 00292 00293 /** 00294 * @} 00295 */ 00296 00297 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) */ 00298 00299 /** 00300 * @} 00301 */ 00302 00303 #endif /* USE_FULL_LL_DRIVER */ 00304 00305