STM32L4xx_HAL_Driver  1.14.0
Initialization/de-initialization functions

Initialization and Configuration functions. More...

Functions

void HAL_GPIO_Init (GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
 Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init. More...
 
void HAL_GPIO_DeInit (GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
 De-initialize the GPIOx peripheral registers to their default reset values. More...
 

Detailed Description

Initialization and Configuration functions.

 ===============================================================================
              ##### Initialization and de-initialization functions #####
 ===============================================================================

Function Documentation

◆ HAL_GPIO_DeInit()

void HAL_GPIO_DeInit ( GPIO_TypeDef *  GPIOx,
uint32_t  GPIO_Pin 
)

De-initialize the GPIOx peripheral registers to their default reset values.

Parameters
GPIOxwhere x can be (A..H) to select the GPIO peripheral for STM32L4 family
GPIO_Pinspecifies the port bit to be written. This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
Return values
None

Definition at line 311 of file stm32l4xx_hal_gpio.c.

312 {
313  uint32_t position = 0x00u;
314  uint32_t iocurrent;
315  uint32_t tmp;
316 
317  /* Check the parameters */
318  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
319  assert_param(IS_GPIO_PIN(GPIO_Pin));
320 
321  /* Configure the port pins */
322  while ((GPIO_Pin >> position) != 0x00u)
323  {
324  /* Get current io position */
325  iocurrent = (GPIO_Pin) & (1uL << position);
326 
327  if (iocurrent != 0x00u)
328  {
329  /*------------------------- EXTI Mode Configuration --------------------*/
330  /* Clear the External Interrupt or Event for the current IO */
331 
332  tmp = SYSCFG->EXTICR[position >> 2u];
333  tmp &= (0x0FuL << (4u * (position & 0x03u)));
334  if (tmp == (GPIO_GET_INDEX(GPIOx) << (4u * (position & 0x03u))))
335  {
336  /* Clear EXTI line configuration */
337  EXTI->IMR1 &= ~(iocurrent);
338  EXTI->EMR1 &= ~(iocurrent);
339 
340  /* Clear Rising Falling edge configuration */
341  EXTI->RTSR1 &= ~(iocurrent);
342  EXTI->FTSR1 &= ~(iocurrent);
343 
344  tmp = 0x0FuL << (4u * (position & 0x03u));
345  SYSCFG->EXTICR[position >> 2u] &= ~tmp;
346  }
347 
348  /*------------------------- GPIO Mode Configuration --------------------*/
349  /* Configure IO in Analog Mode */
350  GPIOx->MODER |= (GPIO_MODER_MODE0 << (position * 2u));
351 
352  /* Configure the default Alternate Function in current IO */
353  GPIOx->AFR[position >> 3u] &= ~(0xFu << ((position & 0x07u) * 4u)) ;
354 
355  /* Configure the default value for IO Speed */
356  GPIOx->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2u));
357 
358  /* Configure the default value IO Output Type */
359  GPIOx->OTYPER &= ~(GPIO_OTYPER_OT0 << position) ;
360 
361  /* Deactivate the Pull-up and Pull-down resistor for the current IO */
362  GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPD0 << (position * 2u));
363 
364 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx)
365  /* Deactivate the Control bit of Analog mode for the current IO */
366  GPIOx->ASCR &= ~(GPIO_ASCR_ASC0<< position);
367 #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx */
368  }
369 
370  position++;
371  }
372 }
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_GPIO_Init()

void HAL_GPIO_Init ( GPIO_TypeDef *  GPIOx,
GPIO_InitTypeDef *  GPIO_Init 
)

Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init.

Parameters
GPIOxwhere x can be (A..H) to select the GPIO peripheral for STM32L4 family
GPIO_Initpointer to a GPIO_InitTypeDef structure that contains the configuration information for the specified GPIO peripheral.
Return values
None

Definition at line 172 of file stm32l4xx_hal_gpio.c.

173 {
174  uint32_t position = 0x00u;
175  uint32_t iocurrent;
176  uint32_t temp;
177 
178  /* Check the parameters */
179  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
180  assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
181  assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
182  assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
183 
184  /* Configure the port pins */
185  while (((GPIO_Init->Pin) >> position) != 0x00u)
186  {
187  /* Get current io position */
188  iocurrent = (GPIO_Init->Pin) & (1uL << position);
189 
190  if (iocurrent != 0x00u)
191  {
192  /*--------------------- GPIO Mode Configuration ------------------------*/
193  /* In case of Alternate function mode selection */
194  if((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
195  {
196  /* Check the Alternate function parameters */
197  assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
198  assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
199 
200  /* Configure Alternate function mapped with the current IO */
201  temp = GPIOx->AFR[position >> 3u];
202  temp &= ~(0xFu << ((position & 0x07u) * 4u));
203  temp |= ((GPIO_Init->Alternate) << ((position & 0x07u) * 4u));
204  GPIOx->AFR[position >> 3u] = temp;
205  }
206 
207  /* Configure IO Direction mode (Input, Output, Alternate or Analog) */
208  temp = GPIOx->MODER;
209  temp &= ~(GPIO_MODER_MODE0 << (position * 2u));
210  temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2u));
211  GPIOx->MODER = temp;
212 
213  /* In case of Output or Alternate function mode selection */
214  if((GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) ||
215  (GPIO_Init->Mode == GPIO_MODE_OUTPUT_OD) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
216  {
217  /* Check the Speed parameter */
218  assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
219  /* Configure the IO Speed */
220  temp = GPIOx->OSPEEDR;
221  temp &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2u));
222  temp |= (GPIO_Init->Speed << (position * 2u));
223  GPIOx->OSPEEDR = temp;
224 
225  /* Configure the IO Output Type */
226  temp = GPIOx->OTYPER;
227  temp &= ~(GPIO_OTYPER_OT0 << position) ;
228  temp |= (((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4u) << position);
229  GPIOx->OTYPER = temp;
230  }
231 
232 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx)
233 
234  /* In case of Analog mode, check if ADC control mode is selected */
235  if((GPIO_Init->Mode & GPIO_MODE_ANALOG) == GPIO_MODE_ANALOG)
236  {
237  /* Configure the IO Output Type */
238  temp = GPIOx->ASCR;
239  temp &= ~(GPIO_ASCR_ASC0 << position) ;
240  temp |= (((GPIO_Init->Mode & ANALOG_MODE) >> 3) << position);
241  GPIOx->ASCR = temp;
242  }
243 
244 #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx */
245 
246  /* Activate the Pull-up or Pull down resistor for the current IO */
247  temp = GPIOx->PUPDR;
248  temp &= ~(GPIO_PUPDR_PUPD0 << (position * 2u));
249  temp |= ((GPIO_Init->Pull) << (position * 2u));
250  GPIOx->PUPDR = temp;
251 
252  /*--------------------- EXTI Mode Configuration ------------------------*/
253  /* Configure the External Interrupt or event for the current IO */
254  if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
255  {
256  /* Enable SYSCFG Clock */
257  __HAL_RCC_SYSCFG_CLK_ENABLE();
258 
259  temp = SYSCFG->EXTICR[position >> 2u];
260  temp &= ~(0x0FuL << (4u * (position & 0x03u)));
261  temp |= (GPIO_GET_INDEX(GPIOx) << (4u * (position & 0x03u)));
262  SYSCFG->EXTICR[position >> 2u] = temp;
263 
264  /* Clear EXTI line configuration */
265  temp = EXTI->IMR1;
266  temp &= ~(iocurrent);
267  if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
268  {
269  temp |= iocurrent;
270  }
271  EXTI->IMR1 = temp;
272 
273  temp = EXTI->EMR1;
274  temp &= ~(iocurrent);
275  if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
276  {
277  temp |= iocurrent;
278  }
279  EXTI->EMR1 = temp;
280 
281  /* Clear Rising Falling edge configuration */
282  temp = EXTI->RTSR1;
283  temp &= ~(iocurrent);
284  if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
285  {
286  temp |= iocurrent;
287  }
288  EXTI->RTSR1 = temp;
289 
290  temp = EXTI->FTSR1;
291  temp &= ~(iocurrent);
292  if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
293  {
294  temp |= iocurrent;
295  }
296  EXTI->FTSR1 = temp;
297  }
298  }
299 
300  position++;
301  }
302 }
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))