STM32F4xx_HAL_Driver  1.8.3
stm32f4xx_ll_gpio.c
Go to the documentation of this file.
1 
18 #if defined(USE_FULL_LL_DRIVER)
19 
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32f4xx_ll_gpio.h"
22 #include "stm32f4xx_ll_bus.h"
23 #ifdef USE_FULL_ASSERT
24 #include "stm32_assert.h"
25 #else
26 #define assert_param(expr) ((void)0U)
27 #endif
28 
33 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK)
34 
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /* Private macros ------------------------------------------------------------*/
46 #define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
47 
48 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
49  ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
50  ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
51  ((__VALUE__) == LL_GPIO_MODE_ANALOG))
52 
53 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
54  ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
55 
56 #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
57  ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
58  ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
59  ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
60 
61 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
62  ((__VALUE__) == LL_GPIO_PULL_UP) ||\
63  ((__VALUE__) == LL_GPIO_PULL_DOWN))
64 
65 #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
66  ((__VALUE__) == LL_GPIO_AF_1 ) ||\
67  ((__VALUE__) == LL_GPIO_AF_2 ) ||\
68  ((__VALUE__) == LL_GPIO_AF_3 ) ||\
69  ((__VALUE__) == LL_GPIO_AF_4 ) ||\
70  ((__VALUE__) == LL_GPIO_AF_5 ) ||\
71  ((__VALUE__) == LL_GPIO_AF_6 ) ||\
72  ((__VALUE__) == LL_GPIO_AF_7 ) ||\
73  ((__VALUE__) == LL_GPIO_AF_8 ) ||\
74  ((__VALUE__) == LL_GPIO_AF_9 ) ||\
75  ((__VALUE__) == LL_GPIO_AF_10 ) ||\
76  ((__VALUE__) == LL_GPIO_AF_11 ) ||\
77  ((__VALUE__) == LL_GPIO_AF_12 ) ||\
78  ((__VALUE__) == LL_GPIO_AF_13 ) ||\
79  ((__VALUE__) == LL_GPIO_AF_14 ) ||\
80  ((__VALUE__) == LL_GPIO_AF_15 ))
85 /* Private function prototypes -----------------------------------------------*/
86 
87 /* Exported functions --------------------------------------------------------*/
103 ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
104 {
105  ErrorStatus status = SUCCESS;
106 
107  /* Check the parameters */
108  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
109 
110  /* Force and Release reset on clock of GPIOx Port */
111  if (GPIOx == GPIOA)
112  {
113  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA);
114  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA);
115  }
116  else if (GPIOx == GPIOB)
117  {
118  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB);
119  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB);
120  }
121  else if (GPIOx == GPIOC)
122  {
123  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC);
124  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC);
125  }
126 #if defined(GPIOD)
127  else if (GPIOx == GPIOD)
128  {
129  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD);
130  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD);
131  }
132 #endif /* GPIOD */
133 #if defined(GPIOE)
134  else if (GPIOx == GPIOE)
135  {
136  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE);
137  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE);
138  }
139 #endif /* GPIOE */
140 #if defined(GPIOF)
141  else if (GPIOx == GPIOF)
142  {
143  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF);
144  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF);
145  }
146 #endif /* GPIOF */
147 #if defined(GPIOG)
148  else if (GPIOx == GPIOG)
149  {
150  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOG);
151  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOG);
152  }
153 #endif /* GPIOG */
154 #if defined(GPIOH)
155  else if (GPIOx == GPIOH)
156  {
157  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOH);
158  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOH);
159  }
160 #endif /* GPIOH */
161 #if defined(GPIOI)
162  else if (GPIOx == GPIOI)
163  {
164  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOI);
165  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOI);
166  }
167 #endif /* GPIOI */
168 #if defined(GPIOJ)
169  else if (GPIOx == GPIOJ)
170  {
171  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOJ);
172  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOJ);
173  }
174 #endif /* GPIOJ */
175 #if defined(GPIOK)
176  else if (GPIOx == GPIOK)
177  {
178  LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOK);
179  LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOK);
180  }
181 #endif /* GPIOK */
182  else
183  {
184  status = ERROR;
185  }
186 
187  return (status);
188 }
189 
199 ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
200 {
201  uint32_t pinpos = 0x00000000U;
202  uint32_t currentpin = 0x00000000U;
203 
204  /* Check the parameters */
205  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
206  assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
207  assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
208  assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
209 
210  /* ------------------------- Configure the port pins ---------------- */
211  /* Initialize pinpos on first pin set */
212  pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
213 
214  /* Configure the port pins */
215  while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
216  {
217  /* Get current io position */
218  currentpin = (GPIO_InitStruct->Pin) & (0x00000001U << pinpos);
219 
220  if (currentpin)
221  {
222 
223  if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
224  {
225  /* Check Speed mode parameters */
226  assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
227 
228  /* Speed mode configuration */
229  LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
230 
231  /* Check Output mode parameters */
232  assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
233 
234  /* Output mode configuration*/
235  LL_GPIO_SetPinOutputType(GPIOx, currentpin, GPIO_InitStruct->OutputType);
236  }
237 
238  /* Pull-up Pull down resistor configuration*/
239  LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
240 
241  if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
242  {
243  /* Check Alternate parameter */
244  assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
245 
246  /* Speed mode configuration */
247  if (POSITION_VAL(currentpin) < 0x00000008U)
248  {
249  LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
250  }
251  else
252  {
253  LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
254  }
255  }
256 
257  /* Pin Mode configuration */
258  LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
259  }
260  pinpos++;
261  }
262 
263  return (SUCCESS);
264 }
265 
274 {
275  /* Reset GPIO init structure parameters values */
276  GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
277  GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
278  GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
279  GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
280  GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
281  GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
282 }
283 
296 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) */
297 
302 #endif /* USE_FULL_LL_DRIVER */
303 
__STATIC_INLINE void LL_AHB1_GRP1_ReleaseReset(uint32_t Periphs)
Release AHB1 peripherals reset. @rmtoll AHB1RSTR GPIOARST LL_AHB1_GRP1_ReleaseReset AHB1RSTR GPIOBRS...
__STATIC_INLINE void LL_AHB1_GRP1_ForceReset(uint32_t Periphs)
Force AHB1 peripherals reset. @rmtoll AHB1RSTR GPIOARST LL_AHB1_GRP1_ForceReset AHB1RSTR GPIOBRST LL...
ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
De-initialize GPIO registers (Registers restored to their default values).
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
Set each LL_GPIO_InitTypeDef field to default value.
ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
__STATIC_INLINE void LL_GPIO_SetPinSpeed(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Speed)
Configure gpio speed for a dedicated pin on dedicated port.
__STATIC_INLINE void LL_GPIO_SetPinOutputType(GPIO_TypeDef *GPIOx, uint32_t PinMask, uint32_t OutputType)
Configure gpio output type for several pins on dedicated port.
__STATIC_INLINE void LL_GPIO_SetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode)
Configure gpio mode for a dedicated pin on dedicated port.
__STATIC_INLINE void LL_GPIO_SetAFPin_0_7(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
Configure gpio alternate function of a dedicated pin from 0 to 7 for a dedicated port.
__STATIC_INLINE void LL_GPIO_SetPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Pull)
Configure gpio pull-up or pull-down for a dedicated pin on a dedicated port.
__STATIC_INLINE void LL_GPIO_SetAFPin_8_15(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
Configure gpio alternate function of a dedicated pin from 8 to 15 for a dedicated port.
LL GPIO Init Structure definition.
Header file of BUS LL module.
Header file of GPIO LL module.