Nut/OS  5.0.5
API Reference
stm32f4xx_gpio.h
Go to the documentation of this file.
00001 
00023 /* Define to prevent recursive inclusion -------------------------------------*/
00024 #ifndef __STM32F4xx_GPIO_H
00025 #define __STM32F4xx_GPIO_H
00026 
00027 #ifdef __cplusplus
00028  extern "C" {
00029 #endif
00030 
00031 /* Includes ------------------------------------------------------------------*/
00032 #include "stm32f4xx.h"
00033 
00042 /* Exported types ------------------------------------------------------------*/
00043 
00044 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
00045                                     ((PERIPH) == GPIOB) || \
00046                                     ((PERIPH) == GPIOC) || \
00047                                     ((PERIPH) == GPIOD) || \
00048                                     ((PERIPH) == GPIOE) || \
00049                                     ((PERIPH) == GPIOF) || \
00050                                     ((PERIPH) == GPIOG) || \
00051                                     ((PERIPH) == GPIOH) || \
00052                                     ((PERIPH) == GPIOI))
00053 
00057 typedef enum
00058 {
00059   GPIO_Mode_IN   = 0x00, 
00060   GPIO_Mode_OUT  = 0x01, 
00061   GPIO_Mode_AF   = 0x02, 
00062   GPIO_Mode_AN   = 0x03  
00063 }GPIOMode_TypeDef;
00064 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)  || ((MODE) == GPIO_Mode_OUT) || \
00065                             ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
00066 
00070 typedef enum
00071 {
00072   GPIO_OType_PP = 0x00,
00073   GPIO_OType_OD = 0x01
00074 }GPIOOType_TypeDef;
00075 #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
00076 
00077 
00081 typedef enum
00082 {
00083   GPIO_Speed_2MHz   = 0x00, 
00084   GPIO_Speed_25MHz  = 0x01, 
00085   GPIO_Speed_50MHz  = 0x02, 
00086   GPIO_Speed_100MHz = 0x03  
00087 }GPIOSpeed_TypeDef;
00088 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_2MHz) || ((SPEED) == GPIO_Speed_25MHz) || \
00089                               ((SPEED) == GPIO_Speed_50MHz)||  ((SPEED) == GPIO_Speed_100MHz))
00090 
00094 typedef enum
00095 {
00096   GPIO_PuPd_NOPULL = 0x00,
00097   GPIO_PuPd_UP     = 0x01,
00098   GPIO_PuPd_DOWN   = 0x02
00099 }GPIOPuPd_TypeDef;
00100 #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
00101                             ((PUPD) == GPIO_PuPd_DOWN))
00102 
00106 typedef enum
00107 {
00108   Bit_RESET = 0,
00109   Bit_SET
00110 }BitAction;
00111 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
00112 
00113 
00117 typedef struct
00118 {
00119   uint32_t GPIO_Pin;              
00122   GPIOMode_TypeDef GPIO_Mode;     
00125   GPIOSpeed_TypeDef GPIO_Speed;   
00128   GPIOOType_TypeDef GPIO_OType;   
00131   GPIOPuPd_TypeDef GPIO_PuPd;     
00133 }GPIO_InitTypeDef;
00134 
00135 /* Exported constants --------------------------------------------------------*/
00136 
00144 #define GPIO_Pin_0                 ((uint16_t)0x0001)  /* Pin 0 selected */
00145 #define GPIO_Pin_1                 ((uint16_t)0x0002)  /* Pin 1 selected */
00146 #define GPIO_Pin_2                 ((uint16_t)0x0004)  /* Pin 2 selected */
00147 #define GPIO_Pin_3                 ((uint16_t)0x0008)  /* Pin 3 selected */
00148 #define GPIO_Pin_4                 ((uint16_t)0x0010)  /* Pin 4 selected */
00149 #define GPIO_Pin_5                 ((uint16_t)0x0020)  /* Pin 5 selected */
00150 #define GPIO_Pin_6                 ((uint16_t)0x0040)  /* Pin 6 selected */
00151 #define GPIO_Pin_7                 ((uint16_t)0x0080)  /* Pin 7 selected */
00152 #define GPIO_Pin_8                 ((uint16_t)0x0100)  /* Pin 8 selected */
00153 #define GPIO_Pin_9                 ((uint16_t)0x0200)  /* Pin 9 selected */
00154 #define GPIO_Pin_10                ((uint16_t)0x0400)  /* Pin 10 selected */
00155 #define GPIO_Pin_11                ((uint16_t)0x0800)  /* Pin 11 selected */
00156 #define GPIO_Pin_12                ((uint16_t)0x1000)  /* Pin 12 selected */
00157 #define GPIO_Pin_13                ((uint16_t)0x2000)  /* Pin 13 selected */
00158 #define GPIO_Pin_14                ((uint16_t)0x4000)  /* Pin 14 selected */
00159 #define GPIO_Pin_15                ((uint16_t)0x8000)  /* Pin 15 selected */
00160 #define GPIO_Pin_All               ((uint16_t)0xFFFF)  /* All pins selected */
00161 
00162 #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00))
00163 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
00164                               ((PIN) == GPIO_Pin_1) || \
00165                               ((PIN) == GPIO_Pin_2) || \
00166                               ((PIN) == GPIO_Pin_3) || \
00167                               ((PIN) == GPIO_Pin_4) || \
00168                               ((PIN) == GPIO_Pin_5) || \
00169                               ((PIN) == GPIO_Pin_6) || \
00170                               ((PIN) == GPIO_Pin_7) || \
00171                               ((PIN) == GPIO_Pin_8) || \
00172                               ((PIN) == GPIO_Pin_9) || \
00173                               ((PIN) == GPIO_Pin_10) || \
00174                               ((PIN) == GPIO_Pin_11) || \
00175                               ((PIN) == GPIO_Pin_12) || \
00176                               ((PIN) == GPIO_Pin_13) || \
00177                               ((PIN) == GPIO_Pin_14) || \
00178                               ((PIN) == GPIO_Pin_15))
00179 
00187 #define GPIO_PinSource0            ((uint8_t)0x00)
00188 #define GPIO_PinSource1            ((uint8_t)0x01)
00189 #define GPIO_PinSource2            ((uint8_t)0x02)
00190 #define GPIO_PinSource3            ((uint8_t)0x03)
00191 #define GPIO_PinSource4            ((uint8_t)0x04)
00192 #define GPIO_PinSource5            ((uint8_t)0x05)
00193 #define GPIO_PinSource6            ((uint8_t)0x06)
00194 #define GPIO_PinSource7            ((uint8_t)0x07)
00195 #define GPIO_PinSource8            ((uint8_t)0x08)
00196 #define GPIO_PinSource9            ((uint8_t)0x09)
00197 #define GPIO_PinSource10           ((uint8_t)0x0A)
00198 #define GPIO_PinSource11           ((uint8_t)0x0B)
00199 #define GPIO_PinSource12           ((uint8_t)0x0C)
00200 #define GPIO_PinSource13           ((uint8_t)0x0D)
00201 #define GPIO_PinSource14           ((uint8_t)0x0E)
00202 #define GPIO_PinSource15           ((uint8_t)0x0F)
00203 
00204 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
00205                                        ((PINSOURCE) == GPIO_PinSource1) || \
00206                                        ((PINSOURCE) == GPIO_PinSource2) || \
00207                                        ((PINSOURCE) == GPIO_PinSource3) || \
00208                                        ((PINSOURCE) == GPIO_PinSource4) || \
00209                                        ((PINSOURCE) == GPIO_PinSource5) || \
00210                                        ((PINSOURCE) == GPIO_PinSource6) || \
00211                                        ((PINSOURCE) == GPIO_PinSource7) || \
00212                                        ((PINSOURCE) == GPIO_PinSource8) || \
00213                                        ((PINSOURCE) == GPIO_PinSource9) || \
00214                                        ((PINSOURCE) == GPIO_PinSource10) || \
00215                                        ((PINSOURCE) == GPIO_PinSource11) || \
00216                                        ((PINSOURCE) == GPIO_PinSource12) || \
00217                                        ((PINSOURCE) == GPIO_PinSource13) || \
00218                                        ((PINSOURCE) == GPIO_PinSource14) || \
00219                                        ((PINSOURCE) == GPIO_PinSource15))
00220 
00230 #define GPIO_AF_RTC_50Hz      ((uint8_t)0x00)  /* RTC_50Hz Alternate Function mapping */
00231 #define GPIO_AF_MCO           ((uint8_t)0x00)  /* MCO (MCO1 and MCO2) Alternate Function mapping */
00232 #define GPIO_AF_TAMPER        ((uint8_t)0x00)  /* TAMPER (TAMPER_1 and TAMPER_2) Alternate Function mapping */
00233 #define GPIO_AF_SWJ           ((uint8_t)0x00)  /* SWJ (SWD and JTAG) Alternate Function mapping */
00234 #define GPIO_AF_TRACE         ((uint8_t)0x00)  /* TRACE Alternate Function mapping */
00235 
00239 #define GPIO_AF_TIM1          ((uint8_t)0x01)  /* TIM1 Alternate Function mapping */
00240 #define GPIO_AF_TIM2          ((uint8_t)0x01)  /* TIM2 Alternate Function mapping */
00241 
00245 #define GPIO_AF_TIM3          ((uint8_t)0x02)  /* TIM3 Alternate Function mapping */
00246 #define GPIO_AF_TIM4          ((uint8_t)0x02)  /* TIM4 Alternate Function mapping */
00247 #define GPIO_AF_TIM5          ((uint8_t)0x02)  /* TIM5 Alternate Function mapping */
00248 
00252 #define GPIO_AF_TIM8          ((uint8_t)0x03)  /* TIM8 Alternate Function mapping */
00253 #define GPIO_AF_TIM9          ((uint8_t)0x03)  /* TIM9 Alternate Function mapping */
00254 #define GPIO_AF_TIM10         ((uint8_t)0x03)  /* TIM10 Alternate Function mapping */
00255 #define GPIO_AF_TIM11         ((uint8_t)0x03)  /* TIM11 Alternate Function mapping */
00256 
00260 #define GPIO_AF_I2C1          ((uint8_t)0x04)  /* I2C1 Alternate Function mapping */
00261 #define GPIO_AF_I2C2          ((uint8_t)0x04)  /* I2C2 Alternate Function mapping */
00262 #define GPIO_AF_I2C3          ((uint8_t)0x04)  /* I2C3 Alternate Function mapping */
00263 
00267 #define GPIO_AF_SPI1          ((uint8_t)0x05)  /* SPI1 Alternate Function mapping */
00268 #define GPIO_AF_SPI2          ((uint8_t)0x05)  /* SPI2/I2S2 Alternate Function mapping */
00269 
00273 #define GPIO_AF_SPI3          ((uint8_t)0x06)  /* SPI3/I2S3 Alternate Function mapping */
00274 
00278 #define GPIO_AF_USART1        ((uint8_t)0x07)  /* USART1 Alternate Function mapping */
00279 #define GPIO_AF_USART2        ((uint8_t)0x07)  /* USART2 Alternate Function mapping */
00280 #define GPIO_AF_USART3        ((uint8_t)0x07)  /* USART3 Alternate Function mapping */
00281 #define GPIO_AF_I2S3ext       ((uint8_t)0x07)  /* I2S3ext Alternate Function mapping */
00282 
00286 #define GPIO_AF_UART4         ((uint8_t)0x08)  /* UART4 Alternate Function mapping */
00287 #define GPIO_AF_UART5         ((uint8_t)0x08)  /* UART5 Alternate Function mapping */
00288 #define GPIO_AF_USART6        ((uint8_t)0x08)  /* USART6 Alternate Function mapping */
00289 
00293 #define GPIO_AF_CAN1          ((uint8_t)0x09)  /* CAN1 Alternate Function mapping */
00294 #define GPIO_AF_CAN2          ((uint8_t)0x09)  /* CAN2 Alternate Function mapping */
00295 #define GPIO_AF_TIM12         ((uint8_t)0x09)  /* TIM12 Alternate Function mapping */
00296 #define GPIO_AF_TIM13         ((uint8_t)0x09)  /* TIM13 Alternate Function mapping */
00297 #define GPIO_AF_TIM14         ((uint8_t)0x09)  /* TIM14 Alternate Function mapping */
00298 
00302 #define GPIO_AF_OTG_FS         ((uint8_t)0xA)  /* OTG_FS Alternate Function mapping */
00303 #define GPIO_AF_OTG_HS         ((uint8_t)0xA)  /* OTG_HS Alternate Function mapping */
00304 
00308 #define GPIO_AF_ETH             ((uint8_t)0x0B)  /* ETHERNET Alternate Function mapping */
00309 
00313 #define GPIO_AF_FSMC            ((uint8_t)0xC)  /* FSMC Alternate Function mapping */
00314 #define GPIO_AF_OTG_HS_FS       ((uint8_t)0xC)  /* OTG HS configured in FS, Alternate Function mapping */
00315 #define GPIO_AF_SDIO            ((uint8_t)0xC)  /* SDIO Alternate Function mapping */
00316 
00320 #define GPIO_AF_DCMI          ((uint8_t)0x0D)  /* DCMI Alternate Function mapping */
00321 
00325 #define GPIO_AF_EVENTOUT      ((uint8_t)0x0F)  /* EVENTOUT Alternate Function mapping */
00326 
00327 #define IS_GPIO_AF(AF)   (((AF) == GPIO_AF_RTC_50Hz)  || ((AF) == GPIO_AF_TIM14)  || \
00328                           ((AF) == GPIO_AF_MCO)       || ((AF) == GPIO_AF_TAMPER) || \
00329                           ((AF) == GPIO_AF_SWJ)       || ((AF) == GPIO_AF_TRACE)  || \
00330                           ((AF) == GPIO_AF_TIM1)      || ((AF) == GPIO_AF_TIM2)   || \
00331                           ((AF) == GPIO_AF_TIM3)      || ((AF) == GPIO_AF_TIM4)   || \
00332                           ((AF) == GPIO_AF_TIM5)      || ((AF) == GPIO_AF_TIM8)   || \
00333                           ((AF) == GPIO_AF_I2C1)      || ((AF) == GPIO_AF_I2C2)   || \
00334                           ((AF) == GPIO_AF_I2C3)      || ((AF) == GPIO_AF_SPI1)   || \
00335                           ((AF) == GPIO_AF_SPI2)      || ((AF) == GPIO_AF_TIM13)  || \
00336                           ((AF) == GPIO_AF_SPI3)      || ((AF) == GPIO_AF_TIM14)  || \
00337                           ((AF) == GPIO_AF_USART1)    || ((AF) == GPIO_AF_USART2) || \
00338                           ((AF) == GPIO_AF_USART3)    || ((AF) == GPIO_AF_UART4)  || \
00339                           ((AF) == GPIO_AF_UART5)     || ((AF) == GPIO_AF_USART6) || \
00340                           ((AF) == GPIO_AF_CAN1)      || ((AF) == GPIO_AF_CAN2)   || \
00341                           ((AF) == GPIO_AF_OTG_FS)    || ((AF) == GPIO_AF_OTG_HS) || \
00342                           ((AF) == GPIO_AF_ETH)       || ((AF) == GPIO_AF_FSMC)   || \
00343                           ((AF) == GPIO_AF_OTG_HS_FS) || ((AF) == GPIO_AF_SDIO)   || \
00344                           ((AF) == GPIO_AF_DCMI)      || ((AF) == GPIO_AF_EVENTOUT))
00345 
00353 #define GPIO_Mode_AIN           GPIO_Mode_AN
00354 
00355 #define GPIO_AF_OTG1_FS         GPIO_AF_OTG_FS
00356 #define GPIO_AF_OTG2_HS         GPIO_AF_OTG_HS
00357 #define GPIO_AF_OTG2_FS         GPIO_AF_OTG_HS_FS
00358 
00367 /* Exported macro ------------------------------------------------------------*/
00368 /* Exported functions --------------------------------------------------------*/
00369 
00370 /*  Function used to set the GPIO configuration to the default reset state ****/
00371 void GPIO_DeInit(GPIO_TypeDef* GPIOx);
00372 
00373 /* Initialization and Configuration functions *********************************/
00374 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
00375 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
00376 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00377 
00378 /* GPIO Read and Write functions **********************************************/
00379 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00380 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
00381 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00382 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
00383 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00384 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00385 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
00386 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
00387 void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00388 
00389 /* GPIO Alternate functions configuration function ****************************/
00390 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
00391 
00392 #ifdef __cplusplus
00393 }
00394 #endif
00395 
00396 #endif /*__STM32F4xx_GPIO_H */
00397 
00406 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/