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