Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 18 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32f1xx_hal_gpio.c |
3 | * @file stm32f1xx_hal_gpio.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @brief GPIO HAL module driver. |
5 | * @brief GPIO HAL module driver. |
6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
7 | * functionalities of the General Purpose Input/Output (GPIO) peripheral: |
7 | * functionalities of the General Purpose Input/Output (GPIO) peripheral: |
8 | * + Initialization and de-initialization functions |
8 | * + Initialization and de-initialization functions |
9 | * + IO operation functions |
9 | * + IO operation functions |
10 | * |
10 | * |
11 | @verbatim |
11 | ****************************************************************************** |
12 | ============================================================================== |
12 | * @attention |
13 | ##### GPIO Peripheral features ##### |
13 | * |
14 | ============================================================================== |
14 | * Copyright (c) 2016 STMicroelectronics. |
15 | [..] |
15 | * All rights reserved. |
16 | Subject to the specific hardware characteristics of each I/O port listed in the datasheet, each |
16 | * |
17 | port bit of the General Purpose IO (GPIO) Ports, can be individually configured by software |
17 | * This software is licensed under terms that can be found in the LICENSE file |
18 | in several modes: |
18 | * in the root directory of this software component. |
19 | (+) Input mode |
19 | * If no LICENSE file comes with this software, it is provided AS-IS. |
20 | (+) Analog mode |
20 | * |
21 | (+) Output mode |
21 | ****************************************************************************** |
22 | (+) Alternate function mode |
22 | @verbatim |
23 | (+) External interrupt/event lines |
23 | ============================================================================== |
24 | 24 | ##### GPIO Peripheral features ##### |
|
25 | [..] |
25 | ============================================================================== |
26 | During and just after reset, the alternate functions and external interrupt |
26 | [..] |
27 | lines are not active and the I/O ports are configured in input floating mode. |
27 | Subject to the specific hardware characteristics of each I/O port listed in the datasheet, each |
28 | 28 | port bit of the General Purpose IO (GPIO) Ports, can be individually configured by software |
|
29 | [..] |
29 | in several modes: |
30 | All GPIO pins have weak internal pull-up and pull-down resistors, which can be |
30 | (+) Input mode |
31 | activated or not. |
31 | (+) Analog mode |
32 | 32 | (+) Output mode |
|
33 | [..] |
33 | (+) Alternate function mode |
34 | In Output or Alternate mode, each IO can be configured on open-drain or push-pull |
34 | (+) External interrupt/event lines |
35 | type and the IO speed can be selected depending on the VDD value. |
35 | |
36 | 36 | [..] |
|
37 | [..] |
37 | During and just after reset, the alternate functions and external interrupt |
38 | All ports have external interrupt/event capability. To use external interrupt |
38 | lines are not active and the I/O ports are configured in input floating mode. |
39 | lines, the port must be configured in input mode. All available GPIO pins are |
39 | |
40 | connected to the 16 external interrupt/event lines from EXTI0 to EXTI15. |
40 | [..] |
41 | 41 | All GPIO pins have weak internal pull-up and pull-down resistors, which can be |
|
42 | [..] |
42 | activated or not. |
43 | The external interrupt/event controller consists of up to 20 edge detectors in connectivity |
43 | |
44 | line devices, or 19 edge detectors in other devices for generating event/interrupt requests. |
44 | [..] |
45 | Each input line can be independently configured to select the type (event or interrupt) and |
45 | In Output or Alternate mode, each IO can be configured on open-drain or push-pull |
46 | the corresponding trigger event (rising or falling or both). Each line can also masked |
46 | type and the IO speed can be selected depending on the VDD value. |
47 | independently. A pending register maintains the status line of the interrupt requests |
47 | |
48 | 48 | [..] |
|
49 | ##### How to use this driver ##### |
49 | All ports have external interrupt/event capability. To use external interrupt |
50 | ============================================================================== |
50 | lines, the port must be configured in input mode. All available GPIO pins are |
51 | [..] |
51 | connected to the 16 external interrupt/event lines from EXTI0 to EXTI15. |
52 | (#) Enable the GPIO APB2 clock using the following function : __HAL_RCC_GPIOx_CLK_ENABLE(). |
52 | |
53 | 53 | [..] |
|
54 | (#) Configure the GPIO pin(s) using HAL_GPIO_Init(). |
54 | The external interrupt/event controller consists of up to 20 edge detectors in connectivity |
55 | (++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure |
55 | line devices, or 19 edge detectors in other devices for generating event/interrupt requests. |
56 | (++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef |
56 | Each input line can be independently configured to select the type (event or interrupt) and |
57 | structure. |
57 | the corresponding trigger event (rising or falling or both). Each line can also masked |
58 | (++) In case of Output or alternate function mode selection: the speed is |
58 | independently. A pending register maintains the status line of the interrupt requests |
59 | configured through "Speed" member from GPIO_InitTypeDef structure |
59 | |
60 | (++) Analog mode is required when a pin is to be used as ADC channel |
60 | ##### How to use this driver ##### |
61 | or DAC output. |
61 | ============================================================================== |
62 | (++) In case of external interrupt/event selection the "Mode" member from |
62 | [..] |
63 | GPIO_InitTypeDef structure select the type (interrupt or event) and |
63 | (#) Enable the GPIO APB2 clock using the following function : __HAL_RCC_GPIOx_CLK_ENABLE(). |
64 | the corresponding trigger event (rising or falling or both). |
64 | |
65 | 65 | (#) Configure the GPIO pin(s) using HAL_GPIO_Init(). |
|
66 | (#) In case of external interrupt/event mode selection, configure NVIC IRQ priority |
66 | (++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure |
67 | mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using |
67 | (++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef |
68 | HAL_NVIC_EnableIRQ(). |
68 | structure. |
69 | 69 | (++) In case of Output or alternate function mode selection: the speed is |
|
70 | (#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin(). |
70 | configured through "Speed" member from GPIO_InitTypeDef structure |
71 | 71 | (++) Analog mode is required when a pin is to be used as ADC channel |
|
72 | (#) To set/reset the level of a pin configured in output mode use |
72 | or DAC output. |
73 | HAL_GPIO_WritePin()/HAL_GPIO_TogglePin(). |
73 | (++) In case of external interrupt/event selection the "Mode" member from |
74 | 74 | GPIO_InitTypeDef structure select the type (interrupt or event) and |
|
75 | (#) To lock pin configuration until next reset use HAL_GPIO_LockPin(). |
75 | the corresponding trigger event (rising or falling or both). |
76 | 76 | ||
77 | (#) During and just after reset, the alternate functions are not |
77 | (#) In case of external interrupt/event mode selection, configure NVIC IRQ priority |
78 | active and the GPIO pins are configured in input floating mode (except JTAG |
78 | mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using |
79 | pins). |
79 | HAL_NVIC_EnableIRQ(). |
80 | 80 | ||
81 | (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose |
81 | (#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin(). |
82 | (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has |
82 | |
83 | priority over the GPIO function. |
83 | (#) To set/reset the level of a pin configured in output mode use |
84 | 84 | HAL_GPIO_WritePin()/HAL_GPIO_TogglePin(). |
|
85 | (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as |
85 | |
86 | general purpose PD0 and PD1, respectively, when the HSE oscillator is off. |
86 | (#) To lock pin configuration until next reset use HAL_GPIO_LockPin(). |
87 | The HSE has priority over the GPIO function. |
87 | |
88 | 88 | (#) During and just after reset, the alternate functions are not |
|
89 | @endverbatim |
89 | active and the GPIO pins are configured in input floating mode (except JTAG |
90 | ****************************************************************************** |
90 | pins). |
91 | * @attention |
91 | |
92 | * |
92 | (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose |
93 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
93 | (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has |
94 | * All rights reserved.</center></h2> |
94 | priority over the GPIO function. |
95 | * |
95 | |
96 | * This software component is licensed by ST under BSD 3-Clause license, |
96 | (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as |
97 | * the "License"; You may not use this file except in compliance with the |
97 | general purpose PD0 and PD1, respectively, when the HSE oscillator is off. |
98 | * License. You may obtain a copy of the License at: |
98 | The HSE has priority over the GPIO function. |
99 | * opensource.org/licenses/BSD-3-Clause |
99 | |
100 | * |
100 | @endverbatim |
101 | ****************************************************************************** |
101 | ****************************************************************************** |
102 | */ |
102 | */ |
103 | 103 | ||
104 | /* Includes ------------------------------------------------------------------*/ |
104 | /* Includes ------------------------------------------------------------------*/ |
105 | #include "stm32f1xx_hal.h" |
105 | #include "stm32f1xx_hal.h" |
106 | 106 | ||
107 | /** @addtogroup STM32F1xx_HAL_Driver |
107 | /** @addtogroup STM32F1xx_HAL_Driver |
108 | * @{ |
108 | * @{ |
109 | */ |
109 | */ |
110 | 110 | ||
111 | /** @defgroup GPIO GPIO |
111 | /** @defgroup GPIO GPIO |
112 | * @brief GPIO HAL module driver |
112 | * @brief GPIO HAL module driver |
113 | * @{ |
113 | * @{ |
114 | */ |
114 | */ |
115 | 115 | ||
116 | #ifdef HAL_GPIO_MODULE_ENABLED |
116 | #ifdef HAL_GPIO_MODULE_ENABLED |
117 | 117 | ||
118 | /* Private typedef -----------------------------------------------------------*/ |
118 | /* Private typedef -----------------------------------------------------------*/ |
119 | /* Private define ------------------------------------------------------------*/ |
119 | /* Private define ------------------------------------------------------------*/ |
120 | /** @addtogroup GPIO_Private_Constants GPIO Private Constants |
120 | /** @addtogroup GPIO_Private_Constants GPIO Private Constants |
121 | * @{ |
121 | * @{ |
122 | */ |
122 | */ |
123 | #define GPIO_MODE 0x00000003u |
123 | #define GPIO_MODE 0x00000003u |
124 | #define EXTI_MODE 0x10000000u |
124 | #define EXTI_MODE 0x10000000u |
125 | #define GPIO_MODE_IT 0x00010000u |
125 | #define GPIO_MODE_IT 0x00010000u |
126 | #define GPIO_MODE_EVT 0x00020000u |
126 | #define GPIO_MODE_EVT 0x00020000u |
127 | #define RISING_EDGE 0x00100000u |
127 | #define RISING_EDGE 0x00100000u |
128 | #define FALLING_EDGE 0x00200000u |
128 | #define FALLING_EDGE 0x00200000u |
129 | #define GPIO_OUTPUT_TYPE 0x00000010u |
129 | #define GPIO_OUTPUT_TYPE 0x00000010u |
130 | 130 | ||
131 | #define GPIO_NUMBER 16u |
131 | #define GPIO_NUMBER 16u |
132 | 132 | ||
133 | /* Definitions for bit manipulation of CRL and CRH register */ |
133 | /* Definitions for bit manipulation of CRL and CRH register */ |
134 | #define GPIO_CR_MODE_INPUT 0x00000000u /*!< 00: Input mode (reset state) */ |
134 | #define GPIO_CR_MODE_INPUT 0x00000000u /*!< 00: Input mode (reset state) */ |
135 | #define GPIO_CR_CNF_ANALOG 0x00000000u /*!< 00: Analog mode */ |
135 | #define GPIO_CR_CNF_ANALOG 0x00000000u /*!< 00: Analog mode */ |
136 | #define GPIO_CR_CNF_INPUT_FLOATING 0x00000004u /*!< 01: Floating input (reset state) */ |
136 | #define GPIO_CR_CNF_INPUT_FLOATING 0x00000004u /*!< 01: Floating input (reset state) */ |
137 | #define GPIO_CR_CNF_INPUT_PU_PD 0x00000008u /*!< 10: Input with pull-up / pull-down */ |
137 | #define GPIO_CR_CNF_INPUT_PU_PD 0x00000008u /*!< 10: Input with pull-up / pull-down */ |
138 | #define GPIO_CR_CNF_GP_OUTPUT_PP 0x00000000u /*!< 00: General purpose output push-pull */ |
138 | #define GPIO_CR_CNF_GP_OUTPUT_PP 0x00000000u /*!< 00: General purpose output push-pull */ |
139 | #define GPIO_CR_CNF_GP_OUTPUT_OD 0x00000004u /*!< 01: General purpose output Open-drain */ |
139 | #define GPIO_CR_CNF_GP_OUTPUT_OD 0x00000004u /*!< 01: General purpose output Open-drain */ |
140 | #define GPIO_CR_CNF_AF_OUTPUT_PP 0x00000008u /*!< 10: Alternate function output Push-pull */ |
140 | #define GPIO_CR_CNF_AF_OUTPUT_PP 0x00000008u /*!< 10: Alternate function output Push-pull */ |
141 | #define GPIO_CR_CNF_AF_OUTPUT_OD 0x0000000Cu /*!< 11: Alternate function output Open-drain */ |
141 | #define GPIO_CR_CNF_AF_OUTPUT_OD 0x0000000Cu /*!< 11: Alternate function output Open-drain */ |
142 | 142 | ||
143 | /** |
143 | /** |
144 | * @} |
144 | * @} |
145 | */ |
145 | */ |
146 | /* Private macro -------------------------------------------------------------*/ |
146 | /* Private macro -------------------------------------------------------------*/ |
147 | /* Private variables ---------------------------------------------------------*/ |
147 | /* Private variables ---------------------------------------------------------*/ |
148 | /* Private function prototypes -----------------------------------------------*/ |
148 | /* Private function prototypes -----------------------------------------------*/ |
149 | /* Private functions ---------------------------------------------------------*/ |
149 | /* Private functions ---------------------------------------------------------*/ |
150 | /* Exported functions --------------------------------------------------------*/ |
150 | /* Exported functions --------------------------------------------------------*/ |
151 | /** @defgroup GPIO_Exported_Functions GPIO Exported Functions |
151 | /** @defgroup GPIO_Exported_Functions GPIO Exported Functions |
152 | * @{ |
152 | * @{ |
153 | */ |
153 | */ |
154 | 154 | ||
155 | /** @defgroup GPIO_Exported_Functions_Group1 Initialization and de-initialization functions |
155 | /** @defgroup GPIO_Exported_Functions_Group1 Initialization and de-initialization functions |
156 | * @brief Initialization and Configuration functions |
156 | * @brief Initialization and Configuration functions |
157 | * |
157 | * |
158 | @verbatim |
158 | @verbatim |
159 | =============================================================================== |
159 | =============================================================================== |
160 | ##### Initialization and de-initialization functions ##### |
160 | ##### Initialization and de-initialization functions ##### |
161 | =============================================================================== |
161 | =============================================================================== |
162 | [..] |
162 | [..] |
163 | This section provides functions allowing to initialize and de-initialize the GPIOs |
163 | This section provides functions allowing to initialize and de-initialize the GPIOs |
164 | to be ready for use. |
164 | to be ready for use. |
165 | 165 | ||
166 | @endverbatim |
166 | @endverbatim |
167 | * @{ |
167 | * @{ |
168 | */ |
168 | */ |
169 | 169 | ||
170 | 170 | ||
171 | /** |
171 | /** |
172 | * @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init. |
172 | * @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init. |
173 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
173 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
174 | * @param GPIO_Init: pointer to a GPIO_InitTypeDef structure that contains |
174 | * @param GPIO_Init: pointer to a GPIO_InitTypeDef structure that contains |
175 | * the configuration information for the specified GPIO peripheral. |
175 | * the configuration information for the specified GPIO peripheral. |
176 | * @retval None |
176 | * @retval None |
177 | */ |
177 | */ |
178 | void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init) |
178 | void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init) |
179 | { |
179 | { |
180 | uint32_t position = 0x00u; |
180 | uint32_t position = 0x00u; |
181 | uint32_t ioposition; |
181 | uint32_t ioposition; |
182 | uint32_t iocurrent; |
182 | uint32_t iocurrent; |
183 | uint32_t temp; |
183 | uint32_t temp; |
184 | uint32_t config = 0x00u; |
184 | uint32_t config = 0x00u; |
185 | __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */ |
185 | __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */ |
186 | uint32_t registeroffset; /* offset used during computation of CNF and MODE bits placement inside CRL or CRH register */ |
186 | uint32_t registeroffset; /* offset used during computation of CNF and MODE bits placement inside CRL or CRH register */ |
187 | 187 | ||
188 | /* Check the parameters */ |
188 | /* Check the parameters */ |
189 | assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); |
189 | assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); |
190 | assert_param(IS_GPIO_PIN(GPIO_Init->Pin)); |
190 | assert_param(IS_GPIO_PIN(GPIO_Init->Pin)); |
191 | assert_param(IS_GPIO_MODE(GPIO_Init->Mode)); |
191 | assert_param(IS_GPIO_MODE(GPIO_Init->Mode)); |
192 | 192 | ||
193 | /* Configure the port pins */ |
193 | /* Configure the port pins */ |
194 | while (((GPIO_Init->Pin) >> position) != 0x00u) |
194 | while (((GPIO_Init->Pin) >> position) != 0x00u) |
195 | { |
195 | { |
196 | /* Get the IO position */ |
196 | /* Get the IO position */ |
197 | ioposition = (0x01uL << position); |
197 | ioposition = (0x01uL << position); |
198 | 198 | ||
199 | /* Get the current IO position */ |
199 | /* Get the current IO position */ |
200 | iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition; |
200 | iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition; |
201 | 201 | ||
202 | if (iocurrent == ioposition) |
202 | if (iocurrent == ioposition) |
203 | { |
203 | { |
204 | /* Check the Alternate function parameters */ |
204 | /* Check the Alternate function parameters */ |
205 | assert_param(IS_GPIO_AF_INSTANCE(GPIOx)); |
205 | assert_param(IS_GPIO_AF_INSTANCE(GPIOx)); |
206 | 206 | ||
207 | /* Based on the required mode, filling config variable with MODEy[1:0] and CNFy[3:2] corresponding bits */ |
207 | /* Based on the required mode, filling config variable with MODEy[1:0] and CNFy[3:2] corresponding bits */ |
208 | switch (GPIO_Init->Mode) |
208 | switch (GPIO_Init->Mode) |
209 | { |
209 | { |
210 | /* If we are configuring the pin in OUTPUT push-pull mode */ |
210 | /* If we are configuring the pin in OUTPUT push-pull mode */ |
211 | case GPIO_MODE_OUTPUT_PP: |
211 | case GPIO_MODE_OUTPUT_PP: |
212 | /* Check the GPIO speed parameter */ |
212 | /* Check the GPIO speed parameter */ |
213 | assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); |
213 | assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); |
214 | config = GPIO_Init->Speed + GPIO_CR_CNF_GP_OUTPUT_PP; |
214 | config = GPIO_Init->Speed + GPIO_CR_CNF_GP_OUTPUT_PP; |
215 | break; |
215 | break; |
216 | 216 | ||
217 | /* If we are configuring the pin in OUTPUT open-drain mode */ |
217 | /* If we are configuring the pin in OUTPUT open-drain mode */ |
218 | case GPIO_MODE_OUTPUT_OD: |
218 | case GPIO_MODE_OUTPUT_OD: |
219 | /* Check the GPIO speed parameter */ |
219 | /* Check the GPIO speed parameter */ |
220 | assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); |
220 | assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); |
221 | config = GPIO_Init->Speed + GPIO_CR_CNF_GP_OUTPUT_OD; |
221 | config = GPIO_Init->Speed + GPIO_CR_CNF_GP_OUTPUT_OD; |
222 | break; |
222 | break; |
223 | 223 | ||
224 | /* If we are configuring the pin in ALTERNATE FUNCTION push-pull mode */ |
224 | /* If we are configuring the pin in ALTERNATE FUNCTION push-pull mode */ |
225 | case GPIO_MODE_AF_PP: |
225 | case GPIO_MODE_AF_PP: |
226 | /* Check the GPIO speed parameter */ |
226 | /* Check the GPIO speed parameter */ |
227 | assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); |
227 | assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); |
228 | config = GPIO_Init->Speed + GPIO_CR_CNF_AF_OUTPUT_PP; |
228 | config = GPIO_Init->Speed + GPIO_CR_CNF_AF_OUTPUT_PP; |
229 | break; |
229 | break; |
230 | 230 | ||
231 | /* If we are configuring the pin in ALTERNATE FUNCTION open-drain mode */ |
231 | /* If we are configuring the pin in ALTERNATE FUNCTION open-drain mode */ |
232 | case GPIO_MODE_AF_OD: |
232 | case GPIO_MODE_AF_OD: |
233 | /* Check the GPIO speed parameter */ |
233 | /* Check the GPIO speed parameter */ |
234 | assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); |
234 | assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); |
235 | config = GPIO_Init->Speed + GPIO_CR_CNF_AF_OUTPUT_OD; |
235 | config = GPIO_Init->Speed + GPIO_CR_CNF_AF_OUTPUT_OD; |
236 | break; |
236 | break; |
237 | 237 | ||
238 | /* If we are configuring the pin in INPUT (also applicable to EVENT and IT mode) */ |
238 | /* If we are configuring the pin in INPUT (also applicable to EVENT and IT mode) */ |
239 | case GPIO_MODE_INPUT: |
239 | case GPIO_MODE_INPUT: |
240 | case GPIO_MODE_IT_RISING: |
240 | case GPIO_MODE_IT_RISING: |
241 | case GPIO_MODE_IT_FALLING: |
241 | case GPIO_MODE_IT_FALLING: |
242 | case GPIO_MODE_IT_RISING_FALLING: |
242 | case GPIO_MODE_IT_RISING_FALLING: |
243 | case GPIO_MODE_EVT_RISING: |
243 | case GPIO_MODE_EVT_RISING: |
244 | case GPIO_MODE_EVT_FALLING: |
244 | case GPIO_MODE_EVT_FALLING: |
245 | case GPIO_MODE_EVT_RISING_FALLING: |
245 | case GPIO_MODE_EVT_RISING_FALLING: |
246 | /* Check the GPIO pull parameter */ |
246 | /* Check the GPIO pull parameter */ |
247 | assert_param(IS_GPIO_PULL(GPIO_Init->Pull)); |
247 | assert_param(IS_GPIO_PULL(GPIO_Init->Pull)); |
248 | if (GPIO_Init->Pull == GPIO_NOPULL) |
248 | if (GPIO_Init->Pull == GPIO_NOPULL) |
249 | { |
249 | { |
250 | config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_FLOATING; |
250 | config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_FLOATING; |
251 | } |
251 | } |
252 | else if (GPIO_Init->Pull == GPIO_PULLUP) |
252 | else if (GPIO_Init->Pull == GPIO_PULLUP) |
253 | { |
253 | { |
254 | config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD; |
254 | config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD; |
255 | 255 | ||
256 | /* Set the corresponding ODR bit */ |
256 | /* Set the corresponding ODR bit */ |
257 | GPIOx->BSRR = ioposition; |
257 | GPIOx->BSRR = ioposition; |
258 | } |
258 | } |
259 | else /* GPIO_PULLDOWN */ |
259 | else /* GPIO_PULLDOWN */ |
260 | { |
260 | { |
261 | config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD; |
261 | config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD; |
262 | 262 | ||
263 | /* Reset the corresponding ODR bit */ |
263 | /* Reset the corresponding ODR bit */ |
264 | GPIOx->BRR = ioposition; |
264 | GPIOx->BRR = ioposition; |
265 | } |
265 | } |
266 | break; |
266 | break; |
267 | 267 | ||
268 | /* If we are configuring the pin in INPUT analog mode */ |
268 | /* If we are configuring the pin in INPUT analog mode */ |
269 | case GPIO_MODE_ANALOG: |
269 | case GPIO_MODE_ANALOG: |
270 | config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_ANALOG; |
270 | config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_ANALOG; |
271 | break; |
271 | break; |
272 | 272 | ||
273 | /* Parameters are checked with assert_param */ |
273 | /* Parameters are checked with assert_param */ |
274 | default: |
274 | default: |
275 | break; |
275 | break; |
276 | } |
276 | } |
277 | 277 | ||
278 | /* Check if the current bit belongs to first half or last half of the pin count number |
278 | /* Check if the current bit belongs to first half or last half of the pin count number |
279 | in order to address CRH or CRL register*/ |
279 | in order to address CRH or CRL register*/ |
280 | configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL : &GPIOx->CRH; |
280 | configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL : &GPIOx->CRH; |
281 | registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2u) : ((position - 8u) << 2u); |
281 | registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2u) : ((position - 8u) << 2u); |
282 | 282 | ||
283 | /* Apply the new configuration of the pin to the register */ |
283 | /* Apply the new configuration of the pin to the register */ |
284 | MODIFY_REG((*configregister), ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), (config << registeroffset)); |
284 | MODIFY_REG((*configregister), ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), (config << registeroffset)); |
285 | 285 | ||
286 | /*--------------------- EXTI Mode Configuration ------------------------*/ |
286 | /*--------------------- EXTI Mode Configuration ------------------------*/ |
287 | /* Configure the External Interrupt or event for the current IO */ |
287 | /* Configure the External Interrupt or event for the current IO */ |
288 | if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE) |
288 | if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE) |
289 | { |
289 | { |
290 | /* Enable AFIO Clock */ |
290 | /* Enable AFIO Clock */ |
291 | __HAL_RCC_AFIO_CLK_ENABLE(); |
291 | __HAL_RCC_AFIO_CLK_ENABLE(); |
292 | temp = AFIO->EXTICR[position >> 2u]; |
292 | temp = AFIO->EXTICR[position >> 2u]; |
293 | CLEAR_BIT(temp, (0x0Fu) << (4u * (position & 0x03u))); |
293 | CLEAR_BIT(temp, (0x0Fu) << (4u * (position & 0x03u))); |
294 | SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4u * (position & 0x03u))); |
294 | SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4u * (position & 0x03u))); |
295 | AFIO->EXTICR[position >> 2u] = temp; |
295 | AFIO->EXTICR[position >> 2u] = temp; |
296 | 296 | ||
297 | 297 | ||
298 | /* Configure the interrupt mask */ |
298 | /* Enable or disable the rising trigger */ |
299 | if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT) |
299 | if ((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE) |
300 | { |
300 | { |
301 | SET_BIT(EXTI->IMR, iocurrent); |
301 | SET_BIT(EXTI->RTSR, iocurrent); |
302 | } |
302 | } |
303 | else |
303 | else |
304 | { |
304 | { |
305 | CLEAR_BIT(EXTI->IMR, iocurrent); |
305 | CLEAR_BIT(EXTI->RTSR, iocurrent); |
306 | } |
306 | } |
307 | 307 | ||
308 | /* Configure the event mask */ |
308 | /* Enable or disable the falling trigger */ |
309 | if ((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT) |
309 | if ((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE) |
310 | { |
310 | { |
311 | SET_BIT(EXTI->EMR, iocurrent); |
311 | SET_BIT(EXTI->FTSR, iocurrent); |
312 | } |
312 | } |
313 | else |
313 | else |
314 | { |
314 | { |
315 | CLEAR_BIT(EXTI->EMR, iocurrent); |
315 | CLEAR_BIT(EXTI->FTSR, iocurrent); |
316 | } |
316 | } |
317 | 317 | ||
318 | /* Enable or disable the rising trigger */ |
318 | /* Configure the event mask */ |
319 | if ((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE) |
319 | if ((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT) |
320 | { |
320 | { |
321 | SET_BIT(EXTI->RTSR, iocurrent); |
321 | SET_BIT(EXTI->EMR, iocurrent); |
322 | } |
322 | } |
323 | else |
323 | else |
324 | { |
324 | { |
325 | CLEAR_BIT(EXTI->RTSR, iocurrent); |
325 | CLEAR_BIT(EXTI->EMR, iocurrent); |
326 | } |
326 | } |
327 | 327 | ||
328 | /* Enable or disable the falling trigger */ |
328 | /* Configure the interrupt mask */ |
329 | if ((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE) |
329 | if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT) |
330 | { |
330 | { |
331 | SET_BIT(EXTI->FTSR, iocurrent); |
331 | SET_BIT(EXTI->IMR, iocurrent); |
332 | } |
332 | } |
333 | else |
333 | else |
334 | { |
334 | { |
335 | CLEAR_BIT(EXTI->FTSR, iocurrent); |
335 | CLEAR_BIT(EXTI->IMR, iocurrent); |
336 | } |
336 | } |
337 | } |
337 | } |
338 | } |
338 | } |
339 | 339 | ||
340 | position++; |
340 | position++; |
341 | } |
341 | } |
342 | } |
342 | } |
343 | 343 | ||
344 | /** |
344 | /** |
345 | * @brief De-initializes the GPIOx peripheral registers to their default reset values. |
345 | * @brief De-initializes the GPIOx peripheral registers to their default reset values. |
346 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
346 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
347 | * @param GPIO_Pin: specifies the port bit to be written. |
347 | * @param GPIO_Pin: specifies the port bit to be written. |
348 | * This parameter can be one of GPIO_PIN_x where x can be (0..15). |
348 | * This parameter can be one of GPIO_PIN_x where x can be (0..15). |
349 | * @retval None |
349 | * @retval None |
350 | */ |
350 | */ |
351 | void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) |
351 | void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) |
352 | { |
352 | { |
353 | uint32_t position = 0x00u; |
353 | uint32_t position = 0x00u; |
354 | uint32_t iocurrent; |
354 | uint32_t iocurrent; |
355 | uint32_t tmp; |
355 | uint32_t tmp; |
356 | __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */ |
356 | __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */ |
357 | uint32_t registeroffset; |
357 | uint32_t registeroffset; |
358 | 358 | ||
359 | /* Check the parameters */ |
359 | /* Check the parameters */ |
360 | assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); |
360 | assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); |
361 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
361 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
362 | 362 | ||
363 | /* Configure the port pins */ |
363 | /* Configure the port pins */ |
364 | while ((GPIO_Pin >> position) != 0u) |
364 | while ((GPIO_Pin >> position) != 0u) |
365 | { |
365 | { |
366 | /* Get current io position */ |
366 | /* Get current io position */ |
367 | iocurrent = (GPIO_Pin) & (1uL << position); |
367 | iocurrent = (GPIO_Pin) & (1uL << position); |
368 | 368 | ||
369 | if (iocurrent) |
369 | if (iocurrent) |
370 | { |
370 | { |
371 | /*------------------------- EXTI Mode Configuration --------------------*/ |
371 | /*------------------------- EXTI Mode Configuration --------------------*/ |
372 | /* Clear the External Interrupt or Event for the current IO */ |
372 | /* Clear the External Interrupt or Event for the current IO */ |
373 | 373 | ||
374 | tmp = AFIO->EXTICR[position >> 2u]; |
374 | tmp = AFIO->EXTICR[position >> 2u]; |
375 | tmp &= 0x0FuL << (4u * (position & 0x03u)); |
375 | tmp &= 0x0FuL << (4u * (position & 0x03u)); |
376 | if (tmp == (GPIO_GET_INDEX(GPIOx) << (4u * (position & 0x03u)))) |
376 | if (tmp == (GPIO_GET_INDEX(GPIOx) << (4u * (position & 0x03u)))) |
377 | { |
377 | { |
378 | tmp = 0x0FuL << (4u * (position & 0x03u)); |
378 | /* Clear EXTI line configuration */ |
379 | CLEAR_BIT(AFIO->EXTICR[position >> 2u], tmp); |
379 | CLEAR_BIT(EXTI->IMR, (uint32_t)iocurrent); |
380 | 380 | CLEAR_BIT(EXTI->EMR, (uint32_t)iocurrent); |
|
381 | /* Clear EXTI line configuration */ |
381 | |
382 | CLEAR_BIT(EXTI->IMR, (uint32_t)iocurrent); |
382 | /* Clear Rising Falling edge configuration */ |
383 | CLEAR_BIT(EXTI->EMR, (uint32_t)iocurrent); |
383 | CLEAR_BIT(EXTI->FTSR, (uint32_t)iocurrent); |
384 | 384 | CLEAR_BIT(EXTI->RTSR, (uint32_t)iocurrent); |
|
385 | /* Clear Rising Falling edge configuration */ |
385 | |
386 | CLEAR_BIT(EXTI->RTSR, (uint32_t)iocurrent); |
386 | tmp = 0x0FuL << (4u * (position & 0x03u)); |
387 | CLEAR_BIT(EXTI->FTSR, (uint32_t)iocurrent); |
387 | CLEAR_BIT(AFIO->EXTICR[position >> 2u], tmp); |
388 | } |
388 | } |
389 | /*------------------------- GPIO Mode Configuration --------------------*/ |
389 | /*------------------------- GPIO Mode Configuration --------------------*/ |
390 | /* Check if the current bit belongs to first half or last half of the pin count number |
390 | /* Check if the current bit belongs to first half or last half of the pin count number |
391 | in order to address CRH or CRL register */ |
391 | in order to address CRH or CRL register */ |
392 | configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL : &GPIOx->CRH; |
392 | configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL : &GPIOx->CRH; |
393 | registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2u) : ((position - 8u) << 2u); |
393 | registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2u) : ((position - 8u) << 2u); |
394 | 394 | ||
395 | /* CRL/CRH default value is floating input(0x04) shifted to correct position */ |
395 | /* CRL/CRH default value is floating input(0x04) shifted to correct position */ |
396 | MODIFY_REG(*configregister, ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), GPIO_CRL_CNF0_0 << registeroffset); |
396 | MODIFY_REG(*configregister, ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), GPIO_CRL_CNF0_0 << registeroffset); |
397 | 397 | ||
398 | /* ODR default value is 0 */ |
398 | /* ODR default value is 0 */ |
399 | CLEAR_BIT(GPIOx->ODR, iocurrent); |
399 | CLEAR_BIT(GPIOx->ODR, iocurrent); |
400 | } |
400 | } |
401 | 401 | ||
402 | position++; |
402 | position++; |
403 | } |
403 | } |
404 | } |
404 | } |
405 | 405 | ||
406 | /** |
406 | /** |
407 | * @} |
407 | * @} |
408 | */ |
408 | */ |
409 | 409 | ||
410 | /** @defgroup GPIO_Exported_Functions_Group2 IO operation functions |
410 | /** @defgroup GPIO_Exported_Functions_Group2 IO operation functions |
411 | * @brief GPIO Read and Write |
411 | * @brief GPIO Read and Write |
412 | * |
412 | * |
413 | @verbatim |
413 | @verbatim |
414 | =============================================================================== |
414 | =============================================================================== |
415 | ##### IO operation functions ##### |
415 | ##### IO operation functions ##### |
416 | =============================================================================== |
416 | =============================================================================== |
417 | [..] |
417 | [..] |
418 | This subsection provides a set of functions allowing to manage the GPIOs. |
418 | This subsection provides a set of functions allowing to manage the GPIOs. |
419 | 419 | ||
420 | @endverbatim |
420 | @endverbatim |
421 | * @{ |
421 | * @{ |
422 | */ |
422 | */ |
423 | 423 | ||
424 | /** |
424 | /** |
425 | * @brief Reads the specified input port pin. |
425 | * @brief Reads the specified input port pin. |
426 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
426 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
427 | * @param GPIO_Pin: specifies the port bit to read. |
427 | * @param GPIO_Pin: specifies the port bit to read. |
428 | * This parameter can be GPIO_PIN_x where x can be (0..15). |
428 | * This parameter can be GPIO_PIN_x where x can be (0..15). |
429 | * @retval The input port pin value. |
429 | * @retval The input port pin value. |
430 | */ |
430 | */ |
431 | GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) |
431 | GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) |
432 | { |
432 | { |
433 | GPIO_PinState bitstatus; |
433 | GPIO_PinState bitstatus; |
434 | 434 | ||
435 | /* Check the parameters */ |
435 | /* Check the parameters */ |
436 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
436 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
437 | 437 | ||
438 | if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET) |
438 | if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET) |
439 | { |
439 | { |
440 | bitstatus = GPIO_PIN_SET; |
440 | bitstatus = GPIO_PIN_SET; |
441 | } |
441 | } |
442 | else |
442 | else |
443 | { |
443 | { |
444 | bitstatus = GPIO_PIN_RESET; |
444 | bitstatus = GPIO_PIN_RESET; |
445 | } |
445 | } |
446 | return bitstatus; |
446 | return bitstatus; |
447 | } |
447 | } |
448 | 448 | ||
449 | /** |
449 | /** |
450 | * @brief Sets or clears the selected data port bit. |
450 | * @brief Sets or clears the selected data port bit. |
451 | * |
451 | * |
452 | * @note This function uses GPIOx_BSRR register to allow atomic read/modify |
452 | * @note This function uses GPIOx_BSRR register to allow atomic read/modify |
453 | * accesses. In this way, there is no risk of an IRQ occurring between |
453 | * accesses. In this way, there is no risk of an IRQ occurring between |
454 | * the read and the modify access. |
454 | * the read and the modify access. |
455 | * |
455 | * |
456 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
456 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
457 | * @param GPIO_Pin: specifies the port bit to be written. |
457 | * @param GPIO_Pin: specifies the port bit to be written. |
458 | * This parameter can be one of GPIO_PIN_x where x can be (0..15). |
458 | * This parameter can be one of GPIO_PIN_x where x can be (0..15). |
459 | * @param PinState: specifies the value to be written to the selected bit. |
459 | * @param PinState: specifies the value to be written to the selected bit. |
460 | * This parameter can be one of the GPIO_PinState enum values: |
460 | * This parameter can be one of the GPIO_PinState enum values: |
461 | * @arg GPIO_PIN_RESET: to clear the port pin |
461 | * @arg GPIO_PIN_RESET: to clear the port pin |
462 | * @arg GPIO_PIN_SET: to set the port pin |
462 | * @arg GPIO_PIN_SET: to set the port pin |
463 | * @retval None |
463 | * @retval None |
464 | */ |
464 | */ |
465 | void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) |
465 | void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) |
466 | { |
466 | { |
467 | /* Check the parameters */ |
467 | /* Check the parameters */ |
468 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
468 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
469 | assert_param(IS_GPIO_PIN_ACTION(PinState)); |
469 | assert_param(IS_GPIO_PIN_ACTION(PinState)); |
470 | 470 | ||
471 | if (PinState != GPIO_PIN_RESET) |
471 | if (PinState != GPIO_PIN_RESET) |
472 | { |
472 | { |
473 | GPIOx->BSRR = GPIO_Pin; |
473 | GPIOx->BSRR = GPIO_Pin; |
474 | } |
474 | } |
475 | else |
475 | else |
476 | { |
476 | { |
477 | GPIOx->BSRR = (uint32_t)GPIO_Pin << 16u; |
477 | GPIOx->BSRR = (uint32_t)GPIO_Pin << 16u; |
478 | } |
478 | } |
479 | } |
479 | } |
480 | 480 | ||
481 | /** |
481 | /** |
482 | * @brief Toggles the specified GPIO pin |
482 | * @brief Toggles the specified GPIO pin |
483 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
483 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
484 | * @param GPIO_Pin: Specifies the pins to be toggled. |
484 | * @param GPIO_Pin: Specifies the pins to be toggled. |
485 | * @retval None |
485 | * @retval None |
486 | */ |
486 | */ |
487 | void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) |
487 | void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) |
488 | { |
488 | { |
489 | uint32_t odr; |
489 | uint32_t odr; |
490 | 490 | ||
491 | /* Check the parameters */ |
491 | /* Check the parameters */ |
492 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
492 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
493 | 493 | ||
494 | /* get current Ouput Data Register value */ |
494 | /* get current Output Data Register value */ |
495 | odr = GPIOx->ODR; |
495 | odr = GPIOx->ODR; |
496 | 496 | ||
497 | /* Set selected pins that were at low level, and reset ones that were high */ |
497 | /* Set selected pins that were at low level, and reset ones that were high */ |
498 | GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin); |
498 | GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin); |
499 | } |
499 | } |
500 | 500 | ||
501 | /** |
501 | /** |
502 | * @brief Locks GPIO Pins configuration registers. |
502 | * @brief Locks GPIO Pins configuration registers. |
503 | * @note The locking mechanism allows the IO configuration to be frozen. When the LOCK sequence |
503 | * @note The locking mechanism allows the IO configuration to be frozen. When the LOCK sequence |
504 | * has been applied on a port bit, it is no longer possible to modify the value of the port bit until |
504 | * has been applied on a port bit, it is no longer possible to modify the value of the port bit until |
505 | * the next reset. |
505 | * the next reset. |
506 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
506 | * @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral |
507 | * @param GPIO_Pin: specifies the port bit to be locked. |
507 | * @param GPIO_Pin: specifies the port bit to be locked. |
508 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
508 | * This parameter can be any combination of GPIO_Pin_x where x can be (0..15). |
509 | * @retval None |
509 | * @retval None |
510 | */ |
510 | */ |
511 | HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) |
511 | HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) |
512 | { |
512 | { |
513 | __IO uint32_t tmp = GPIO_LCKR_LCKK; |
513 | __IO uint32_t tmp = GPIO_LCKR_LCKK; |
514 | 514 | ||
515 | /* Check the parameters */ |
515 | /* Check the parameters */ |
516 | assert_param(IS_GPIO_LOCK_INSTANCE(GPIOx)); |
516 | assert_param(IS_GPIO_LOCK_INSTANCE(GPIOx)); |
517 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
517 | assert_param(IS_GPIO_PIN(GPIO_Pin)); |
518 | 518 | ||
519 | /* Apply lock key write sequence */ |
519 | /* Apply lock key write sequence */ |
520 | SET_BIT(tmp, GPIO_Pin); |
520 | SET_BIT(tmp, GPIO_Pin); |
521 | /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */ |
521 | /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */ |
522 | GPIOx->LCKR = tmp; |
522 | GPIOx->LCKR = tmp; |
523 | /* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */ |
523 | /* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */ |
524 | GPIOx->LCKR = GPIO_Pin; |
524 | GPIOx->LCKR = GPIO_Pin; |
525 | /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */ |
525 | /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */ |
526 | GPIOx->LCKR = tmp; |
526 | GPIOx->LCKR = tmp; |
527 | /* Read LCKK register. This read is mandatory to complete key lock sequence */ |
527 | /* Read LCKK register. This read is mandatory to complete key lock sequence */ |
528 | tmp = GPIOx->LCKR; |
528 | tmp = GPIOx->LCKR; |
529 | 529 | ||
530 | /* read again in order to confirm lock is active */ |
530 | /* read again in order to confirm lock is active */ |
531 | if ((uint32_t)(GPIOx->LCKR & GPIO_LCKR_LCKK)) |
531 | if ((uint32_t)(GPIOx->LCKR & GPIO_LCKR_LCKK)) |
532 | { |
532 | { |
533 | return HAL_OK; |
533 | return HAL_OK; |
534 | } |
534 | } |
535 | else |
535 | else |
536 | { |
536 | { |
537 | return HAL_ERROR; |
537 | return HAL_ERROR; |
538 | } |
538 | } |
539 | } |
539 | } |
540 | 540 | ||
541 | /** |
541 | /** |
542 | * @brief This function handles EXTI interrupt request. |
542 | * @brief This function handles EXTI interrupt request. |
543 | * @param GPIO_Pin: Specifies the pins connected EXTI line |
543 | * @param GPIO_Pin: Specifies the pins connected EXTI line |
544 | * @retval None |
544 | * @retval None |
545 | */ |
545 | */ |
546 | void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin) |
546 | void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin) |
547 | { |
547 | { |
548 | /* EXTI line interrupt detected */ |
548 | /* EXTI line interrupt detected */ |
549 | if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00u) |
549 | if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00u) |
550 | { |
550 | { |
551 | __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin); |
551 | __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin); |
552 | HAL_GPIO_EXTI_Callback(GPIO_Pin); |
552 | HAL_GPIO_EXTI_Callback(GPIO_Pin); |
553 | } |
553 | } |
554 | } |
554 | } |
555 | 555 | ||
556 | /** |
556 | /** |
557 | * @brief EXTI line detection callbacks. |
557 | * @brief EXTI line detection callbacks. |
558 | * @param GPIO_Pin: Specifies the pins connected EXTI line |
558 | * @param GPIO_Pin: Specifies the pins connected EXTI line |
559 | * @retval None |
559 | * @retval None |
560 | */ |
560 | */ |
561 | __weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) |
561 | __weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) |
562 | { |
562 | { |
563 | /* Prevent unused argument(s) compilation warning */ |
563 | /* Prevent unused argument(s) compilation warning */ |
564 | UNUSED(GPIO_Pin); |
564 | UNUSED(GPIO_Pin); |
565 | /* NOTE: This function Should not be modified, when the callback is needed, |
565 | /* NOTE: This function Should not be modified, when the callback is needed, |
566 | the HAL_GPIO_EXTI_Callback could be implemented in the user file |
566 | the HAL_GPIO_EXTI_Callback could be implemented in the user file |
567 | */ |
567 | */ |
568 | } |
568 | } |
569 | 569 | ||
570 | /** |
570 | /** |
571 | * @} |
571 | * @} |
572 | */ |
572 | */ |
573 | 573 | ||
574 | /** |
574 | /** |
575 | * @} |
575 | * @} |
576 | */ |
576 | */ |
577 | 577 | ||
578 | #endif /* HAL_GPIO_MODULE_ENABLED */ |
578 | #endif /* HAL_GPIO_MODULE_ENABLED */ |
579 | /** |
579 | /** |
580 | * @} |
580 | * @} |
581 | */ |
581 | */ |
582 | 582 | ||
583 | /** |
583 | /** |
584 | * @} |
584 | * @} |
585 | */ |
585 | */ |
586 | 586 | ||
587 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
- |