Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:09

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_ll_gpio.c
0004   * @author  MCD Application Team
0005   * @brief   GPIO LL module driver.
0006   ******************************************************************************
0007   * @attention
0008   *
0009   * Copyright (c) 2017 STMicroelectronics.
0010   * All rights reserved.
0011   *
0012   * This software is licensed under terms that can be found in the LICENSE file
0013   * in the root directory of this software component.
0014   * If no LICENSE file comes with this software, it is provided AS-IS.
0015   *
0016   ******************************************************************************
0017   */
0018   
0019 #if defined(USE_FULL_LL_DRIVER) || defined(__rtems__)
0020 
0021 /* Includes ------------------------------------------------------------------*/
0022 #include "stm32h7xx_ll_gpio.h"
0023 #include "stm32h7xx_ll_bus.h"
0024 #ifdef  USE_FULL_ASSERT
0025 #include "stm32_assert.h"
0026 #else
0027 #define assert_param(expr) ((void)0U)
0028 #endif
0029 
0030 /** @addtogroup STM32H7xx_LL_Driver
0031   * @{
0032   */
0033 
0034 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK)
0035 
0036 /** @addtogroup GPIO_LL
0037   * @{
0038   */
0039 
0040 /* Private types -------------------------------------------------------------*/
0041 /* Private variables ---------------------------------------------------------*/
0042 /* Private constants ---------------------------------------------------------*/
0043 /* Private macros ------------------------------------------------------------*/
0044 /** @addtogroup GPIO_LL_Private_Macros
0045   * @{
0046   */
0047 #define IS_LL_GPIO_PIN(__VALUE__)          (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
0048 
0049 #define IS_LL_GPIO_MODE(__VALUE__)         (((__VALUE__) == LL_GPIO_MODE_INPUT)     ||\
0050                                             ((__VALUE__) == LL_GPIO_MODE_OUTPUT)    ||\
0051                                             ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
0052                                             ((__VALUE__) == LL_GPIO_MODE_ANALOG))
0053 
0054 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__)  (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL)  ||\
0055                                             ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
0056 
0057 #define IS_LL_GPIO_SPEED(__VALUE__)        (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW)       ||\
0058                                             ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM)    ||\
0059                                             ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH)      ||\
0060                                             ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
0061 
0062 #define IS_LL_GPIO_PULL(__VALUE__)         (((__VALUE__) == LL_GPIO_PULL_NO)   ||\
0063                                             ((__VALUE__) == LL_GPIO_PULL_UP)   ||\
0064                                             ((__VALUE__) == LL_GPIO_PULL_DOWN))
0065 
0066 #define IS_LL_GPIO_ALTERNATE(__VALUE__)    (((__VALUE__) == LL_GPIO_AF_0  )   ||\
0067                                             ((__VALUE__) == LL_GPIO_AF_1  )   ||\
0068                                             ((__VALUE__) == LL_GPIO_AF_2  )   ||\
0069                                             ((__VALUE__) == LL_GPIO_AF_3  )   ||\
0070                                             ((__VALUE__) == LL_GPIO_AF_4  )   ||\
0071                                             ((__VALUE__) == LL_GPIO_AF_5  )   ||\
0072                                             ((__VALUE__) == LL_GPIO_AF_6  )   ||\
0073                                             ((__VALUE__) == LL_GPIO_AF_7  )   ||\
0074                                             ((__VALUE__) == LL_GPIO_AF_8  )   ||\
0075                                             ((__VALUE__) == LL_GPIO_AF_9  )   ||\
0076                                             ((__VALUE__) == LL_GPIO_AF_10 )   ||\
0077                                             ((__VALUE__) == LL_GPIO_AF_11 )   ||\
0078                                             ((__VALUE__) == LL_GPIO_AF_12 )   ||\
0079                                             ((__VALUE__) == LL_GPIO_AF_13 )   ||\
0080                                             ((__VALUE__) == LL_GPIO_AF_14 )   ||\
0081                                             ((__VALUE__) == LL_GPIO_AF_15 ))
0082 /**
0083   * @}
0084   */
0085 
0086 /* Private function prototypes -----------------------------------------------*/
0087 
0088 /* Exported functions --------------------------------------------------------*/
0089 /** @addtogroup GPIO_LL_Exported_Functions
0090   * @{
0091   */
0092 
0093 /** @addtogroup GPIO_LL_EF_Init
0094   * @{
0095   */
0096 
0097 /**
0098   * @brief  De-initialize GPIO registers (Registers restored to their default values).
0099   * @param  GPIOx GPIO Port
0100   * @retval An ErrorStatus enumeration value:
0101   *          - SUCCESS: GPIO registers are de-initialized
0102   *          - ERROR:   Wrong GPIO Port
0103   */
0104 ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
0105 {
0106   ErrorStatus status = SUCCESS;
0107 
0108   /* Check the parameters */
0109   assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
0110 
0111   /* Force and Release reset on clock of GPIOx Port */
0112   if (GPIOx == GPIOA)
0113   {
0114     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOA);
0115     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOA);
0116   }
0117   else if (GPIOx == GPIOB)
0118   {
0119     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOB);
0120     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOB);
0121   }
0122   else if (GPIOx == GPIOC)
0123   {
0124     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOC);
0125     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOC);
0126   }
0127 #if defined(GPIOD)
0128   else if (GPIOx == GPIOD)
0129   {
0130     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOD);
0131     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOD);
0132   }
0133 #endif /* GPIOD */
0134 #if defined(GPIOE)
0135   else if (GPIOx == GPIOE)
0136   {
0137     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOE);
0138     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOE);
0139   }
0140 #endif /* GPIOE */
0141 #if defined(GPIOF)
0142   else if (GPIOx == GPIOF)
0143   {
0144     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOF);
0145     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOF);
0146   }
0147 #endif /* GPIOF */
0148 #if defined(GPIOG)
0149   else if (GPIOx == GPIOG)
0150   {
0151     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOG);
0152     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOG);
0153   }
0154 #endif /* GPIOG */
0155 #if defined(GPIOH)
0156   else if (GPIOx == GPIOH)
0157   {
0158     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOH);
0159     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOH);
0160   }
0161 #endif /* GPIOH */
0162 #if defined(GPIOI)
0163   else if (GPIOx == GPIOI)
0164   {
0165     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOI);
0166     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOI);
0167   }
0168 #endif /* GPIOI */
0169 #if defined(GPIOJ)
0170   else if (GPIOx == GPIOJ)
0171   {
0172     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOJ);
0173     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOJ);
0174   }
0175 #endif /* GPIOJ */
0176 #if defined(GPIOK)
0177   else if (GPIOx == GPIOK)
0178   {
0179     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_GPIOK);
0180     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_GPIOK);
0181   }
0182 #endif /* GPIOK */
0183   else
0184   {
0185     status = ERROR;
0186   }
0187 
0188   return (status);
0189 }
0190 
0191 /**
0192   * @brief  Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
0193   * @param  GPIOx GPIO Port
0194   * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
0195   *         that contains the configuration information for the specified GPIO peripheral.
0196   * @retval An ErrorStatus enumeration value:
0197   *          - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
0198   *          - ERROR:   Not applicable
0199   */
0200 ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
0201 {
0202   uint32_t pinpos, currentpin;
0203 
0204   /* Check the parameters */
0205   assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
0206   assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
0207   assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
0208   assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
0209 
0210   /* ------------------------- Configure the port pins ---------------- */
0211   /* Initialize  pinpos on first pin set */
0212   pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
0213 
0214   /* Configure the port pins */
0215   while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
0216   {
0217     /* Get current io position */
0218     currentpin = (GPIO_InitStruct->Pin) & (0x00000001UL << pinpos);
0219 
0220     if (currentpin != 0x00000000U)
0221     {
0222 
0223       if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
0224       {
0225         /* Check Speed mode parameters */
0226         assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
0227 
0228         /* Speed mode configuration */
0229         LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
0230 
0231         /* Check Output mode parameters */
0232         assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
0233 
0234         /* Output mode configuration*/
0235         LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
0236 
0237       }
0238 
0239       /* Pull-up Pull down resistor configuration*/
0240       LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
0241 
0242       if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
0243       {
0244         /* Check Alternate parameter */
0245         assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
0246 
0247         /* Alternate function configuration */
0248         if (currentpin < LL_GPIO_PIN_8)
0249         {
0250           LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
0251         }
0252         else
0253         {
0254           LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
0255         }
0256       }
0257 
0258       /* Pin Mode configuration */
0259       LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
0260     }
0261     pinpos++;
0262   }
0263 
0264   return (SUCCESS);
0265 }
0266 
0267 /**
0268   * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
0269   * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
0270   *                          whose fields will be set to default values.
0271   * @retval None
0272   */
0273 
0274 void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
0275 {
0276   /* Reset GPIO init structure parameters values */
0277   GPIO_InitStruct->Pin        = LL_GPIO_PIN_ALL;
0278   GPIO_InitStruct->Mode       = LL_GPIO_MODE_ANALOG;
0279   GPIO_InitStruct->Speed      = LL_GPIO_SPEED_FREQ_LOW;
0280   GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
0281   GPIO_InitStruct->Pull       = LL_GPIO_PULL_NO;
0282   GPIO_InitStruct->Alternate  = LL_GPIO_AF_0;
0283 }
0284 
0285 /**
0286   * @}
0287   */
0288 
0289 /**
0290   * @}
0291   */
0292 
0293 /**
0294   * @}
0295   */
0296 
0297 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) */
0298 
0299 /**
0300   * @}
0301   */
0302 
0303 #endif /* USE_FULL_LL_DRIVER */
0304 
0305