2 ******************************************************************************
3 * @file stm32f4xx_gpio.h
4 * @author MCD Application Team
7 * @brief This file contains all the functions prototypes for the GPIO firmware
9 ******************************************************************************
12 * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
14 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
15 * You may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at:
18 * http://www.st.com/software_license_agreement_liberty_v2
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
26 ******************************************************************************
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F4xx_GPIO_H
31 #define __STM32F4xx_GPIO_H
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4xx.h"
40 /** @addtogroup STM32F4xx_StdPeriph_Driver
48 /* Exported types ------------------------------------------------------------*/
50 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
51 ((PERIPH) == GPIOB) || \
52 ((PERIPH) == GPIOC) || \
53 ((PERIPH) == GPIOD) || \
54 ((PERIPH) == GPIOE) || \
55 ((PERIPH) == GPIOF) || \
56 ((PERIPH) == GPIOG) || \
57 ((PERIPH) == GPIOH) || \
58 ((PERIPH) == GPIOI) || \
59 ((PERIPH) == GPIOJ) || \
63 * @brief GPIO Configuration Mode enumeration
67 GPIO_Mode_IN
= 0x00, /*!< GPIO Input Mode */
68 GPIO_Mode_OUT
= 0x01, /*!< GPIO Output Mode */
69 GPIO_Mode_AF
= 0x02, /*!< GPIO Alternate function Mode */
70 GPIO_Mode_AN
= 0x03 /*!< GPIO Analog Mode */
72 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN) || ((MODE) == GPIO_Mode_OUT) || \
73 ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
76 * @brief GPIO Output type enumeration
83 #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
87 * @brief GPIO Output Maximum frequency enumeration
91 GPIO_Low_Speed
= 0x00, /*!< Low speed */
92 GPIO_Medium_Speed
= 0x01, /*!< Medium speed */
93 GPIO_Fast_Speed
= 0x02, /*!< Fast speed */
94 GPIO_High_Speed
= 0x03 /*!< High speed */
97 /* Add legacy definition */
98 #define GPIO_Speed_2MHz GPIO_Low_Speed
99 #define GPIO_Speed_25MHz GPIO_Medium_Speed
100 #define GPIO_Speed_50MHz GPIO_Fast_Speed
101 #define GPIO_Speed_100MHz GPIO_High_Speed
103 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Low_Speed) || ((SPEED) == GPIO_Medium_Speed) || \
104 ((SPEED) == GPIO_Fast_Speed)|| ((SPEED) == GPIO_High_Speed))
107 * @brief GPIO Configuration PullUp PullDown enumeration
111 GPIO_PuPd_NOPULL
= 0x00,
113 GPIO_PuPd_DOWN
= 0x02
115 #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
116 ((PUPD) == GPIO_PuPd_DOWN))
119 * @brief GPIO Bit SET and Bit RESET enumeration
126 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
130 * @brief GPIO Init structure definition
134 uint32_t GPIO_Pin
; /*!< Specifies the GPIO pins to be configured.
135 This parameter can be any value of @ref GPIO_pins_define */
137 GPIOMode_TypeDef GPIO_Mode
; /*!< Specifies the operating mode for the selected pins.
138 This parameter can be a value of @ref GPIOMode_TypeDef */
140 GPIOSpeed_TypeDef GPIO_Speed
; /*!< Specifies the speed for the selected pins.
141 This parameter can be a value of @ref GPIOSpeed_TypeDef */
143 GPIOOType_TypeDef GPIO_OType
; /*!< Specifies the operating output type for the selected pins.
144 This parameter can be a value of @ref GPIOOType_TypeDef */
146 GPIOPuPd_TypeDef GPIO_PuPd
; /*!< Specifies the operating Pull-up/Pull down for the selected pins.
147 This parameter can be a value of @ref GPIOPuPd_TypeDef */
150 /* Exported constants --------------------------------------------------------*/
152 /** @defgroup GPIO_Exported_Constants
156 /** @defgroup GPIO_pins_define
159 #define GPIO_Pin_0 ((uint16_t)0x0001) /* Pin 0 selected */
160 #define GPIO_Pin_1 ((uint16_t)0x0002) /* Pin 1 selected */
161 #define GPIO_Pin_2 ((uint16_t)0x0004) /* Pin 2 selected */
162 #define GPIO_Pin_3 ((uint16_t)0x0008) /* Pin 3 selected */
163 #define GPIO_Pin_4 ((uint16_t)0x0010) /* Pin 4 selected */
164 #define GPIO_Pin_5 ((uint16_t)0x0020) /* Pin 5 selected */
165 #define GPIO_Pin_6 ((uint16_t)0x0040) /* Pin 6 selected */
166 #define GPIO_Pin_7 ((uint16_t)0x0080) /* Pin 7 selected */
167 #define GPIO_Pin_8 ((uint16_t)0x0100) /* Pin 8 selected */
168 #define GPIO_Pin_9 ((uint16_t)0x0200) /* Pin 9 selected */
169 #define GPIO_Pin_10 ((uint16_t)0x0400) /* Pin 10 selected */
170 #define GPIO_Pin_11 ((uint16_t)0x0800) /* Pin 11 selected */
171 #define GPIO_Pin_12 ((uint16_t)0x1000) /* Pin 12 selected */
172 #define GPIO_Pin_13 ((uint16_t)0x2000) /* Pin 13 selected */
173 #define GPIO_Pin_14 ((uint16_t)0x4000) /* Pin 14 selected */
174 #define GPIO_Pin_15 ((uint16_t)0x8000) /* Pin 15 selected */
175 #define GPIO_Pin_All ((uint16_t)0xFFFF) /* All pins selected */
177 #define GPIO_PIN_MASK ((uint32_t)0x0000FFFF) /* PIN mask for assert test */
178 #define IS_GPIO_PIN(PIN) (((PIN) & GPIO_PIN_MASK ) != (uint32_t)0x00)
179 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
180 ((PIN) == GPIO_Pin_1) || \
181 ((PIN) == GPIO_Pin_2) || \
182 ((PIN) == GPIO_Pin_3) || \
183 ((PIN) == GPIO_Pin_4) || \
184 ((PIN) == GPIO_Pin_5) || \
185 ((PIN) == GPIO_Pin_6) || \
186 ((PIN) == GPIO_Pin_7) || \
187 ((PIN) == GPIO_Pin_8) || \
188 ((PIN) == GPIO_Pin_9) || \
189 ((PIN) == GPIO_Pin_10) || \
190 ((PIN) == GPIO_Pin_11) || \
191 ((PIN) == GPIO_Pin_12) || \
192 ((PIN) == GPIO_Pin_13) || \
193 ((PIN) == GPIO_Pin_14) || \
194 ((PIN) == GPIO_Pin_15))
200 /** @defgroup GPIO_Pin_sources
203 #define GPIO_PinSource0 ((uint8_t)0x00)
204 #define GPIO_PinSource1 ((uint8_t)0x01)
205 #define GPIO_PinSource2 ((uint8_t)0x02)
206 #define GPIO_PinSource3 ((uint8_t)0x03)
207 #define GPIO_PinSource4 ((uint8_t)0x04)
208 #define GPIO_PinSource5 ((uint8_t)0x05)
209 #define GPIO_PinSource6 ((uint8_t)0x06)
210 #define GPIO_PinSource7 ((uint8_t)0x07)
211 #define GPIO_PinSource8 ((uint8_t)0x08)
212 #define GPIO_PinSource9 ((uint8_t)0x09)
213 #define GPIO_PinSource10 ((uint8_t)0x0A)
214 #define GPIO_PinSource11 ((uint8_t)0x0B)
215 #define GPIO_PinSource12 ((uint8_t)0x0C)
216 #define GPIO_PinSource13 ((uint8_t)0x0D)
217 #define GPIO_PinSource14 ((uint8_t)0x0E)
218 #define GPIO_PinSource15 ((uint8_t)0x0F)
220 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
221 ((PINSOURCE) == GPIO_PinSource1) || \
222 ((PINSOURCE) == GPIO_PinSource2) || \
223 ((PINSOURCE) == GPIO_PinSource3) || \
224 ((PINSOURCE) == GPIO_PinSource4) || \
225 ((PINSOURCE) == GPIO_PinSource5) || \
226 ((PINSOURCE) == GPIO_PinSource6) || \
227 ((PINSOURCE) == GPIO_PinSource7) || \
228 ((PINSOURCE) == GPIO_PinSource8) || \
229 ((PINSOURCE) == GPIO_PinSource9) || \
230 ((PINSOURCE) == GPIO_PinSource10) || \
231 ((PINSOURCE) == GPIO_PinSource11) || \
232 ((PINSOURCE) == GPIO_PinSource12) || \
233 ((PINSOURCE) == GPIO_PinSource13) || \
234 ((PINSOURCE) == GPIO_PinSource14) || \
235 ((PINSOURCE) == GPIO_PinSource15))
240 /** @defgroup GPIO_Alternat_function_selection_define
244 * @brief AF 0 selection
246 #define GPIO_AF_RTC_50Hz ((uint8_t)0x00) /* RTC_50Hz Alternate Function mapping */
247 #define GPIO_AF_MCO ((uint8_t)0x00) /* MCO (MCO1 and MCO2) Alternate Function mapping */
248 #define GPIO_AF_TAMPER ((uint8_t)0x00) /* TAMPER (TAMPER_1 and TAMPER_2) Alternate Function mapping */
249 #define GPIO_AF_SWJ ((uint8_t)0x00) /* SWJ (SWD and JTAG) Alternate Function mapping */
250 #define GPIO_AF_TRACE ((uint8_t)0x00) /* TRACE Alternate Function mapping */
251 #if defined(STM32F446xx)
252 #define GPIO_AF0_TIM2 ((uint8_t)0x00) /* TIM2 Alternate Function mapping */
253 #endif /* STM32F446xx */
256 * @brief AF 1 selection
258 #define GPIO_AF_TIM1 ((uint8_t)0x01) /* TIM1 Alternate Function mapping */
259 #define GPIO_AF_TIM2 ((uint8_t)0x01) /* TIM2 Alternate Function mapping */
260 #if defined(STM32F410xx)
261 #define GPIO_AF_LPTIM ((uint8_t)0x01) /* LPTIM Alternate Function mapping */
262 #endif /* STM32F410xx */
264 * @brief AF 2 selection
266 #define GPIO_AF_TIM3 ((uint8_t)0x02) /* TIM3 Alternate Function mapping */
267 #define GPIO_AF_TIM4 ((uint8_t)0x02) /* TIM4 Alternate Function mapping */
268 #define GPIO_AF_TIM5 ((uint8_t)0x02) /* TIM5 Alternate Function mapping */
271 * @brief AF 3 selection
273 #define GPIO_AF_TIM8 ((uint8_t)0x03) /* TIM8 Alternate Function mapping */
274 #define GPIO_AF_TIM9 ((uint8_t)0x03) /* TIM9 Alternate Function mapping */
275 #define GPIO_AF_TIM10 ((uint8_t)0x03) /* TIM10 Alternate Function mapping */
276 #define GPIO_AF_TIM11 ((uint8_t)0x03) /* TIM11 Alternate Function mapping */
277 #if defined(STM32F446xx)
278 #define GPIO_AF3_CEC ((uint8_t)0x03) /* CEC Alternate Function mapping */
279 #endif /* STM32F446xx */
281 * @brief AF 4 selection
283 #define GPIO_AF_I2C1 ((uint8_t)0x04) /* I2C1 Alternate Function mapping */
284 #define GPIO_AF_I2C2 ((uint8_t)0x04) /* I2C2 Alternate Function mapping */
285 #define GPIO_AF_I2C3 ((uint8_t)0x04) /* I2C3 Alternate Function mapping */
286 #if defined(STM32F446xx)
287 #define GPIO_AF4_CEC ((uint8_t)0x04) /* CEC Alternate Function mapping */
288 #endif /* STM32F446xx */
289 #if defined(STM32F410xx) || defined(STM32F412xG) || defined(STM32F446xx)
290 #define GPIO_AF_FMPI2C ((uint8_t)0x04) /* FMPI2C Alternate Function mapping */
291 #endif /* STM32F410xx || STM32F446xx */
294 * @brief AF 5 selection
296 #define GPIO_AF_SPI1 ((uint8_t)0x05) /* SPI1/I2S1 Alternate Function mapping */
297 #define GPIO_AF_SPI2 ((uint8_t)0x05) /* SPI2/I2S2 Alternate Function mapping */
298 #define GPIO_AF5_SPI3 ((uint8_t)0x05) /* SPI3/I2S3 Alternate Function mapping (Only for STM32F411xE Devices) */
299 #define GPIO_AF_SPI4 ((uint8_t)0x05) /* SPI4/I2S4 Alternate Function mapping */
300 #define GPIO_AF_SPI5 ((uint8_t)0x05) /* SPI5 Alternate Function mapping */
301 #define GPIO_AF_SPI6 ((uint8_t)0x05) /* SPI6 Alternate Function mapping */
304 * @brief AF 6 selection
306 #define GPIO_AF_SPI3 ((uint8_t)0x06) /* SPI3/I2S3 Alternate Function mapping */
307 #define GPIO_AF6_SPI1 ((uint8_t)0x06) /* SPI1 Alternate Function mapping (Only for STM32F410xx Devices) */
308 #define GPIO_AF6_SPI2 ((uint8_t)0x06) /* SPI2 Alternate Function mapping (Only for STM32F410xx/STM32F411xE Devices) */
309 #define GPIO_AF6_SPI4 ((uint8_t)0x06) /* SPI4 Alternate Function mapping (Only for STM32F411xE Devices) */
310 #define GPIO_AF6_SPI5 ((uint8_t)0x06) /* SPI5 Alternate Function mapping (Only for STM32F410xx/STM32F411xE Devices) */
311 #define GPIO_AF_SAI1 ((uint8_t)0x06) /* SAI1 Alternate Function mapping */
312 #define GPIO_AF_I2S2ext ((uint8_t)0x06) /* I2S2ext_SD Alternate Function mapping (only for STM32F412xG Devices) */
313 #if defined(STM32F412xG)
314 #define GPIO_AF6_DFSDM1 ((uint8_t)0x06) /* DFSDM Alternate Function mapping */
315 #endif /* STM32F412xG */
318 * @brief AF 7 selection
320 #define GPIO_AF_USART1 ((uint8_t)0x07) /* USART1 Alternate Function mapping */
321 #define GPIO_AF_USART2 ((uint8_t)0x07) /* USART2 Alternate Function mapping */
322 #define GPIO_AF_USART3 ((uint8_t)0x07) /* USART3 Alternate Function mapping */
323 #define GPIO_AF7_SPI3 ((uint8_t)0x07) /* SPI3/I2S3ext Alternate Function mapping */
326 * @brief AF 7 selection Legacy
328 #define GPIO_AF_I2S3ext GPIO_AF7_SPI3
331 * @brief AF 8 selection
333 #define GPIO_AF_UART4 ((uint8_t)0x08) /* UART4 Alternate Function mapping */
334 #define GPIO_AF_UART5 ((uint8_t)0x08) /* UART5 Alternate Function mapping */
335 #define GPIO_AF_USART6 ((uint8_t)0x08) /* USART6 Alternate Function mapping */
336 #define GPIO_AF_UART7 ((uint8_t)0x08) /* UART7 Alternate Function mapping */
337 #define GPIO_AF_UART8 ((uint8_t)0x08) /* UART8 Alternate Function mapping */
338 #if defined(STM32F412xG)
339 #define GPIO_AF8_USART3 ((uint8_t)0x08) /* USART3 Alternate Function mapping */
340 #define GPIO_AF8_DFSDM1 ((uint8_t)0x08) /* DFSDM Alternate Function mapping */
341 #define GPIO_AF8_CAN1 ((uint8_t)0x08) /* CAN1 Alternate Function mapping */
342 #endif /* STM32F412xG */
343 #if defined(STM32F446xx)
344 #define GPIO_AF8_SAI2 ((uint8_t)0x08) /* SAI2 Alternate Function mapping */
345 #define GPIO_AF_SPDIF ((uint8_t)0x08) /* SPDIF Alternate Function mapping */
346 #endif /* STM32F446xx */
349 * @brief AF 9 selection
351 #define GPIO_AF_CAN1 ((uint8_t)0x09) /* CAN1 Alternate Function mapping */
352 #define GPIO_AF_CAN2 ((uint8_t)0x09) /* CAN2 Alternate Function mapping */
353 #define GPIO_AF_TIM12 ((uint8_t)0x09) /* TIM12 Alternate Function mapping */
354 #define GPIO_AF_TIM13 ((uint8_t)0x09) /* TIM13 Alternate Function mapping */
355 #define GPIO_AF_TIM14 ((uint8_t)0x09) /* TIM14 Alternate Function mapping */
356 #define GPIO_AF9_I2C2 ((uint8_t)0x09) /* I2C2 Alternate Function mapping (Only for STM32F401xx/STM32F410xx/STM32F411xE/STM32F412xG Devices) */
357 #define GPIO_AF9_I2C3 ((uint8_t)0x09) /* I2C3 Alternate Function mapping (Only for STM32F401xx/STM32F411xE/STM32F412xG Devices) */
358 #if defined(STM32F446xx)
359 #define GPIO_AF9_SAI2 ((uint8_t)0x09) /* SAI2 Alternate Function mapping */
360 #endif /* STM32F446xx */
361 #define GPIO_AF9_LTDC ((uint8_t)0x09) /* LTDC Alternate Function mapping */
362 #if defined(STM32F412xG) || defined(STM32F446xx) || defined(STM32F469_479xx)
363 #define GPIO_AF9_QUADSPI ((uint8_t)0x09) /* QuadSPI Alternate Function mapping */
364 #endif /* STM32F412xG || STM32F446xx || STM32F469_479xx */
365 #if defined(STM32F410xx) || defined(STM32F412xG)
366 #define GPIO_AF9_FMPI2C ((uint8_t)0x09) /* FMPI2C Alternate Function mapping (Only for STM32F410xx Devices) */
367 #endif /* STM32F410xx || STM32F412xG */
370 * @brief AF 10 selection
372 #define GPIO_AF_OTG_FS ((uint8_t)0xA) /* OTG_FS Alternate Function mapping */
373 #define GPIO_AF_OTG_HS ((uint8_t)0xA) /* OTG_HS Alternate Function mapping */
374 #if defined(STM32F446xx)
375 #define GPIO_AF10_SAI2 ((uint8_t)0x0A) /* SAI2 Alternate Function mapping */
376 #endif /* STM32F446xx */
377 #if defined(STM32F412xG) || defined(STM32F446xx) || defined(STM32F469_479xx)
378 #define GPIO_AF10_QUADSPI ((uint8_t)0x0A) /* QuadSPI Alternate Function mapping */
379 #endif /* STM32F412xG || STM32F446xx || STM32F469_479xx */
380 #if defined(STM32F412xG)
381 #define GPIO_AF10_FMC ((uint8_t)0xA) /* FMC Alternate Function mapping */
382 #define GPIO_AF10_DFSDM ((uint8_t)0xA) /* DFSDM Alternate Function mapping */
383 #endif /* STM32F412xG */
385 * @brief AF 11 selection
387 #define GPIO_AF_ETH ((uint8_t)0x0B) /* ETHERNET Alternate Function mapping */
390 * @brief AF 12 selection
392 #if defined(STM32F40_41xxx) || defined(STM32F412xG)
393 #define GPIO_AF_FSMC ((uint8_t)0xC) /* FSMC Alternate Function mapping */
394 #endif /* STM32F40_41xxx || STM32F412xG */
396 #if defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F446xx) || defined(STM32F469_479xx)
397 #define GPIO_AF_FMC ((uint8_t)0xC) /* FMC Alternate Function mapping */
398 #endif /* STM32F427_437xx || STM32F429_439xx || STM32F446xx || STM32F469_479xx */
400 #define GPIO_AF_OTG_HS_FS ((uint8_t)0xC) /* OTG HS configured in FS, Alternate Function mapping */
401 #define GPIO_AF_SDIO ((uint8_t)0xC) /* SDIO Alternate Function mapping */
404 * @brief AF 13 selection
406 #define GPIO_AF_DCMI ((uint8_t)0x0D) /* DCMI Alternate Function mapping */
407 #if defined(STM32F469_479xx)
408 #define GPIO_AF_DSI ((uint8_t)0x0D) /* DSI Alternate Function mapping */
409 #endif /* STM32F469_479xx */
411 * @brief AF 14 selection
413 #define GPIO_AF_LTDC ((uint8_t)0x0E) /* LCD-TFT Alternate Function mapping */
416 * @brief AF 15 selection
418 #define GPIO_AF_EVENTOUT ((uint8_t)0x0F) /* EVENTOUT Alternate Function mapping */
420 #if defined(STM32F40_41xxx)
421 #define IS_GPIO_AF(AF) (((AF) == GPIO_AF_RTC_50Hz) || ((AF) == GPIO_AF_TIM14) || \
422 ((AF) == GPIO_AF_MCO) || ((AF) == GPIO_AF_TAMPER) || \
423 ((AF) == GPIO_AF_SWJ) || ((AF) == GPIO_AF_TRACE) || \
424 ((AF) == GPIO_AF_TIM1) || ((AF) == GPIO_AF_TIM2) || \
425 ((AF) == GPIO_AF_TIM3) || ((AF) == GPIO_AF_TIM4) || \
426 ((AF) == GPIO_AF_TIM5) || ((AF) == GPIO_AF_TIM8) || \
427 ((AF) == GPIO_AF_I2C1) || ((AF) == GPIO_AF_I2C2) || \
428 ((AF) == GPIO_AF_I2C3) || ((AF) == GPIO_AF_SPI1) || \
429 ((AF) == GPIO_AF_SPI2) || ((AF) == GPIO_AF_TIM13) || \
430 ((AF) == GPIO_AF_SPI3) || ((AF) == GPIO_AF_TIM14) || \
431 ((AF) == GPIO_AF_USART1) || ((AF) == GPIO_AF_USART2) || \
432 ((AF) == GPIO_AF_USART3) || ((AF) == GPIO_AF_UART4) || \
433 ((AF) == GPIO_AF_UART5) || ((AF) == GPIO_AF_USART6) || \
434 ((AF) == GPIO_AF_CAN1) || ((AF) == GPIO_AF_CAN2) || \
435 ((AF) == GPIO_AF_OTG_FS) || ((AF) == GPIO_AF_OTG_HS) || \
436 ((AF) == GPIO_AF_ETH) || ((AF) == GPIO_AF_OTG_HS_FS) || \
437 ((AF) == GPIO_AF_SDIO) || ((AF) == GPIO_AF_DCMI) || \
438 ((AF) == GPIO_AF_EVENTOUT) || ((AF) == GPIO_AF_FSMC))
439 #endif /* STM32F40_41xxx */
441 #if defined(STM32F401xx)
442 #define IS_GPIO_AF(AF) (((AF) == GPIO_AF_RTC_50Hz) || ((AF) == GPIO_AF_TIM14) || \
443 ((AF) == GPIO_AF_MCO) || ((AF) == GPIO_AF_TAMPER) || \
444 ((AF) == GPIO_AF_SWJ) || ((AF) == GPIO_AF_TRACE) || \
445 ((AF) == GPIO_AF_TIM1) || ((AF) == GPIO_AF_TIM2) || \
446 ((AF) == GPIO_AF_TIM3) || ((AF) == GPIO_AF_TIM4) || \
447 ((AF) == GPIO_AF_TIM5) || ((AF) == GPIO_AF_TIM8) || \
448 ((AF) == GPIO_AF_I2C1) || ((AF) == GPIO_AF_I2C2) || \
449 ((AF) == GPIO_AF_I2C3) || ((AF) == GPIO_AF_SPI1) || \
450 ((AF) == GPIO_AF_SPI2) || ((AF) == GPIO_AF_TIM13) || \
451 ((AF) == GPIO_AF_SPI3) || ((AF) == GPIO_AF_TIM14) || \
452 ((AF) == GPIO_AF_USART1) || ((AF) == GPIO_AF_USART2) || \
453 ((AF) == GPIO_AF_SDIO) || ((AF) == GPIO_AF_USART6) || \
454 ((AF) == GPIO_AF_OTG_FS) || ((AF) == GPIO_AF_OTG_HS) || \
455 ((AF) == GPIO_AF_EVENTOUT) || ((AF) == GPIO_AF_SPI4))
456 #endif /* STM32F401xx */
458 #if defined(STM32F411xE)
459 #define IS_GPIO_AF(AF) (((AF) < 16) && ((AF) != 11) && ((AF) != 13) && ((AF) != 14))
460 #endif /* STM32F411xE */
462 #if defined(STM32F410xx)
463 #define IS_GPIO_AF(AF) (((AF) < 10) || ((AF) == 15))
464 #endif /* STM32F410xx */
466 #if defined(STM32F427_437xx) || defined(STM32F429_439xx)
467 #define IS_GPIO_AF(AF) (((AF) == GPIO_AF_RTC_50Hz) || ((AF) == GPIO_AF_TIM14) || \
468 ((AF) == GPIO_AF_MCO) || ((AF) == GPIO_AF_TAMPER) || \
469 ((AF) == GPIO_AF_SWJ) || ((AF) == GPIO_AF_TRACE) || \
470 ((AF) == GPIO_AF_TIM1) || ((AF) == GPIO_AF_TIM2) || \
471 ((AF) == GPIO_AF_TIM3) || ((AF) == GPIO_AF_TIM4) || \
472 ((AF) == GPIO_AF_TIM5) || ((AF) == GPIO_AF_TIM8) || \
473 ((AF) == GPIO_AF_I2C1) || ((AF) == GPIO_AF_I2C2) || \
474 ((AF) == GPIO_AF_I2C3) || ((AF) == GPIO_AF_SPI1) || \
475 ((AF) == GPIO_AF_SPI2) || ((AF) == GPIO_AF_TIM13) || \
476 ((AF) == GPIO_AF_SPI3) || ((AF) == GPIO_AF_TIM14) || \
477 ((AF) == GPIO_AF_USART1) || ((AF) == GPIO_AF_USART2) || \
478 ((AF) == GPIO_AF_USART3) || ((AF) == GPIO_AF_UART4) || \
479 ((AF) == GPIO_AF_UART5) || ((AF) == GPIO_AF_USART6) || \
480 ((AF) == GPIO_AF_CAN1) || ((AF) == GPIO_AF_CAN2) || \
481 ((AF) == GPIO_AF_OTG_FS) || ((AF) == GPIO_AF_OTG_HS) || \
482 ((AF) == GPIO_AF_ETH) || ((AF) == GPIO_AF_OTG_HS_FS) || \
483 ((AF) == GPIO_AF_SDIO) || ((AF) == GPIO_AF_DCMI) || \
484 ((AF) == GPIO_AF_EVENTOUT) || ((AF) == GPIO_AF_SPI4) || \
485 ((AF) == GPIO_AF_SPI5) || ((AF) == GPIO_AF_SPI6) || \
486 ((AF) == GPIO_AF_UART7) || ((AF) == GPIO_AF_UART8) || \
487 ((AF) == GPIO_AF_FMC) || ((AF) == GPIO_AF_SAI1) || \
488 ((AF) == GPIO_AF_LTDC))
489 #endif /* STM32F427_437xx || STM32F429_439xx */
491 #if defined(STM32F412xG)
492 #define IS_GPIO_AF(AF) (((AF) < 16) && ((AF) != 11) && ((AF) != 14))
493 #endif /* STM32F412xG */
495 #if defined(STM32F446xx)
496 #define IS_GPIO_AF(AF) (((AF) < 16) && ((AF) != 11) && ((AF) != 14))
497 #endif /* STM32F446xx */
499 #if defined(STM32F469_479xx)
500 #define IS_GPIO_AF(AF) ((AF) < 16)
501 #endif /* STM32F469_479xx */
507 /** @defgroup GPIO_Legacy
511 #define GPIO_Mode_AIN GPIO_Mode_AN
513 #define GPIO_AF_OTG1_FS GPIO_AF_OTG_FS
514 #define GPIO_AF_OTG2_HS GPIO_AF_OTG_HS
515 #define GPIO_AF_OTG2_FS GPIO_AF_OTG_HS_FS
525 /* Exported macro ------------------------------------------------------------*/
526 /* Exported functions --------------------------------------------------------*/
528 /* Function used to set the GPIO configuration to the default reset state ****/
529 void GPIO_DeInit(GPIO_TypeDef
* GPIOx
);
531 /* Initialization and Configuration functions *********************************/
532 void GPIO_Init(GPIO_TypeDef
* GPIOx
, GPIO_InitTypeDef
* GPIO_InitStruct
);
533 void GPIO_StructInit(GPIO_InitTypeDef
* GPIO_InitStruct
);
534 void GPIO_PinLockConfig(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
536 /* GPIO Read and Write functions **********************************************/
537 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
538 uint16_t GPIO_ReadInputData(GPIO_TypeDef
* GPIOx
);
539 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
540 uint16_t GPIO_ReadOutputData(GPIO_TypeDef
* GPIOx
);
541 void GPIO_SetBits(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
542 void GPIO_ResetBits(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
543 void GPIO_WriteBit(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
, BitAction BitVal
);
544 void GPIO_Write(GPIO_TypeDef
* GPIOx
, uint16_t PortVal
);
545 void GPIO_ToggleBits(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
547 /* GPIO Alternate functions configuration function ****************************/
548 void GPIO_PinAFConfig(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_PinSource
, uint8_t GPIO_AF
);
554 #endif /*__STM32F4xx_GPIO_H */
564 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/