1 /**
2 ******************************************************************************
3 * @file stm32wbaxx_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) 2022 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 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 When interrupt occurs,
82 (+) HAL_GPIO_EXTI_Rising_Callback() user callbacks will be executed :
83 (++) on rising edge detection.
84 (+) HAL_GPIO_EXTI_Rising_Callback() user callbacks will be executed :
85 (++) on falling edge detection.
86
87 (#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin().
88
89 (#) To set/reset the level of a pin configured in output mode use
90 HAL_GPIO_WritePin()/HAL_GPIO_TogglePin().
91
92 (#) To set the level of several pins and reset level of several other pins in
93 same cycle, use HAL_GPIO_WriteMultipleStatePin().
94
95 (#) To lock pin configuration until next reset use HAL_GPIO_LockPin().
96
97 (#) During and just after reset, the alternate functions are not
98 active and the GPIO pins are configured in input floating mode (except JTAG
99 pins).
100
101 (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose
102 (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has
103 priority over the GPIO function.
104
105 @endverbatim
106 */
107
108 /* Includes ------------------------------------------------------------------*/
109 #include "stm32wbaxx_hal.h"
110
111 /** @addtogroup STM32WBAxx_HAL_Driver
112 * @{
113 */
114
115 /** @addtogroup GPIO
116 * @{
117 */
118 /** MISRA C:2012 deviation rule has been granted for following rules:
119 * Rule-12.2 - Medium: RHS argument is in interval [0,INF] which is out of
120 * range of the shift operator in following API :
121 * HAL_GPIO_Init
122 * HAL_GPIO_DeInit
123 */
124
125 #ifdef HAL_GPIO_MODULE_ENABLED
126
127 /* Private typedef -----------------------------------------------------------*/
128 /* Private defines ------------------------------------------------------------*/
129 /** @addtogroup GPIO_Private_Constants
130 * @{
131 */
132 #define GPIO_NUMBER (16u)
133 /**
134 * @}
135 */
136
137 /* Private macros ------------------------------------------------------------*/
138 /* Private variables ---------------------------------------------------------*/
139 /* Private function prototypes -----------------------------------------------*/
140 /* Exported functions --------------------------------------------------------*/
141
142 /** @addtogroup GPIO_Exported_Functions
143 * @{
144 */
145
146 /** @addtogroup GPIO_Exported_Functions_Group1
147 * @brief Initialization and Configuration functions
148 *
149 @verbatim
150 ===============================================================================
151 ##### Initialization and de-initialization functions #####
152 ===============================================================================
153
154 @endverbatim
155 * @{
156 */
157
158 /**
159 * @brief Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init.
160 * @note If GPIOx peripheral pin is used in EXTI_MODE and the pin is secure in case
161 * the system implements the security (TZEN=1), it is up to the secure application to
162 * insure that the corresponding EXTI line is set secure.
163 * @param GPIOx where x can be (A..C, H).
164 * @param GPIO_Init pointer to a GPIO_InitTypeDef structure that contains
165 * the configuration information for the specified GPIO peripheral.
166 * @retval None
167 */
HAL_GPIO_Init(GPIO_TypeDef * GPIOx,const GPIO_InitTypeDef * GPIO_Init)168 void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, const GPIO_InitTypeDef *GPIO_Init)
169 {
170 uint32_t position = 0x00u;
171 uint32_t iocurrent;
172 uint32_t temp;
173
174 /* Check the parameters */
175 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
176 assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
177 assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
178
179 /* Configure the port pins */
180 while (((GPIO_Init->Pin) >> position) != 0x00u)
181 {
182 /* Get current io position */
183 iocurrent = (GPIO_Init->Pin) & (1uL << position);
184
185 if (iocurrent != 0x00u)
186 {
187 /*--------------------- GPIO Mode Configuration ------------------------*/
188 /* In case of Output or Alternate function mode selection */
189 if (((GPIO_Init->Mode & GPIO_MODE) == MODE_OUTPUT) || ((GPIO_Init->Mode & GPIO_MODE) == MODE_AF))
190 {
191 /* Check the Speed parameter */
192 assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
193
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 & OUTPUT_TYPE) >> OUTPUT_TYPE_Pos) << position);
204 GPIOx->OTYPER = temp;
205 }
206
207 if ((GPIO_Init->Mode & GPIO_MODE) != MODE_ANALOG)
208 {
209 /* Check the Pull parameter */
210 assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
211
212 /* Activate the Pull-up or Pull down resistor for the current IO */
213 temp = GPIOx->PUPDR;
214 temp &= ~(GPIO_PUPDR_PUPD0 << (position * 2u));
215 temp |= ((GPIO_Init->Pull) << (position * 2u));
216 GPIOx->PUPDR = temp;
217 }
218
219 /* In case of Alternate function mode selection */
220 if ((GPIO_Init->Mode & GPIO_MODE) == MODE_AF)
221 {
222 /* Check the Alternate function parameters */
223 assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
224 assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
225
226 /* Configure Alternate function mapped with the current IO */
227 temp = GPIOx->AFR[position >> 3u];
228 temp &= ~(0xFu << ((position & 0x07u) * 4u));
229 temp |= ((GPIO_Init->Alternate) << ((position & 0x07u) * 4u));
230 GPIOx->AFR[position >> 3u] = temp;
231 }
232
233 /* Configure IO Direction mode (Input, Output, Alternate or Analog) */
234 temp = GPIOx->MODER;
235 temp &= ~(GPIO_MODER_MODE0 << (position * 2u));
236 temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2u));
237 GPIOx->MODER = temp;
238
239 /*--------------------- EXTI Mode Configuration ------------------------*/
240 /* Configure the External Interrupt or event for the current IO */
241 if ((GPIO_Init->Mode & EXTI_MODE) != 0x00u)
242 {
243 temp = EXTI->EXTICR[position >> 2u];
244 temp &= ~(0x0FuL << (8u * (position & 0x03u)));
245 temp |= (GPIO_GET_INDEX(GPIOx) << (8u * (position & 0x03u)));
246 EXTI->EXTICR[position >> 2u] = temp;
247
248 /* Clear Rising Falling edge configuration */
249 temp = EXTI->RTSR1;
250 temp &= ~(iocurrent);
251 if ((GPIO_Init->Mode & TRIGGER_RISING) != 0x00u)
252 {
253 temp |= iocurrent;
254 }
255 EXTI->RTSR1 = temp;
256
257 temp = EXTI->FTSR1;
258 temp &= ~(iocurrent);
259 if ((GPIO_Init->Mode & TRIGGER_FALLING) != 0x00u)
260 {
261 temp |= iocurrent;
262 }
263 EXTI->FTSR1 = temp;
264
265 /* Clear EXTI line configuration */
266 temp = EXTI->EMR1;
267 temp &= ~(iocurrent);
268 if ((GPIO_Init->Mode & EXTI_EVT) != 0x00u)
269 {
270 temp |= iocurrent;
271 }
272 EXTI->EMR1 = temp;
273
274 temp = EXTI->IMR1;
275 temp &= ~(iocurrent);
276 if ((GPIO_Init->Mode & EXTI_IT) != 0x00u)
277 {
278 temp |= iocurrent;
279 }
280 EXTI->IMR1 = temp;
281 }
282 }
283
284 position++;
285 }
286 }
287
288 /**
289 * @brief De-initialize the GPIOx peripheral registers to their default reset values.
290 * @param GPIOx where x can be (A..C, H).
291 * @param GPIO_Pin specifies the port bit to be written.
292 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
293 * @retval None
294 */
HAL_GPIO_DeInit(GPIO_TypeDef * GPIOx,uint32_t GPIO_Pin)295 void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
296 {
297 uint32_t position = 0x00u;
298 uint32_t iocurrent;
299 uint32_t tmp;
300
301 /* Check the parameters */
302 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
303 assert_param(IS_GPIO_PIN(GPIO_Pin));
304
305 /* Configure the port pins */
306 while ((GPIO_Pin >> position) != 0x00u)
307 {
308 /* Get current io position */
309 iocurrent = (GPIO_Pin) & (1uL << position);
310
311 if (iocurrent != 0x00u)
312 {
313 /*------------------------- EXTI Mode Configuration --------------------*/
314 /* Clear the External Interrupt or Event for the current IO */
315
316 tmp = EXTI->EXTICR[position >> 2u];
317 tmp &= (0x0FuL << (8u * (position & 0x03u)));
318 if (tmp == (GPIO_GET_INDEX(GPIOx) << (8u * (position & 0x03u))))
319 {
320 /* Clear EXTI line configuration */
321 EXTI->IMR1 &= ~(iocurrent);
322 EXTI->EMR1 &= ~(iocurrent);
323
324 /* Clear Rising Falling edge configuration */
325 EXTI->FTSR1 &= ~(iocurrent);
326 EXTI->RTSR1 &= ~(iocurrent);
327
328 tmp = 0x0FuL << (8u * (position & 0x03u));
329 EXTI->EXTICR[position >> 2u] &= ~tmp;
330 }
331
332 /*------------------------- GPIO Mode Configuration --------------------*/
333 /* Configure IO in Analog Mode */
334 GPIOx->MODER |= (GPIO_MODER_MODE0 << (position * 2u));
335
336 /* Configure the default Alternate Function in current IO */
337 GPIOx->AFR[position >> 3u] &= ~(0xFu << ((position & 0x07u) * 4u)) ;
338
339 /* Configure the default value for IO Speed */
340 GPIOx->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2u));
341
342 /* Configure the default value IO Output Type */
343 GPIOx->OTYPER &= ~(GPIO_OTYPER_OT0 << position) ;
344
345 /* Deactivate the Pull-up and Pull-down resistor for the current IO */
346 GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPD0 << (position * 2u));
347 }
348
349 position++;
350 }
351 }
352
353 /**
354 * @}
355 */
356
357 /** @addtogroup GPIO_Exported_Functions_Group2
358 * @brief GPIO Read, Write, Toggle, Lock and EXTI management functions.
359 *
360 @verbatim
361 ===============================================================================
362 ##### IO operation functions #####
363 ===============================================================================
364
365 @endverbatim
366 * @{
367 */
368
369 /**
370 * @brief Read the specified input port pin.
371 * @param GPIOx where x can be (A..C, H).
372 * @param GPIO_Pin specifies the port bit to read.
373 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
374 * @retval The input port pin value.
375 */
HAL_GPIO_ReadPin(const GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)376 GPIO_PinState HAL_GPIO_ReadPin(const GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
377 {
378 GPIO_PinState bitstatus;
379
380 /* Check the parameters */
381 assert_param(IS_GPIO_PIN(GPIO_Pin));
382
383 if ((GPIOx->IDR & GPIO_Pin) != 0x00u)
384 {
385 bitstatus = GPIO_PIN_SET;
386 }
387 else
388 {
389 bitstatus = GPIO_PIN_RESET;
390 }
391 return bitstatus;
392 }
393
394 /**
395 * @brief Set or clear the selected data port bit.
396 * @note This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify
397 * accesses. In this way, there is no risk of an IRQ occurring between
398 * the read and the modify access.
399 * @param GPIOx where x can be (A..C, H).
400 * @param GPIO_Pin specifies the port bit to be written.
401 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
402 * @param PinState specifies the value to be written to the selected bit.
403 * This parameter can be one of the GPIO_PinState enum values:
404 * @arg GPIO_PIN_RESET: to clear the port pin
405 * @arg GPIO_PIN_SET: to set the port pin
406 * @retval None
407 */
HAL_GPIO_WritePin(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin,GPIO_PinState PinState)408 void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
409 {
410 /* Check the parameters */
411 assert_param(IS_GPIO_PIN(GPIO_Pin));
412 assert_param(IS_GPIO_PIN_ACTION(PinState));
413
414 if (PinState != GPIO_PIN_RESET)
415 {
416 GPIOx->BSRR = (uint32_t)GPIO_Pin;
417 }
418 else
419 {
420 GPIOx->BRR = (uint32_t)GPIO_Pin;
421 }
422 }
423
424 /**
425 * @brief Set and clear several pins of a dedicated port in same cycle.
426 * @param GPIOx where x can be (A..C, H).
427 * @param PinReset specifies the port bits to be reset
428 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15) or zero.
429 * @param PinSet specifies the port bits to be set
430 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15) or zero.
431 * @note Both PinReset and PinSet combinations shall not get any common bit, else
432 * assert would be triggered.
433 * @note At least one of the two parameters used to set or reset shall be different from zero.
434 * @retval None
435 */
HAL_GPIO_WriteMultipleStatePin(GPIO_TypeDef * GPIOx,uint16_t PinReset,uint16_t PinSet)436 void HAL_GPIO_WriteMultipleStatePin(GPIO_TypeDef *GPIOx, uint16_t PinReset, uint16_t PinSet)
437 {
438 uint32_t tmp;
439
440 /* Check the parameters */
441 /* Make sure at least one parameter is different from zero and that there is no common pin */
442 assert_param(IS_GPIO_PIN((uint32_t)PinReset | (uint32_t)PinSet));
443 assert_param(IS_GPIO_COMMON_PIN(PinReset, PinSet));
444
445 tmp = (((uint32_t)PinReset << 16) | PinSet);
446 GPIOx->BSRR = tmp;
447 }
448
449 /**
450 * @brief Toggle the specified GPIO pin.
451 * @param GPIOx where x can be (A..C, H).
452 * @param GPIO_Pin specifies the pin to be toggled.
453 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
454 * @retval None
455 */
HAL_GPIO_TogglePin(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)456 void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
457 {
458 uint32_t odr;
459
460 /* Check the parameters */
461 assert_param(IS_GPIO_PIN(GPIO_Pin));
462
463 /* get current Output Data Register value */
464 odr = GPIOx->ODR;
465
466 /* Set selected pins that were at low level, and reset ones that were high */
467 GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin);
468 }
469
470 /**
471 * @brief Lock GPIO Pins configuration registers.
472 * @note The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
473 * GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
474 * @note The configuration of the locked GPIO pins can no longer be modified
475 * until the next reset.
476 * @param GPIOx where x can be (A..C, H).
477 * @param GPIO_Pin specifies the port bits to be locked.
478 * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
479 * @retval None
480 */
HAL_GPIO_LockPin(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)481 HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
482 {
483 __IO uint32_t tmp = GPIO_LCKR_LCKK;
484
485 /* Check the parameters */
486 assert_param(IS_GPIO_LOCK_INSTANCE(GPIOx));
487 assert_param(IS_GPIO_PIN(GPIO_Pin));
488
489 /* Apply lock key write sequence */
490 tmp |= GPIO_Pin;
491 /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
492 GPIOx->LCKR = tmp;
493 /* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */
494 GPIOx->LCKR = GPIO_Pin;
495 /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
496 GPIOx->LCKR = tmp;
497 /* Read LCKK register. This read is mandatory to complete key lock sequence */
498 tmp = GPIOx->LCKR;
499
500 /* read again in order to confirm lock is active */
501 if ((GPIOx->LCKR & GPIO_LCKR_LCKK) != 0x00u)
502 {
503 return HAL_OK;
504 }
505 else
506 {
507 return HAL_ERROR;
508 }
509 }
510
511 /**
512 * @brief Handle EXTI interrupt request.
513 * @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
514 * @retval None
515 */
HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)516 void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
517 {
518 /* EXTI line interrupt detected */
519 if (__HAL_GPIO_EXTI_GET_RISING_IT(GPIO_Pin) != 0x00u)
520 {
521 __HAL_GPIO_EXTI_CLEAR_RISING_IT(GPIO_Pin);
522 HAL_GPIO_EXTI_Rising_Callback(GPIO_Pin);
523 }
524
525 if (__HAL_GPIO_EXTI_GET_FALLING_IT(GPIO_Pin) != 0x00u)
526 {
527 __HAL_GPIO_EXTI_CLEAR_FALLING_IT(GPIO_Pin);
528 HAL_GPIO_EXTI_Falling_Callback(GPIO_Pin);
529 }
530 }
531
532 /**
533 * @brief EXTI line rising detection callback.
534 * @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
535 * @retval None
536 */
HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)537 __weak void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
538 {
539 /* Prevent unused argument(s) compilation warning */
540 UNUSED(GPIO_Pin);
541
542 /* NOTE: This function should not be modified, when the callback is needed,
543 the HAL_GPIO_EXTI_Rising_Callback could be implemented in the user file
544 */
545 }
546
547 /**
548 * @brief EXTI line falling detection callback.
549 * @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
550 * @retval None
551 */
HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)552 __weak void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
553 {
554 /* Prevent unused argument(s) compilation warning */
555 UNUSED(GPIO_Pin);
556
557 /* NOTE: This function should not be modified, when the callback is needed,
558 the HAL_GPIO_EXTI_Falling_Callback could be implemented in the user file
559 */
560 }
561
562 /**
563 * @}
564 */
565
566 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
567
568 /** @defgroup GPIO_Exported_Functions_Group3 IO attributes management functions
569 * @brief GPIO attributes management functions.
570 *
571 @verbatim
572 ===============================================================================
573 ##### IO attributes functions #####
574 ===============================================================================
575
576 @endverbatim
577 * @{
578 */
579
580 /**
581 * @brief Configure the GPIO pins attributes.
582 * @note Available attributes are to secure GPIO pin(s), so this function is
583 * only available in secure
584 * @param GPIOx where x can be (A..H) to select the GPIO peripheral for STM32WBA family
585 * @param GPIO_Pin specifies the pin(s) to configure the secure attribute
586 * @param PinAttributes specifies the pin(s) to be set in secure mode, other being set non secured.
587 * @retval None
588 */
HAL_GPIO_ConfigPinAttributes(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin,uint32_t PinAttributes)589 void HAL_GPIO_ConfigPinAttributes(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t PinAttributes)
590 {
591 uint32_t sec;
592
593 /* Check the parameters */
594 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
595 assert_param(IS_GPIO_PIN(GPIO_Pin));
596 assert_param(IS_GPIO_PIN_ATTRIBUTES(PinAttributes));
597
598 /* Configure the port pins */
599 sec = GPIOx->SECCFGR;
600 if (PinAttributes != GPIO_PIN_NSEC)
601 {
602 sec |= (uint32_t)GPIO_Pin;
603 }
604 else
605 {
606 sec &= ~((uint32_t)GPIO_Pin);
607 }
608
609 GPIOx->SECCFGR = sec;
610 }
611
612 /**
613 * @brief Get the GPIO pins attributes.
614 * @note Available attributes are to secure GPIO pin(s), so this function is
615 * only available in secure
616 * @param GPIOx where x can be (A..H) to select the GPIO peripheral for STM32WBA family
617 * @param GPIO_Pin specifies the single pin to get the secure attribute from
618 * @param pPinAttributes pointer to return the pin attributes.
619 * @retval HAL Status.
620 */
HAL_GPIO_GetConfigPinAttributes(const GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin,uint32_t * pPinAttributes)621 HAL_StatusTypeDef HAL_GPIO_GetConfigPinAttributes(const GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t *pPinAttributes)
622 {
623 /* Check null pointer */
624 if (pPinAttributes == NULL)
625 {
626 return HAL_ERROR;
627 }
628
629 /* Check the parameters */
630 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
631
632 if ((GPIOx->SECCFGR & GPIO_Pin) != 0x00U)
633 {
634 *pPinAttributes = GPIO_PIN_SEC;
635 }
636 else
637 {
638 *pPinAttributes = GPIO_PIN_NSEC;
639 }
640
641 return HAL_OK;
642 }
643
644 /**
645 * @}
646 */
647
648 #endif /* __ARM_FEATURE_CMSE */
649
650
651 /**
652 * @}
653 */
654
655 #endif /* HAL_GPIO_MODULE_ENABLED */
656 /**
657 * @}
658 */
659
660 /**
661 * @}
662 */
663
664