1 /**
2   ******************************************************************************
3   * @file    stm32l5xx_hal_gpio.c
4   * @author  MCD Application Team
5   * @brief   GPIO HAL module driver.
6   *          This file provides firmware functions to manage the following
7   *          functionalities of the General Purpose Input/Output (GPIO) peripheral:
8   *           + Initialization and de-initialization functions
9   *           + IO operation functions
10   *
11   ******************************************************************************
12   * @attention
13   *
14   * Copyright (c) 2016 STMicroelectronics.
15   * All rights reserved.
16   *
17   * This software is licensed under terms that can be found in the LICENSE file
18   * in the root directory of this software component.
19   * If no LICENSE file comes with this software, it is provided AS-IS.
20   *
21   ******************************************************************************
22   @verbatim
23   ==============================================================================
24                     ##### GPIO Peripheral features #####
25   ==============================================================================
26   [..]
27     (+) Each port bit of the general-purpose I/O (GPIO) ports can be individually
28         configured by software in several modes:
29         (++) Input mode
30         (++) Analog mode
31         (++) Output mode
32         (++) Alternate function mode
33         (++) External interrupt/event lines
34 
35     (+) During and just after reset, the alternate functions and external interrupt
36         lines are not active and the I/O ports are configured in input floating mode.
37 
38     (+) All GPIO pins have weak internal pull-up and pull-down resistors, which can be
39         activated or not.
40 
41     (+) In Output or Alternate mode, each IO can be configured on open-drain or push-pull
42         type and the IO speed can be selected depending on the VDD value.
43 
44     (+) The microcontroller IO pins are connected to onboard peripherals/modules through a
45         multiplexer that allows only one peripheral alternate function (AF) connected
46        to an IO pin at a time. In this way, there can be no conflict between peripherals
47        sharing the same IO pin.
48 
49     (+) All ports have external interrupt/event capability. To use external interrupt
50         lines, the port must be configured in input mode. All available GPIO pins are
51         connected to the 16 external interrupt/event lines from EXTI0 to EXTI15.
52 
53     (+) The external interrupt/event controller consists of up to 39 edge detectors
54         (16 lines are connected to GPIO) for generating event/interrupt requests (each
55         input line can be independently configured to select the type (interrupt or event)
56         and the corresponding trigger event (rising or falling or both). Each line can
57         also be masked independently.
58 
59                      ##### How to use this driver #####
60   ==============================================================================
61   [..]
62     (#) Enable the GPIO AHB clock using the following function: __HAL_RCC_GPIOx_CLK_ENABLE().
63 
64     (#) Configure the GPIO pin(s) using HAL_GPIO_Init().
65         (++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure
66         (++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef
67              structure.
68         (++) In case of Output or alternate function mode selection: the speed is
69              configured through "Speed" member from GPIO_InitTypeDef structure.
70         (++) In alternate mode is selection, the alternate function connected to the IO
71              is configured through "Alternate" member from GPIO_InitTypeDef structure.
72         (++) Analog mode is required when a pin is to be used as ADC channel
73              or DAC output.
74         (++) In case of external interrupt/event selection the "Mode" member from
75              GPIO_InitTypeDef structure select the type (interrupt or event) and
76              the corresponding trigger event (rising or falling or both).
77 
78     (#) In case of external interrupt/event mode selection, configure NVIC IRQ priority
79         mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using
80         HAL_NVIC_EnableIRQ().
81 
82     (#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin().
83 
84     (#) To set/reset the level of a pin configured in output mode use
85         HAL_GPIO_WritePin()/HAL_GPIO_TogglePin().
86 
87    (#) To lock pin configuration until next reset use HAL_GPIO_LockPin().
88 
89     (#) During and just after reset, the alternate functions are not
90         active and the GPIO pins are configured in input floating mode (except JTAG
91         pins).
92 
93     (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose
94         (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has
95         priority over the GPIO function.
96 
97     (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as
98         general purpose PH0 and PH1, respectively, when the HSE oscillator is off.
99         The HSE has priority over the GPIO function.
100 
101   @endverbatim
102   ******************************************************************************
103   */
104 
105 /* Includes ------------------------------------------------------------------*/
106 #include "stm32l5xx_hal.h"
107 
108 /** @addtogroup STM32L5xx_HAL_Driver
109   * @{
110   */
111 
112 /** @addtogroup GPIO
113   * @{
114   */
115 
116 #ifdef HAL_GPIO_MODULE_ENABLED
117 
118 /* Private typedef -----------------------------------------------------------*/
119 /* Private defines -----------------------------------------------------------*/
120 /** @addtogroup GPIO_Private_Defines GPIO Private Defines
121   * @{
122   */
123 #define GPIO_NUMBER           (16U)
124 /**
125   * @}
126   */
127 
128 /* Private macros ------------------------------------------------------------*/
129 /* Private variables ---------------------------------------------------------*/
130 /* Private function prototypes -----------------------------------------------*/
131 /* Exported functions --------------------------------------------------------*/
132 
133 /** @addtogroup GPIO_Exported_Functions
134   * @{
135   */
136 
137 /** @addtogroup GPIO_Exported_Functions_Group1
138   *  @brief    Initialization and Configuration functions
139   *
140 @verbatim
141  ===============================================================================
142               ##### Initialization and de-initialization functions #####
143  ===============================================================================
144 
145 @endverbatim
146   * @{
147   */
148 
149 /**
150   * @brief  Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init.
151   * @note   If GPIOx peripheral pin is used in EXTI_MODE and the pin is secure in case
152   *         the system implements the security (TZEN=1), it is up to the secure application to
153   *         insure that the corresponding EXTI line is set secure.
154   * @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L5 family
155   * @param  GPIO_Init pointer to a GPIO_InitTypeDef structure that contains
156   *         the configuration information for the specified GPIO peripheral.
157   * @retval None
158   */
HAL_GPIO_Init(GPIO_TypeDef * GPIOx,GPIO_InitTypeDef * GPIO_Init)159 void HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init)
160 {
161   uint32_t position = 0U;
162   uint32_t iocurrent;
163   uint32_t temp;
164 
165   /* Check the parameters */
166   assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
167   assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
168   assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
169 
170   /* Configure the port pins */
171   while (((GPIO_Init->Pin) >> position) != 0U)
172   {
173     /* Get current io position */
174     iocurrent = (GPIO_Init->Pin) & (1UL << position);
175 
176     if (iocurrent != 0U)
177     {
178       /*--------------------- GPIO Mode Configuration ------------------------*/
179       /* In case of Output or Alternate function mode selection */
180       if (((GPIO_Init->Mode & GPIO_MODE) == MODE_OUTPUT) || ((GPIO_Init->Mode & GPIO_MODE) == MODE_AF))
181       {
182         /* Check the Speed parameter */
183         assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
184 
185         /* Configure the IO Speed */
186         temp = GPIOx->OSPEEDR;
187         temp &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2U));
188         temp |= (GPIO_Init->Speed << (position * 2U));
189         GPIOx->OSPEEDR = temp;
190 
191         /* Configure the IO Output Type */
192         temp = GPIOx->OTYPER;
193         temp &= ~(GPIO_OTYPER_OT0 << position) ;
194         temp |= (((GPIO_Init->Mode & OUTPUT_TYPE) >> OUTPUT_TYPE_Pos) << position);
195         GPIOx->OTYPER = temp;
196       }
197 
198       /* Activate the Pull-up or Pull down resistor for the current IO */
199       if ((GPIO_Init->Mode & GPIO_MODE) != MODE_ANALOG)
200       {
201         /* Check the Pull parameter */
202         assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
203 
204         temp = GPIOx->PUPDR;
205         temp &= ~(GPIO_PUPDR_PUPD0 << (position * 2U));
206         temp |= ((GPIO_Init->Pull) << (position * 2U));
207         GPIOx->PUPDR = temp;
208       }
209 
210       /* In case of Alternate function mode selection */
211       if ((GPIO_Init->Mode & GPIO_MODE) == MODE_AF)
212       {
213         /* Check the Alternate function parameters */
214         assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
215         assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
216 
217         /* Configure Alternate function mapped with the current IO */
218         temp = GPIOx->AFR[position >> 3U];
219         temp &= ~(0x0FUL << ((position & 0x07U) * 4U)) ;
220         temp |= ((GPIO_Init->Alternate) << ((position & 0x07U) * 4U));
221         GPIOx->AFR[position >> 3U] = temp;
222       }
223 
224       /* Configure IO Direction mode (Input, Output, Alternate or Analog) */
225       temp = GPIOx->MODER;
226       temp &= ~(GPIO_MODER_MODE0 << (position * 2U));
227       temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2U));
228       GPIOx->MODER = temp;
229 
230       /*--------------------- EXTI Mode Configuration ------------------------*/
231       /* Configure the External Interrupt or event for the current IO */
232       if ((GPIO_Init->Mode & EXTI_MODE) != 0x00u)
233       {
234         temp = EXTI->EXTICR[position >> 2U];
235         temp &= ~((0x0FU) << (8U * (position & 0x03U)));
236         temp |= (GPIO_GET_INDEX(GPIOx) << (8U * (position & 0x03U)));
237         EXTI->EXTICR[position >> 2U] = temp;
238 
239         /* Clear Rising Falling edge configuration */
240         temp = EXTI->RTSR1;
241         temp &= ~(iocurrent);
242         if ((GPIO_Init->Mode & TRIGGER_RISING) != 0x00u)
243         {
244           temp |= iocurrent;
245         }
246         EXTI->RTSR1 = temp;
247 
248         temp = EXTI->FTSR1;
249         temp &= ~(iocurrent);
250         if ((GPIO_Init->Mode & TRIGGER_FALLING) != 0x00u)
251         {
252           temp |= iocurrent;
253         }
254         EXTI->FTSR1 = temp;
255 
256         /* Clear EXTI line configuration */
257         temp = EXTI->EMR1;
258         temp &= ~(iocurrent);
259         if ((GPIO_Init->Mode & EXTI_EVT) != 0x00u)
260         {
261           temp |= iocurrent;
262         }
263         EXTI->EMR1 = temp;
264 
265         temp = EXTI->IMR1;
266         temp &= ~(iocurrent);
267         if ((GPIO_Init->Mode & EXTI_IT) != 0x00u)
268         {
269           temp |= iocurrent;
270         }
271         EXTI->IMR1 = temp;
272       }
273     }
274 
275     position++;
276   }
277 }
278 
279 /**
280   * @brief  De-initialize the GPIOx peripheral registers to their default reset values.
281   * @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L5 family
282   * @param  GPIO_Pin specifies the port bit to be written.
283   *         This parameter can be one of GPIO_PIN_x where x can be (0..15).
284   * @retval None
285   */
HAL_GPIO_DeInit(GPIO_TypeDef * GPIOx,uint32_t GPIO_Pin)286 void HAL_GPIO_DeInit(GPIO_TypeDef  *GPIOx, uint32_t GPIO_Pin)
287 {
288   uint32_t position = 0U;
289   uint32_t iocurrent;
290   uint32_t temp;
291 
292   /* Check the parameters */
293   assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
294   assert_param(IS_GPIO_PIN(GPIO_Pin));
295 
296   /* Configure the port pins */
297   while ((GPIO_Pin >> position) != 0U)
298   {
299     /* Get current io position */
300     iocurrent = (GPIO_Pin) & (1UL << position);
301 
302     if (iocurrent != 0U)
303     {
304       /*------------------------- EXTI Mode Configuration --------------------*/
305       /* Clear the External Interrupt or Event for the current IO */
306 
307       temp = EXTI->EXTICR[position >> 2U];
308       temp &= ((0x0FUL) << (8U * (position & 0x03U)));
309       if (temp == (GPIO_GET_INDEX(GPIOx) << (8U * (position & 0x03U))))
310       {
311         /* Clear EXTI line configuration */
312         EXTI->IMR1 &= ~(iocurrent);
313         EXTI->EMR1 &= ~(iocurrent);
314 
315         /* Clear Rising Falling edge configuration */
316         EXTI->FTSR1 &= ~(iocurrent);
317         EXTI->RTSR1 &= ~(iocurrent);
318 
319         temp = (0x0FUL) << (8U * (position & 0x03U));
320         EXTI->EXTICR[position >> 2U] &= ~temp;
321       }
322 
323       /*------------------------- GPIO Mode Configuration --------------------*/
324       /* Configure IO in Analog Mode */
325       GPIOx->MODER |= (GPIO_MODER_MODE0 << (position * 2U));
326 
327       /* Configure the default Alternate Function in current IO */
328       GPIOx->AFR[position >> 3U] &= ~(0x0FUL << ((position & 0x07U) * 4U)) ;
329 
330       /* Configure the default value for IO Speed */
331       GPIOx->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2U));
332 
333       /* Configure the default value IO Output Type */
334       GPIOx->OTYPER  &= ~(GPIO_OTYPER_OT0 << position) ;
335 
336       /* Deactivate the Pull-up and Pull-down resistor for the current IO */
337       GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPD0 << (position * 2U));
338     }
339 
340     position++;
341   }
342 }
343 
344 /**
345   * @}
346   */
347 
348 /** @addtogroup GPIO_Exported_Functions_Group2
349   *  @brief GPIO Read, Write, Toggle, Lock and EXTI management functions.
350   *
351 @verbatim
352  ===============================================================================
353                        ##### IO operation functions #####
354  ===============================================================================
355 
356 @endverbatim
357   * @{
358   */
359 
360 /**
361   * @brief  Read the specified input port pin.
362   * @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L5 family
363   * @param  GPIO_Pin specifies the port bit to read.
364   *         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
365   * @retval The input port pin value.
366   */
HAL_GPIO_ReadPin(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)367 GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
368 {
369   GPIO_PinState bitstatus;
370 
371   /* Check the parameters */
372   assert_param(IS_GPIO_PIN(GPIO_Pin));
373 
374   if ((GPIOx->IDR & GPIO_Pin) != 0U)
375   {
376     bitstatus = GPIO_PIN_SET;
377   }
378   else
379   {
380     bitstatus = GPIO_PIN_RESET;
381   }
382   return bitstatus;
383 }
384 
385 /**
386   * @brief  Set or clear the selected data port bit.
387   *
388   * @note   This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify
389   *         accesses. In this way, there is no risk of an IRQ occurring between
390   *         the read and the modify access.
391   *
392   * @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L5 family
393   * @param  GPIO_Pin specifies the port bit to be written.
394   *         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
395   * @param  PinState specifies the value to be written to the selected bit.
396   *         This parameter can be one of the GPIO_PinState enum values:
397   *            @arg GPIO_PIN_RESET: to clear the port pin
398   *            @arg GPIO_PIN_SET: to set the port pin
399   * @retval None
400   */
HAL_GPIO_WritePin(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin,GPIO_PinState PinState)401 void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
402 {
403   /* Check the parameters */
404   assert_param(IS_GPIO_PIN(GPIO_Pin));
405   assert_param(IS_GPIO_PIN_ACTION(PinState));
406 
407   if (PinState != GPIO_PIN_RESET)
408   {
409     GPIOx->BSRR = (uint32_t)GPIO_Pin;
410   }
411   else
412   {
413     GPIOx->BRR = (uint32_t)GPIO_Pin;
414   }
415 }
416 
417 /**
418   * @brief  Toggle the specified GPIO pin.
419   * @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L5 family
420   * @param  GPIO_Pin specifies the pin to be toggled.
421   *         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
422   * @retval None
423   */
HAL_GPIO_TogglePin(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)424 void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
425 {
426   uint32_t odr;
427 
428   /* Check the parameters */
429   assert_param(IS_GPIO_PIN(GPIO_Pin));
430 
431   /* get current Output Data Register value */
432   odr = GPIOx->ODR;
433 
434   /* Set selected pins that were at low level, and reset ones that were high */
435   GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin);
436 }
437 
438 /**
439   * @brief  Lock GPIO Pins configuration registers.
440   * @note   The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
441   *         GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
442   * @note   The configuration of the locked GPIO pins can no longer be modified
443   *         until the next reset.
444   * @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L5 family
445   * @param  GPIO_Pin specifies the port bits to be locked.
446   *         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
447   * @retval None
448   */
HAL_GPIO_LockPin(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)449 HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
450 {
451   __IO uint32_t temp = GPIO_LCKR_LCKK;
452 
453   /* Check the parameters */
454   assert_param(IS_GPIO_LOCK_INSTANCE(GPIOx));
455   assert_param(IS_GPIO_PIN(GPIO_Pin));
456 
457   /* Apply lock key write sequence */
458   temp |= GPIO_Pin;
459   /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
460   GPIOx->LCKR = temp;
461   /* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */
462   GPIOx->LCKR = GPIO_Pin;
463   /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
464   GPIOx->LCKR = temp;
465   /* Read LCKK register. This read is mandatory to complete key lock sequence */
466   temp = GPIOx->LCKR;
467 
468   /* read again in order to confirm lock is active */
469   if ((GPIOx->LCKR & GPIO_LCKR_LCKK) != 0U)
470   {
471     return HAL_OK;
472   }
473   else
474   {
475     return HAL_ERROR;
476   }
477 }
478 
479 /**
480   * @brief  Handle EXTI interrupt request.
481   * @param  GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
482   * @retval None
483   */
HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)484 void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
485 {
486   /* EXTI line interrupt detected */
487   if (__HAL_GPIO_EXTI_GET_RISING_IT(GPIO_Pin) != 0U)
488   {
489     __HAL_GPIO_EXTI_CLEAR_RISING_IT(GPIO_Pin);
490     HAL_GPIO_EXTI_Rising_Callback(GPIO_Pin);
491   }
492 
493   if (__HAL_GPIO_EXTI_GET_FALLING_IT(GPIO_Pin) != 0U)
494   {
495     __HAL_GPIO_EXTI_CLEAR_FALLING_IT(GPIO_Pin);
496     HAL_GPIO_EXTI_Falling_Callback(GPIO_Pin);
497   }
498 }
499 
500 /**
501   * @brief  EXTI line rising detection callback.
502   * @param  GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
503   * @retval None
504   */
HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)505 __weak void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
506 {
507   /* Prevent unused argument(s) compilation warning */
508   UNUSED(GPIO_Pin);
509 
510   /* NOTE: This function should not be modified, when the callback is needed,
511            the HAL_GPIO_EXTI_Rising_Callback could be implemented in the user file
512    */
513 }
514 
515 /**
516   * @brief  EXTI line falling detection callback.
517   * @param  GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
518   * @retval None
519   */
HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)520 __weak void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
521 {
522   /* Prevent unused argument(s) compilation warning */
523   UNUSED(GPIO_Pin);
524 
525   /* NOTE: This function should not be modified, when the callback is needed,
526            the HAL_GPIO_EXTI_Falling_Callback could be implemented in the user file
527    */
528 }
529 
530 /**
531   * @}
532   */
533 
534 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
535 
536 /** @defgroup GPIO_Exported_Functions_Group3 IO attributes management functions
537   *  @brief GPIO attributes management functions.
538   *
539 @verbatim
540  ===============================================================================
541                        ##### IO attributes functions #####
542  ===============================================================================
543 
544 @endverbatim
545   * @{
546   */
547 
548 /**
549   * @brief  Configure the GPIO pins attributes.
550   * @note   Available attributes are to secure GPIO pin(s), so this function is
551   *         only available in secure
552   * @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L5 family
553   * @param  GPIO_Pin specifies the pin(s) to configure the secure attribute
554   * @param  PinAttributes specifies the pin(s) to be set in secure mode, other being set non secured.
555   * @retval None
556   */
HAL_GPIO_ConfigPinAttributes(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin,uint32_t PinAttributes)557 void HAL_GPIO_ConfigPinAttributes(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t PinAttributes)
558 {
559   uint32_t position = 0U;
560   uint32_t iocurrent;
561   uint32_t temp;
562 
563   /* Check the parameters */
564   assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
565   assert_param(IS_GPIO_PIN(GPIO_Pin));
566   assert_param(IS_GPIO_PIN_ATTRIBUTES(PinAttributes));
567 
568   temp = GPIOx->SECCFGR;
569 
570   /* Configure the port pins */
571   while ((GPIO_Pin >> position) != 0U)
572   {
573     /* Get current io position */
574     iocurrent = GPIO_Pin & (1UL << position);
575 
576     if (iocurrent != 0U)
577     {
578       /* Configure the IO secure attribute */
579       temp &= ~(GPIO_SECCFGR_SEC0 << position) ;
580       temp |= (PinAttributes << position);
581     }
582     position++;
583   }
584 
585   /* Set secure attributes */
586   GPIOx->SECCFGR = temp;
587 }
588 
589 /**
590   * @brief  Get the GPIO pins attributes.
591   * @note   Available attributes are to secure GPIO pin(s), so this function is
592   *         only available in secure
593   * @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L5 family
594   * @param  GPIO_Pin specifies the single pin to get the secure attribute from
595   * @param  pPinAttributes pointer to return the pin attributes.
596   * @retval HAL Status.
597   */
HAL_GPIO_GetConfigPinAttributes(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin,uint32_t * pPinAttributes)598 HAL_StatusTypeDef HAL_GPIO_GetConfigPinAttributes(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t *pPinAttributes)
599 {
600   uint32_t position = 0U;
601   uint32_t iocurrent;
602 
603   /* Check null pointer */
604   if (pPinAttributes == NULL)
605   {
606     return HAL_ERROR;
607   }
608 
609   /* Check the parameters */
610   assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
611   assert_param(IS_GPIO_PIN(GPIO_Pin) && (GPIO_Pin != GPIO_PIN_All));
612 
613   /* Get secure attribute of the port pin */
614   while ((GPIO_Pin >> position) != 0U)
615   {
616     /* Get current io position */
617     iocurrent = GPIO_Pin & (1UL << position);
618 
619     if (iocurrent != 0U)
620     {
621       /* Get the IO secure attribute */
622       if ((GPIOx->SECCFGR & (GPIO_SECCFGR_SEC0 << position)) != 0U)
623       {
624         *pPinAttributes = GPIO_PIN_SEC;
625       }
626       else
627       {
628         *pPinAttributes = GPIO_PIN_NSEC;
629       }
630 
631       break;
632     }
633     position++;
634   }
635 
636   return HAL_OK;
637 }
638 
639 /**
640   * @}
641   */
642 
643 #endif /* __ARM_FEATURE_CMSE */
644 
645 
646 /**
647   * @}
648   */
649 
650 #endif /* HAL_GPIO_MODULE_ENABLED */
651 /**
652   * @}
653   */
654 
655 /**
656   * @}
657   */
658 
659