2 ******************************************************************************
3 * @file stm32f7xx_ll_gpio.c
4 * @author MCD Application Team
7 * @brief GPIO LL module driver.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
37 #if defined(USE_FULL_LL_DRIVER)
39 /* Includes ------------------------------------------------------------------*/
40 #include "stm32f7xx_ll_gpio.h"
41 #include "stm32f7xx_ll_bus.h"
42 #ifdef USE_FULL_ASSERT
43 #include "stm32_assert.h"
45 #define assert_param(expr) ((void)0U)
48 /** @addtogroup STM32F7xx_LL_Driver
52 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK)
54 /** @addtogroup GPIO_LL
58 /* Private types -------------------------------------------------------------*/
59 /* Private variables ---------------------------------------------------------*/
60 /* Private constants ---------------------------------------------------------*/
61 /* Private macros ------------------------------------------------------------*/
62 /** @addtogroup GPIO_LL_Private_Macros
65 #define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
67 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
68 ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
69 ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
70 ((__VALUE__) == LL_GPIO_MODE_ANALOG))
72 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
73 ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
75 #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
76 ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
77 ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
78 ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
80 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
81 ((__VALUE__) == LL_GPIO_PULL_UP) ||\
82 ((__VALUE__) == LL_GPIO_PULL_DOWN))
84 #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
85 ((__VALUE__) == LL_GPIO_AF_1 ) ||\
86 ((__VALUE__) == LL_GPIO_AF_2 ) ||\
87 ((__VALUE__) == LL_GPIO_AF_3 ) ||\
88 ((__VALUE__) == LL_GPIO_AF_4 ) ||\
89 ((__VALUE__) == LL_GPIO_AF_5 ) ||\
90 ((__VALUE__) == LL_GPIO_AF_6 ) ||\
91 ((__VALUE__) == LL_GPIO_AF_7 ) ||\
92 ((__VALUE__) == LL_GPIO_AF_8 ) ||\
93 ((__VALUE__) == LL_GPIO_AF_9 ) ||\
94 ((__VALUE__) == LL_GPIO_AF_10 ) ||\
95 ((__VALUE__) == LL_GPIO_AF_11 ) ||\
96 ((__VALUE__) == LL_GPIO_AF_12 ) ||\
97 ((__VALUE__) == LL_GPIO_AF_13 ) ||\
98 ((__VALUE__) == LL_GPIO_AF_14 ) ||\
99 ((__VALUE__) == LL_GPIO_AF_15 ))
104 /* Private function prototypes -----------------------------------------------*/
106 /* Exported functions --------------------------------------------------------*/
107 /** @addtogroup GPIO_LL_Exported_Functions
111 /** @addtogroup GPIO_LL_EF_Init
116 * @brief De-initialize GPIO registers (Registers restored to their default values).
117 * @param GPIOx GPIO Port
118 * @retval An ErrorStatus enumeration value:
119 * - SUCCESS: GPIO registers are de-initialized
120 * - ERROR: Wrong GPIO Port
122 ErrorStatus
LL_GPIO_DeInit(GPIO_TypeDef
*GPIOx
)
124 ErrorStatus status
= SUCCESS
;
126 /* Check the parameters */
127 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx
));
129 /* Force and Release reset on clock of GPIOx Port */
132 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA
);
133 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA
);
135 else if (GPIOx
== GPIOB
)
137 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB
);
138 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB
);
140 else if (GPIOx
== GPIOC
)
142 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC
);
143 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC
);
146 else if (GPIOx
== GPIOD
)
148 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD
);
149 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD
);
153 else if (GPIOx
== GPIOE
)
155 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE
);
156 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE
);
160 else if (GPIOx
== GPIOF
)
162 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF
);
163 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF
);
167 else if (GPIOx
== GPIOG
)
169 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOG
);
170 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOG
);
174 else if (GPIOx
== GPIOH
)
176 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOH
);
177 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOH
);
181 else if (GPIOx
== GPIOI
)
183 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOI
);
184 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOI
);
188 else if (GPIOx
== GPIOJ
)
190 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOJ
);
191 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOJ
);
195 else if (GPIOx
== GPIOK
)
197 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOK
);
198 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOK
);
210 * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
211 * @param GPIOx GPIO Port
212 * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
213 * that contains the configuration information for the specified GPIO peripheral.
214 * @retval An ErrorStatus enumeration value:
215 * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
216 * - ERROR: Not applicable
218 ErrorStatus
LL_GPIO_Init(GPIO_TypeDef
*GPIOx
, LL_GPIO_InitTypeDef
*GPIO_InitStruct
)
220 uint32_t pinpos
= 0x00000000U
;
221 uint32_t currentpin
= 0x00000000U
;
223 /* Check the parameters */
224 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx
));
225 assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct
->Pin
));
226 assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct
->Mode
));
227 assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct
->Pull
));
229 /* ------------------------- Configure the port pins ---------------- */
230 /* Initialize pinpos on first pin set */
231 pinpos
= POSITION_VAL(GPIO_InitStruct
->Pin
);
233 /* Configure the port pins */
234 while (((GPIO_InitStruct
->Pin
) >> pinpos
) != 0x00000000U
)
236 /* Get current io position */
237 currentpin
= (GPIO_InitStruct
->Pin
) & (0x00000001U
<< pinpos
);
241 /* Pin Mode configuration */
242 LL_GPIO_SetPinMode(GPIOx
, currentpin
, GPIO_InitStruct
->Mode
);
244 if ((GPIO_InitStruct
->Mode
== LL_GPIO_MODE_OUTPUT
) || (GPIO_InitStruct
->Mode
== LL_GPIO_MODE_ALTERNATE
))
246 /* Check Speed mode parameters */
247 assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct
->Speed
));
249 /* Speed mode configuration */
250 LL_GPIO_SetPinSpeed(GPIOx
, currentpin
, GPIO_InitStruct
->Speed
);
253 /* Pull-up Pull down resistor configuration*/
254 LL_GPIO_SetPinPull(GPIOx
, currentpin
, GPIO_InitStruct
->Pull
);
256 if (GPIO_InitStruct
->Mode
== LL_GPIO_MODE_ALTERNATE
)
258 /* Check Alternate parameter */
259 assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct
->Alternate
));
261 /* Speed mode configuration */
262 if (POSITION_VAL(currentpin
) < 0x00000008U
)
264 LL_GPIO_SetAFPin_0_7(GPIOx
, currentpin
, GPIO_InitStruct
->Alternate
);
268 LL_GPIO_SetAFPin_8_15(GPIOx
, currentpin
, GPIO_InitStruct
->Alternate
);
275 if ((GPIO_InitStruct
->Mode
== LL_GPIO_MODE_OUTPUT
) || (GPIO_InitStruct
->Mode
== LL_GPIO_MODE_ALTERNATE
))
277 /* Check Output mode parameters */
278 assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct
->OutputType
));
280 /* Output mode configuration*/
281 LL_GPIO_SetPinOutputType(GPIOx
, GPIO_InitStruct
->Pin
, GPIO_InitStruct
->OutputType
);
288 * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
289 * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
290 * whose fields will be set to default values.
294 void LL_GPIO_StructInit(LL_GPIO_InitTypeDef
*GPIO_InitStruct
)
296 /* Reset GPIO init structure parameters values */
297 GPIO_InitStruct
->Pin
= LL_GPIO_PIN_ALL
;
298 GPIO_InitStruct
->Mode
= LL_GPIO_MODE_ANALOG
;
299 GPIO_InitStruct
->Speed
= LL_GPIO_SPEED_FREQ_LOW
;
300 GPIO_InitStruct
->OutputType
= LL_GPIO_OUTPUT_PUSHPULL
;
301 GPIO_InitStruct
->Pull
= LL_GPIO_PULL_NO
;
302 GPIO_InitStruct
->Alternate
= LL_GPIO_AF_0
;
317 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) */
323 #endif /* USE_FULL_LL_DRIVER */
325 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/