STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_ll_gpio.c
Go to the documentation of this file.
1 
19 #if defined(USE_FULL_LL_DRIVER)
20 
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32l4xx_ll_gpio.h"
23 #include "stm32l4xx_ll_bus.h"
24 #ifdef USE_FULL_ASSERT
25 #include "stm32_assert.h"
26 #else
27 #define assert_param(expr) ((void)0U)
28 #endif
29 
34 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI)
35 
45 /* Private types -------------------------------------------------------------*/
46 /* Private variables ---------------------------------------------------------*/
47 /* Private constants ---------------------------------------------------------*/
48 /* Private macros ------------------------------------------------------------*/
52 #define IS_LL_GPIO_PIN(__VALUE__) (((0x00u) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
53 
54 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
55  ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
56  ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
57  ((__VALUE__) == LL_GPIO_MODE_ANALOG))
58 
59 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
60  ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
61 
62 #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
63  ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
64  ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
65  ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
66 
67 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
68  ((__VALUE__) == LL_GPIO_PULL_UP) ||\
69  ((__VALUE__) == LL_GPIO_PULL_DOWN))
70 
71 #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
72  ((__VALUE__) == LL_GPIO_AF_1 ) ||\
73  ((__VALUE__) == LL_GPIO_AF_2 ) ||\
74  ((__VALUE__) == LL_GPIO_AF_3 ) ||\
75  ((__VALUE__) == LL_GPIO_AF_4 ) ||\
76  ((__VALUE__) == LL_GPIO_AF_5 ) ||\
77  ((__VALUE__) == LL_GPIO_AF_6 ) ||\
78  ((__VALUE__) == LL_GPIO_AF_7 ) ||\
79  ((__VALUE__) == LL_GPIO_AF_8 ) ||\
80  ((__VALUE__) == LL_GPIO_AF_9 ) ||\
81  ((__VALUE__) == LL_GPIO_AF_10 ) ||\
82  ((__VALUE__) == LL_GPIO_AF_11 ) ||\
83  ((__VALUE__) == LL_GPIO_AF_12 ) ||\
84  ((__VALUE__) == LL_GPIO_AF_13 ) ||\
85  ((__VALUE__) == LL_GPIO_AF_14 ) ||\
86  ((__VALUE__) == LL_GPIO_AF_15 ))
87 
91 /* Private function prototypes -----------------------------------------------*/
92 
93 /* Exported functions --------------------------------------------------------*/
109 ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
110 {
111  ErrorStatus status = SUCCESS;
112 
113  /* Check the parameters */
114  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
115 
116  /* Force and Release reset on clock of GPIOx Port */
117  if (GPIOx == GPIOA)
118  {
119  LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOA);
120  LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOA);
121  }
122  else if (GPIOx == GPIOB)
123  {
124  LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOB);
125  LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOB);
126  }
127  else if (GPIOx == GPIOC)
128  {
129  LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOC);
130  LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOC);
131  }
132 #if defined(GPIOD)
133  else if (GPIOx == GPIOD)
134  {
135  LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOD);
136  LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOD);
137  }
138 #endif /* GPIOD */
139 #if defined(GPIOE)
140  else if (GPIOx == GPIOE)
141  {
142  LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOE);
143  LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOE);
144  }
145 #endif /* GPIOE */
146 #if defined(GPIOF)
147  else if (GPIOx == GPIOF)
148  {
149  LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOF);
150  LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOF);
151  }
152 #endif /* GPIOF */
153 #if defined(GPIOG)
154  else if (GPIOx == GPIOG)
155  {
156  LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOG);
157  LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOG);
158  }
159 #endif /* GPIOG */
160 #if defined(GPIOH)
161  else if (GPIOx == GPIOH)
162  {
163  LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOH);
164  LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOH);
165  }
166 #endif /* GPIOH */
167 #if defined(GPIOI)
168  else if (GPIOx == GPIOI)
169  {
170  LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOI);
171  LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOI);
172  }
173 #endif /* GPIOI */
174  else
175  {
176  status = ERROR;
177  }
178 
179  return (status);
180 }
181 
191 ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
192 {
193  uint32_t pinpos;
194  uint32_t currentpin;
195 
196  /* Check the parameters */
197  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
198  assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
199  assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
200  assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
201 
202  /* ------------------------- Configure the port pins ---------------- */
203  /* Initialize pinpos on first pin set */
204  pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
205 
206  /* Configure the port pins */
207  while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00u)
208  {
209  /* Get current io position */
210  currentpin = (GPIO_InitStruct->Pin) & (0x00000001uL << pinpos);
211 
212  if (currentpin != 0x00u)
213  {
214  /* Pin Mode configuration */
215  LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
216 
217  if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
218  {
219  /* Check Speed mode parameters */
220  assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
221 
222  /* Speed mode configuration */
223  LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
224  }
225 
226  /* Pull-up Pull down resistor configuration*/
227  LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
228 
229  if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
230  {
231  /* Check Alternate parameter */
232  assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
233 
234  /* Speed mode configuration */
235  if (currentpin < LL_GPIO_PIN_8)
236  {
237  LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
238  }
239  else
240  {
241  LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
242  }
243  }
244  }
245  pinpos++;
246  }
247 
248  if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
249  {
250  /* Check Output mode parameters */
251  assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
252 
253  /* Output mode configuration*/
254  LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
255 
256  }
257  return (SUCCESS);
258 }
259 
268 {
269  /* Reset GPIO init structure parameters values */
270  GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
271  GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
272  GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
273  GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
274  GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
275  GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
276 }
277 
290 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) */
291 
296 #endif /* USE_FULL_LL_DRIVER */
297 
298 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
De-initialize GPIO registers (Registers restored to their default values).
Header file of GPIO LL module.
LL GPIO Init Structure definition.
__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_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_AHB2_GRP1_ForceReset(uint32_t Periphs)
Force AHB2 peripherals reset. AHB2RSTR GPIOARST LL_AHB2_GRP1_ForceReset AHB2RSTR GPIOBRST LL_AHB2_G...
__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_AHB2_GRP1_ReleaseReset(uint32_t Periphs)
Release AHB2 peripherals reset. AHB2RSTR GPIOARST LL_AHB2_GRP1_ReleaseReset AHB2RSTR GPIOBRST LL_AH...
__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...
Header file of BUS LL module.
__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.
ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
Set each LL_GPIO_InitTypeDef field to default value.