ARMEBS4  revision-26.06.2015
stm32f4xx_gpio.h
Go to the documentation of this file.
1 /**
2  ******************************************************************************
3  * @file stm32f4xx_gpio.h
4  * @author MCD Application Team
5  * @version V1.0.0
6  * @date 30-September-2011
7  * @brief This file contains all the functions prototypes for the GPIO firmware
8  * library.
9  ******************************************************************************
10  * @attention
11  *
12  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18  *
19  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
20  ******************************************************************************
21  */
22 
23 /* Define to prevent recursive inclusion -------------------------------------*/
24 #ifndef __STM32F4xx_GPIO_H
25 #define __STM32F4xx_GPIO_H
26 
27 #ifdef __cplusplus
28  extern "C" {
29 #endif
30 
31 /* Includes ------------------------------------------------------------------*/
32 #include "stm32/stm32f4xx.h"
33 
34 /** @addtogroup STM32F4xx_StdPeriph_Driver
35  * @{
36  */
37 
38 /** @addtogroup GPIO
39  * @{
40  */
41 
42 /* Exported types ------------------------------------------------------------*/
43 
44 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
45  ((PERIPH) == GPIOB) || \
46  ((PERIPH) == GPIOC) || \
47  ((PERIPH) == GPIOD) || \
48  ((PERIPH) == GPIOE) || \
49  ((PERIPH) == GPIOF) || \
50  ((PERIPH) == GPIOG) || \
51  ((PERIPH) == GPIOH) || \
52  ((PERIPH) == GPIOI))
53 
54 /**
55  * @brief GPIO Configuration Mode enumeration
56  */
57 typedef enum
58 {
59  GPIO_Mode_IN = 0x00, /*!< GPIO Input Mode */
60  GPIO_Mode_OUT = 0x01, /*!< GPIO Output Mode */
61  GPIO_Mode_AF = 0x02, /*!< GPIO Alternate function Mode */
62  GPIO_Mode_AN = 0x03 /*!< GPIO Analog Mode */
64 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN) || ((MODE) == GPIO_Mode_OUT) || \
65  ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
66 
67 /**
68  * @brief GPIO Output type enumeration
69  */
70 typedef enum
71 {
72  GPIO_OType_PP = 0x00,
73  GPIO_OType_OD = 0x01
75 #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
76 
77 
78 /**
79  * @brief GPIO Output Maximum frequency enumeration
80  */
81 typedef enum
82 {
83  GPIO_Speed_2MHz = 0x00, /*!< Low speed */
84  GPIO_Speed_25MHz = 0x01, /*!< Medium speed */
85  GPIO_Speed_50MHz = 0x02, /*!< Fast speed */
86  GPIO_Speed_100MHz = 0x03 /*!< High speed on 30 pF (80 MHz Output max speed on 15 pF) */
88 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_2MHz) || ((SPEED) == GPIO_Speed_25MHz) || \
89  ((SPEED) == GPIO_Speed_50MHz)|| ((SPEED) == GPIO_Speed_100MHz))
90 
91 /**
92  * @brief GPIO Configuration PullUp PullDown enumeration
93  */
94 typedef enum
95 {
96  GPIO_PuPd_NOPULL = 0x00,
97  GPIO_PuPd_UP = 0x01,
98  GPIO_PuPd_DOWN = 0x02
100 #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
101  ((PUPD) == GPIO_PuPd_DOWN))
102 
103 /**
104  * @brief GPIO Bit SET and Bit RESET enumeration
105  */
106 typedef enum
107 {
108  Bit_RESET = 0,
109  Bit_SET
110 }BitAction;
111 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
112 
113 
114 /**
115  * @brief GPIO Init structure definition
116  */
117 typedef struct
118 {
119  uint32_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
120  This parameter can be any value of @ref GPIO_pins_define */
121 
122  GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
123  This parameter can be a value of @ref GPIOMode_TypeDef */
124 
125  GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
126  This parameter can be a value of @ref GPIOSpeed_TypeDef */
127 
128  GPIOOType_TypeDef GPIO_OType; /*!< Specifies the operating output type for the selected pins.
129  This parameter can be a value of @ref GPIOOType_TypeDef */
130 
131  GPIOPuPd_TypeDef GPIO_PuPd; /*!< Specifies the operating Pull-up/Pull down for the selected pins.
132  This parameter can be a value of @ref GPIOPuPd_TypeDef */
134 
135 /* Exported constants --------------------------------------------------------*/
136 
137 /** @defgroup GPIO_Exported_Constants
138  * @{
139  */
140 
141 /** @defgroup GPIO_pins_define
142  * @{
143  */
144 #define GPIO_Pin_0 ((uint16_t)0x0001) /* Pin 0 selected */
145 #define GPIO_Pin_1 ((uint16_t)0x0002) /* Pin 1 selected */
146 #define GPIO_Pin_2 ((uint16_t)0x0004) /* Pin 2 selected */
147 #define GPIO_Pin_3 ((uint16_t)0x0008) /* Pin 3 selected */
148 #define GPIO_Pin_4 ((uint16_t)0x0010) /* Pin 4 selected */
149 #define GPIO_Pin_5 ((uint16_t)0x0020) /* Pin 5 selected */
150 #define GPIO_Pin_6 ((uint16_t)0x0040) /* Pin 6 selected */
151 #define GPIO_Pin_7 ((uint16_t)0x0080) /* Pin 7 selected */
152 #define GPIO_Pin_8 ((uint16_t)0x0100) /* Pin 8 selected */
153 #define GPIO_Pin_9 ((uint16_t)0x0200) /* Pin 9 selected */
154 #define GPIO_Pin_10 ((uint16_t)0x0400) /* Pin 10 selected */
155 #define GPIO_Pin_11 ((uint16_t)0x0800) /* Pin 11 selected */
156 #define GPIO_Pin_12 ((uint16_t)0x1000) /* Pin 12 selected */
157 #define GPIO_Pin_13 ((uint16_t)0x2000) /* Pin 13 selected */
158 #define GPIO_Pin_14 ((uint16_t)0x4000) /* Pin 14 selected */
159 #define GPIO_Pin_15 ((uint16_t)0x8000) /* Pin 15 selected */
160 #define GPIO_Pin_All ((uint16_t)0xFFFF) /* All pins selected */
161 
162 #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00))
163 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
164  ((PIN) == GPIO_Pin_1) || \
165  ((PIN) == GPIO_Pin_2) || \
166  ((PIN) == GPIO_Pin_3) || \
167  ((PIN) == GPIO_Pin_4) || \
168  ((PIN) == GPIO_Pin_5) || \
169  ((PIN) == GPIO_Pin_6) || \
170  ((PIN) == GPIO_Pin_7) || \
171  ((PIN) == GPIO_Pin_8) || \
172  ((PIN) == GPIO_Pin_9) || \
173  ((PIN) == GPIO_Pin_10) || \
174  ((PIN) == GPIO_Pin_11) || \
175  ((PIN) == GPIO_Pin_12) || \
176  ((PIN) == GPIO_Pin_13) || \
177  ((PIN) == GPIO_Pin_14) || \
178  ((PIN) == GPIO_Pin_15))
179 /**
180  * @}
181  */
182 
183 
184 /** @defgroup GPIO_Pin_sources
185  * @{
186  */
187 #define GPIO_PinSource0 ((uint8_t)0x00)
188 #define GPIO_PinSource1 ((uint8_t)0x01)
189 #define GPIO_PinSource2 ((uint8_t)0x02)
190 #define GPIO_PinSource3 ((uint8_t)0x03)
191 #define GPIO_PinSource4 ((uint8_t)0x04)
192 #define GPIO_PinSource5 ((uint8_t)0x05)
193 #define GPIO_PinSource6 ((uint8_t)0x06)
194 #define GPIO_PinSource7 ((uint8_t)0x07)
195 #define GPIO_PinSource8 ((uint8_t)0x08)
196 #define GPIO_PinSource9 ((uint8_t)0x09)
197 #define GPIO_PinSource10 ((uint8_t)0x0A)
198 #define GPIO_PinSource11 ((uint8_t)0x0B)
199 #define GPIO_PinSource12 ((uint8_t)0x0C)
200 #define GPIO_PinSource13 ((uint8_t)0x0D)
201 #define GPIO_PinSource14 ((uint8_t)0x0E)
202 #define GPIO_PinSource15 ((uint8_t)0x0F)
203 
204 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
205  ((PINSOURCE) == GPIO_PinSource1) || \
206  ((PINSOURCE) == GPIO_PinSource2) || \
207  ((PINSOURCE) == GPIO_PinSource3) || \
208  ((PINSOURCE) == GPIO_PinSource4) || \
209  ((PINSOURCE) == GPIO_PinSource5) || \
210  ((PINSOURCE) == GPIO_PinSource6) || \
211  ((PINSOURCE) == GPIO_PinSource7) || \
212  ((PINSOURCE) == GPIO_PinSource8) || \
213  ((PINSOURCE) == GPIO_PinSource9) || \
214  ((PINSOURCE) == GPIO_PinSource10) || \
215  ((PINSOURCE) == GPIO_PinSource11) || \
216  ((PINSOURCE) == GPIO_PinSource12) || \
217  ((PINSOURCE) == GPIO_PinSource13) || \
218  ((PINSOURCE) == GPIO_PinSource14) || \
219  ((PINSOURCE) == GPIO_PinSource15))
220 /**
221  * @}
222  */
223 
224 /** @defgroup GPIO_Alternat_function_selection_define
225  * @{
226  */
227 /**
228  * @brief AF 0 selection
229  */
230 #define GPIO_AF_RTC_50Hz ((uint8_t)0x00) /* RTC_50Hz Alternate Function mapping */
231 #define GPIO_AF_MCO ((uint8_t)0x00) /* MCO (MCO1 and MCO2) Alternate Function mapping */
232 #define GPIO_AF_TAMPER ((uint8_t)0x00) /* TAMPER (TAMPER_1 and TAMPER_2) Alternate Function mapping */
233 #define GPIO_AF_SWJ ((uint8_t)0x00) /* SWJ (SWD and JTAG) Alternate Function mapping */
234 #define GPIO_AF_TRACE ((uint8_t)0x00) /* TRACE Alternate Function mapping */
235 
236 /**
237  * @brief AF 1 selection
238  */
239 #define GPIO_AF_TIM1 ((uint8_t)0x01) /* TIM1 Alternate Function mapping */
240 #define GPIO_AF_TIM2 ((uint8_t)0x01) /* TIM2 Alternate Function mapping */
241 
242 /**
243  * @brief AF 2 selection
244  */
245 #define GPIO_AF_TIM3 ((uint8_t)0x02) /* TIM3 Alternate Function mapping */
246 #define GPIO_AF_TIM4 ((uint8_t)0x02) /* TIM4 Alternate Function mapping */
247 #define GPIO_AF_TIM5 ((uint8_t)0x02) /* TIM5 Alternate Function mapping */
248 
249 /**
250  * @brief AF 3 selection
251  */
252 #define GPIO_AF_TIM8 ((uint8_t)0x03) /* TIM8 Alternate Function mapping */
253 #define GPIO_AF_TIM9 ((uint8_t)0x03) /* TIM9 Alternate Function mapping */
254 #define GPIO_AF_TIM10 ((uint8_t)0x03) /* TIM10 Alternate Function mapping */
255 #define GPIO_AF_TIM11 ((uint8_t)0x03) /* TIM11 Alternate Function mapping */
256 
257 /**
258  * @brief AF 4 selection
259  */
260 #define GPIO_AF_I2C1 ((uint8_t)0x04) /* I2C1 Alternate Function mapping */
261 #define GPIO_AF_I2C2 ((uint8_t)0x04) /* I2C2 Alternate Function mapping */
262 #define GPIO_AF_I2C3 ((uint8_t)0x04) /* I2C3 Alternate Function mapping */
263 
264 /**
265  * @brief AF 5 selection
266  */
267 #define GPIO_AF_SPI1 ((uint8_t)0x05) /* SPI1 Alternate Function mapping */
268 #define GPIO_AF_SPI2 ((uint8_t)0x05) /* SPI2/I2S2 Alternate Function mapping */
269 
270 /**
271  * @brief AF 6 selection
272  */
273 #define GPIO_AF_SPI3 ((uint8_t)0x06) /* SPI3/I2S3 Alternate Function mapping */
274 
275 /**
276  * @brief AF 7 selection
277  */
278 #define GPIO_AF_USART1 ((uint8_t)0x07) /* USART1 Alternate Function mapping */
279 #define GPIO_AF_USART2 ((uint8_t)0x07) /* USART2 Alternate Function mapping */
280 #define GPIO_AF_USART3 ((uint8_t)0x07) /* USART3 Alternate Function mapping */
281 #define GPIO_AF_I2S3ext ((uint8_t)0x07) /* I2S3ext Alternate Function mapping */
282 
283 /**
284  * @brief AF 8 selection
285  */
286 #define GPIO_AF_UART4 ((uint8_t)0x08) /* UART4 Alternate Function mapping */
287 #define GPIO_AF_UART5 ((uint8_t)0x08) /* UART5 Alternate Function mapping */
288 #define GPIO_AF_USART6 ((uint8_t)0x08) /* USART6 Alternate Function mapping */
289 
290 /**
291  * @brief AF 9 selection
292  */
293 #define GPIO_AF_CAN1 ((uint8_t)0x09) /* CAN1 Alternate Function mapping */
294 #define GPIO_AF_CAN2 ((uint8_t)0x09) /* CAN2 Alternate Function mapping */
295 #define GPIO_AF_TIM12 ((uint8_t)0x09) /* TIM12 Alternate Function mapping */
296 #define GPIO_AF_TIM13 ((uint8_t)0x09) /* TIM13 Alternate Function mapping */
297 #define GPIO_AF_TIM14 ((uint8_t)0x09) /* TIM14 Alternate Function mapping */
298 
299 /**
300  * @brief AF 10 selection
301  */
302 #define GPIO_AF_OTG_FS ((uint8_t)0xA) /* OTG_FS Alternate Function mapping */
303 #define GPIO_AF_OTG_HS ((uint8_t)0xA) /* OTG_HS Alternate Function mapping */
304 
305 /**
306  * @brief AF 11 selection
307  */
308 #define GPIO_AF_ETH ((uint8_t)0x0B) /* ETHERNET Alternate Function mapping */
309 
310 /**
311  * @brief AF 12 selection
312  */
313 #define GPIO_AF_FSMC ((uint8_t)0xC) /* FSMC Alternate Function mapping */
314 #define GPIO_AF_OTG_HS_FS ((uint8_t)0xC) /* OTG HS configured in FS, Alternate Function mapping */
315 #define GPIO_AF_SDIO ((uint8_t)0xC) /* SDIO Alternate Function mapping */
316 
317 /**
318  * @brief AF 13 selection
319  */
320 #define GPIO_AF_DCMI ((uint8_t)0x0D) /* DCMI Alternate Function mapping */
321 
322 /**
323  * @brief AF 15 selection
324  */
325 #define GPIO_AF_EVENTOUT ((uint8_t)0x0F) /* EVENTOUT Alternate Function mapping */
326 
327 #define IS_GPIO_AF(AF) (((AF) == GPIO_AF_RTC_50Hz) || ((AF) == GPIO_AF_TIM14) || \
328  ((AF) == GPIO_AF_MCO) || ((AF) == GPIO_AF_TAMPER) || \
329  ((AF) == GPIO_AF_SWJ) || ((AF) == GPIO_AF_TRACE) || \
330  ((AF) == GPIO_AF_TIM1) || ((AF) == GPIO_AF_TIM2) || \
331  ((AF) == GPIO_AF_TIM3) || ((AF) == GPIO_AF_TIM4) || \
332  ((AF) == GPIO_AF_TIM5) || ((AF) == GPIO_AF_TIM8) || \
333  ((AF) == GPIO_AF_I2C1) || ((AF) == GPIO_AF_I2C2) || \
334  ((AF) == GPIO_AF_I2C3) || ((AF) == GPIO_AF_SPI1) || \
335  ((AF) == GPIO_AF_SPI2) || ((AF) == GPIO_AF_TIM13) || \
336  ((AF) == GPIO_AF_SPI3) || ((AF) == GPIO_AF_TIM14) || \
337  ((AF) == GPIO_AF_USART1) || ((AF) == GPIO_AF_USART2) || \
338  ((AF) == GPIO_AF_USART3) || ((AF) == GPIO_AF_UART4) || \
339  ((AF) == GPIO_AF_UART5) || ((AF) == GPIO_AF_USART6) || \
340  ((AF) == GPIO_AF_CAN1) || ((AF) == GPIO_AF_CAN2) || \
341  ((AF) == GPIO_AF_OTG_FS) || ((AF) == GPIO_AF_OTG_HS) || \
342  ((AF) == GPIO_AF_ETH) || ((AF) == GPIO_AF_FSMC) || \
343  ((AF) == GPIO_AF_OTG_HS_FS) || ((AF) == GPIO_AF_SDIO) || \
344  ((AF) == GPIO_AF_DCMI) || ((AF) == GPIO_AF_EVENTOUT))
345 /**
346  * @}
347  */
348 
349 /** @defgroup GPIO_Legacy
350  * @{
351  */
352 
353 #define GPIO_Mode_AIN GPIO_Mode_AN
354 
355 #define GPIO_AF_OTG1_FS GPIO_AF_OTG_FS
356 #define GPIO_AF_OTG2_HS GPIO_AF_OTG_HS
357 #define GPIO_AF_OTG2_FS GPIO_AF_OTG_HS_FS
358 
359 /**
360  * @}
361  */
362 
363 /**
364  * @}
365  */
366 
367 /* Exported macro ------------------------------------------------------------*/
368 /* Exported functions --------------------------------------------------------*/
369 
370 /* Function used to set the GPIO configuration to the default reset state ****/
371 void GPIO_DeInit(GPIO_TypeDef* GPIOx);
372 
373 /* Initialization and Configuration functions *********************************/
374 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
375 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
376 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
377 
378 /* GPIO Read and Write functions **********************************************/
379 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
380 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
381 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
382 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
383 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
384 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
385 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
386 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
387 void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
388 
389 /* GPIO Alternate functions configuration function ****************************/
390 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 
396 #endif /*__STM32F4xx_GPIO_H */
397 
398 /**
399  * @}
400  */
401 
402 /**
403  * @}
404  */
405 
406 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
GPIOPuPd_TypeDef
GPIO Configuration PullUp PullDown enumeration.
GPIOSpeed_TypeDef
GPIO Output Maximum frequency enumeration.
GPIOOType_TypeDef GPIO_OType
GPIOMode_TypeDef
GPIO Configuration Mode enumeration.
BitAction
GPIO Bit SET and Bit RESET enumeration.
GPIOSpeed_TypeDef GPIO_Speed
CMSIS Cortex-M4 Device Peripheral Access Layer Header File. This file contains all the peripheral reg...
Alternate function.
Definition: stm32_gpio.h:56
General Purpose I/O.
Definition: stm32f4xx.h:643
GPIO Init structure definition.
GPIOMode_TypeDef GPIO_Mode
GPIOOType_TypeDef
GPIO Output type enumeration.
GPIOPuPd_TypeDef GPIO_PuPd