Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more
stm32f30x_gpio.h
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f30x_gpio.h 00004 * @author MCD Application Team 00005 * @version V1.2.3 00006 * @date 10-July-2015 00007 * @brief This file contains all the functions prototypes for the GPIO 00008 * firmware library. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> 00013 * 00014 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00015 * You may not use this file except in compliance with the License. 00016 * You may obtain a copy of the License at: 00017 * 00018 * http://www.st.com/software_license_agreement_liberty_v2 00019 * 00020 * Unless required by applicable law or agreed to in writing, software 00021 * distributed under the License is distributed on an "AS IS" BASIS, 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00023 * See the License for the specific language governing permissions and 00024 * limitations under the License. 00025 * 00026 ****************************************************************************** 00027 */ 00028 00029 /* Define to prevent recursive inclusion -------------------------------------*/ 00030 #ifndef __STM32F30x_GPIO_H 00031 #define __STM32F30x_GPIO_H 00032 00033 #ifdef __cplusplus 00034 extern "C" { 00035 #endif 00036 00037 /* Includes ------------------------------------------------------------------*/ 00038 #include "stm32f30x.h" 00039 00040 /** @addtogroup STM32F30x_StdPeriph_Driver 00041 * @{ 00042 */ 00043 00044 /** @addtogroup GPIO 00045 * @{ 00046 */ 00047 00048 /* Exported types ------------------------------------------------------------*/ 00049 00050 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \ 00051 ((PERIPH) == GPIOB) || \ 00052 ((PERIPH) == GPIOC) || \ 00053 ((PERIPH) == GPIOD) || \ 00054 ((PERIPH) == GPIOE) || \ 00055 ((PERIPH) == GPIOF) || \ 00056 ((PERIPH) == GPIOG) || \ 00057 ((PERIPH) == GPIOH)) 00058 00059 #define IS_GPIO_LIST_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \ 00060 ((PERIPH) == GPIOB) || \ 00061 ((PERIPH) == GPIOC)|| \ 00062 ((PERIPH) == GPIOD) || \ 00063 ((PERIPH) == GPIOF)) 00064 /** @defgroup Configuration_Mode_enumeration 00065 * @{ 00066 */ 00067 typedef enum 00068 { 00069 GPIO_Mode_IN = 0x00, /*!< GPIO Input Mode */ 00070 GPIO_Mode_OUT = 0x01, /*!< GPIO Output Mode */ 00071 GPIO_Mode_AF = 0x02, /*!< GPIO Alternate function Mode */ 00072 GPIO_Mode_AN = 0x03 /*!< GPIO Analog In/Out Mode */ 00073 }GPIOMode_TypeDef; 00074 00075 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)|| ((MODE) == GPIO_Mode_OUT) || \ 00076 ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN)) 00077 /** 00078 * @} 00079 */ 00080 00081 /** @defgroup Output_type_enumeration 00082 * @{ 00083 */ 00084 typedef enum 00085 { 00086 GPIO_OType_PP = 0x00, 00087 GPIO_OType_OD = 0x01 00088 }GPIOOType_TypeDef; 00089 00090 #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD)) 00091 00092 /** 00093 * @} 00094 */ 00095 00096 /** @defgroup Output_Maximum_frequency_enumeration 00097 * @{ 00098 */ 00099 typedef enum 00100 { 00101 GPIO_Speed_Level_1 = 0x01, /*!< Fast Speed */ 00102 GPIO_Speed_Level_2 = 0x02, /*!< Meduim Speed */ 00103 GPIO_Speed_Level_3 = 0x03 /*!< High Speed */ 00104 }GPIOSpeed_TypeDef; 00105 00106 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_Level_1) || ((SPEED) == GPIO_Speed_Level_2) || \ 00107 ((SPEED) == GPIO_Speed_Level_3)) 00108 /** 00109 * @} 00110 */ 00111 00112 /** @defgroup Configuration_Pull-Up_Pull-Down_enumeration 00113 * @{ 00114 */ 00115 typedef enum 00116 { 00117 GPIO_PuPd_NOPULL = 0x00, 00118 GPIO_PuPd_UP = 0x01, 00119 GPIO_PuPd_DOWN = 0x02 00120 }GPIOPuPd_TypeDef; 00121 00122 #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \ 00123 ((PUPD) == GPIO_PuPd_DOWN)) 00124 /** 00125 * @} 00126 */ 00127 00128 /** @defgroup Bit_SET_and_Bit_RESET_enumeration 00129 * @{ 00130 */ 00131 typedef enum 00132 { 00133 Bit_RESET = 0, 00134 Bit_SET 00135 }BitAction; 00136 00137 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET)) 00138 /** 00139 * @} 00140 */ 00141 00142 /** 00143 * @brief GPIO Init structure definition 00144 */ 00145 typedef struct 00146 { 00147 uint32_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured. 00148 This parameter can be any value of @ref GPIO_pins_define */ 00149 00150 GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins. 00151 This parameter can be a value of @ref GPIOMode_TypeDef */ 00152 00153 GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins. 00154 This parameter can be a value of @ref GPIOSpeed_TypeDef */ 00155 00156 GPIOOType_TypeDef GPIO_OType; /*!< Specifies the operating output type for the selected pins. 00157 This parameter can be a value of @ref GPIOOType_TypeDef */ 00158 00159 GPIOPuPd_TypeDef GPIO_PuPd; /*!< Specifies the operating Pull-up/Pull down for the selected pins. 00160 This parameter can be a value of @ref GPIOPuPd_TypeDef */ 00161 }GPIO_InitTypeDef; 00162 00163 /* Exported constants --------------------------------------------------------*/ 00164 00165 /** @defgroup GPIO_Exported_Constants 00166 * @{ 00167 */ 00168 00169 /** @defgroup GPIO_pins_define 00170 * @{ 00171 */ 00172 #define GPIO_Pin_0 ((uint16_t)0x0001) /*!< Pin 0 selected */ 00173 #define GPIO_Pin_1 ((uint16_t)0x0002) /*!< Pin 1 selected */ 00174 #define GPIO_Pin_2 ((uint16_t)0x0004) /*!< Pin 2 selected */ 00175 #define GPIO_Pin_3 ((uint16_t)0x0008) /*!< Pin 3 selected */ 00176 #define GPIO_Pin_4 ((uint16_t)0x0010) /*!< Pin 4 selected */ 00177 #define GPIO_Pin_5 ((uint16_t)0x0020) /*!< Pin 5 selected */ 00178 #define GPIO_Pin_6 ((uint16_t)0x0040) /*!< Pin 6 selected */ 00179 #define GPIO_Pin_7 ((uint16_t)0x0080) /*!< Pin 7 selected */ 00180 #define GPIO_Pin_8 ((uint16_t)0x0100) /*!< Pin 8 selected */ 00181 #define GPIO_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */ 00182 #define GPIO_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */ 00183 #define GPIO_Pin_11 ((uint16_t)0x0800) /*!< Pin 11 selected */ 00184 #define GPIO_Pin_12 ((uint16_t)0x1000) /*!< Pin 12 selected */ 00185 #define GPIO_Pin_13 ((uint16_t)0x2000) /*!< Pin 13 selected */ 00186 #define GPIO_Pin_14 ((uint16_t)0x4000) /*!< Pin 14 selected */ 00187 #define GPIO_Pin_15 ((uint16_t)0x8000) /*!< Pin 15 selected */ 00188 #define GPIO_Pin_All ((uint16_t)0xFFFF) /*!< All pins selected */ 00189 00190 #define IS_GPIO_PIN(PIN) ((PIN) != (uint16_t)0x00) 00191 00192 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \ 00193 ((PIN) == GPIO_Pin_1) || \ 00194 ((PIN) == GPIO_Pin_2) || \ 00195 ((PIN) == GPIO_Pin_3) || \ 00196 ((PIN) == GPIO_Pin_4) || \ 00197 ((PIN) == GPIO_Pin_5) || \ 00198 ((PIN) == GPIO_Pin_6) || \ 00199 ((PIN) == GPIO_Pin_7) || \ 00200 ((PIN) == GPIO_Pin_8) || \ 00201 ((PIN) == GPIO_Pin_9) || \ 00202 ((PIN) == GPIO_Pin_10) || \ 00203 ((PIN) == GPIO_Pin_11) || \ 00204 ((PIN) == GPIO_Pin_12) || \ 00205 ((PIN) == GPIO_Pin_13) || \ 00206 ((PIN) == GPIO_Pin_14) || \ 00207 ((PIN) == GPIO_Pin_15)) 00208 00209 /** 00210 * @} 00211 */ 00212 00213 /** @defgroup GPIO_Pin_sources 00214 * @{ 00215 */ 00216 #define GPIO_PinSource0 ((uint8_t)0x00) 00217 #define GPIO_PinSource1 ((uint8_t)0x01) 00218 #define GPIO_PinSource2 ((uint8_t)0x02) 00219 #define GPIO_PinSource3 ((uint8_t)0x03) 00220 #define GPIO_PinSource4 ((uint8_t)0x04) 00221 #define GPIO_PinSource5 ((uint8_t)0x05) 00222 #define GPIO_PinSource6 ((uint8_t)0x06) 00223 #define GPIO_PinSource7 ((uint8_t)0x07) 00224 #define GPIO_PinSource8 ((uint8_t)0x08) 00225 #define GPIO_PinSource9 ((uint8_t)0x09) 00226 #define GPIO_PinSource10 ((uint8_t)0x0A) 00227 #define GPIO_PinSource11 ((uint8_t)0x0B) 00228 #define GPIO_PinSource12 ((uint8_t)0x0C) 00229 #define GPIO_PinSource13 ((uint8_t)0x0D) 00230 #define GPIO_PinSource14 ((uint8_t)0x0E) 00231 #define GPIO_PinSource15 ((uint8_t)0x0F) 00232 00233 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \ 00234 ((PINSOURCE) == GPIO_PinSource1) || \ 00235 ((PINSOURCE) == GPIO_PinSource2) || \ 00236 ((PINSOURCE) == GPIO_PinSource3) || \ 00237 ((PINSOURCE) == GPIO_PinSource4) || \ 00238 ((PINSOURCE) == GPIO_PinSource5) || \ 00239 ((PINSOURCE) == GPIO_PinSource6) || \ 00240 ((PINSOURCE) == GPIO_PinSource7) || \ 00241 ((PINSOURCE) == GPIO_PinSource8) || \ 00242 ((PINSOURCE) == GPIO_PinSource9) || \ 00243 ((PINSOURCE) == GPIO_PinSource10) || \ 00244 ((PINSOURCE) == GPIO_PinSource11) || \ 00245 ((PINSOURCE) == GPIO_PinSource12) || \ 00246 ((PINSOURCE) == GPIO_PinSource13) || \ 00247 ((PINSOURCE) == GPIO_PinSource14) || \ 00248 ((PINSOURCE) == GPIO_PinSource15)) 00249 /** 00250 * @} 00251 */ 00252 00253 /** @defgroup GPIO_Alternate_function_selection_define 00254 * @{ 00255 */ 00256 00257 /** 00258 * @brief AF 0 selection 00259 */ 00260 #define GPIO_AF_0 ((uint8_t)0x00) /* JTCK-SWCLK, JTDI, JTDO/TRACESW0, JTMS-SWDAT, 00261 MCO, NJTRST, TRACED, TRACECK */ 00262 /** 00263 * @brief AF 1 selection 00264 */ 00265 #define GPIO_AF_1 ((uint8_t)0x01) /* OUT, TIM2, TIM15, TIM16, TIM17 */ 00266 00267 /** 00268 * @brief AF 2 selection 00269 */ 00270 #define GPIO_AF_2 ((uint8_t)0x02) /* COMP1_OUT, TIM1, TIM2, TIM3, TIM4, TIM8, TIM15, TIM16 */ 00271 00272 /** 00273 * @brief AF 3 selection 00274 */ 00275 #define GPIO_AF_3 ((uint8_t)0x03) /* COMP7_OUT, TIM8, TIM15, Touch, HRTIM1 */ 00276 00277 /** 00278 * @brief AF 4 selection 00279 */ 00280 #define GPIO_AF_4 ((uint8_t)0x04) /* I2C1, I2C2, TIM1, TIM8, TIM16, TIM17 */ 00281 00282 /** 00283 * @brief AF 5 selection 00284 */ 00285 #define GPIO_AF_5 ((uint8_t)0x05) /* IR_OUT, I2S2, I2S3, SPI1, SPI2, TIM8, USART4, USART5 */ 00286 00287 /** 00288 * @brief AF 6 selection 00289 */ 00290 #define GPIO_AF_6 ((uint8_t)0x06) /* IR_OUT, I2S2, I2S3, SPI2, SPI3, TIM1, TIM8 */ 00291 00292 /** 00293 * @brief AF 7 selection 00294 */ 00295 #define GPIO_AF_7 ((uint8_t)0x07) /* AOP2_OUT, CAN, COMP3_OUT, COMP5_OUT, COMP6_OUT, 00296 USART1, USART2, USART3 */ 00297 00298 /** 00299 * @brief AF 8 selection 00300 */ 00301 #define GPIO_AF_8 ((uint8_t)0x08) /* COMP1_OUT, COMP2_OUT, COMP3_OUT, COMP4_OUT, 00302 COMP5_OUT, COMP6_OUT */ 00303 00304 /** 00305 * @brief AF 9 selection 00306 */ 00307 #define GPIO_AF_9 ((uint8_t)0x09) /* AOP4_OUT, CAN, TIM1, TIM8, TIM15 */ 00308 00309 /** 00310 * @brief AF 10 selection 00311 */ 00312 #define GPIO_AF_10 ((uint8_t)0x0A) /* AOP1_OUT, AOP3_OUT, TIM2, TIM3, TIM4, TIM8, TIM17 */ 00313 00314 /** 00315 * @brief AF 11 selection 00316 */ 00317 #define GPIO_AF_11 ((uint8_t)0x0B) /* TIM1, TIM8 */ 00318 00319 /** 00320 * @brief AF 12 selection 00321 */ 00322 #define GPIO_AF_12 ((uint8_t)0x0C) /* TIM1, HRTIM1 */ 00323 00324 /** 00325 * @brief AF 13 selection 00326 */ 00327 #define GPIO_AF_13 ((uint8_t)0x0D) /* HRTIM1, AOP2_OUT */ 00328 00329 /** 00330 * @brief AF 14 selection 00331 */ 00332 #define GPIO_AF_14 ((uint8_t)0x0E) /* USBDM, USBDP */ 00333 00334 /** 00335 * @brief AF 15 selection 00336 */ 00337 #define GPIO_AF_15 ((uint8_t)0x0F) /* OUT */ 00338 00339 #define IS_GPIO_AF(AF) (((AF) == GPIO_AF_0)||((AF) == GPIO_AF_1)||\ 00340 ((AF) == GPIO_AF_2)||((AF) == GPIO_AF_3)||\ 00341 ((AF) == GPIO_AF_4)||((AF) == GPIO_AF_5)||\ 00342 ((AF) == GPIO_AF_6)||((AF) == GPIO_AF_7)||\ 00343 ((AF) == GPIO_AF_8)||((AF) == GPIO_AF_9)||\ 00344 ((AF) == GPIO_AF_10)||((AF) == GPIO_AF_11)||\ 00345 ((AF) == GPIO_AF_12)||((AF) == GPIO_AF_13)||\ 00346 ((AF) == GPIO_AF_14)||((AF) == GPIO_AF_15)) 00347 00348 /** 00349 * @} 00350 */ 00351 00352 /** @defgroup GPIO_Speed_Legacy 00353 * @{ 00354 */ 00355 00356 #define GPIO_Speed_10MHz GPIO_Speed_Level_1 /*!< Fast Speed:10MHz */ 00357 #define GPIO_Speed_2MHz GPIO_Speed_Level_2 /*!< Medium Speed:2MHz */ 00358 #define GPIO_Speed_50MHz GPIO_Speed_Level_3 /*!< High Speed:50MHz */ 00359 00360 /** 00361 * @} 00362 */ 00363 00364 /** 00365 * @} 00366 */ 00367 00368 /* Exported macro ------------------------------------------------------------*/ 00369 /* Exported functions ------------------------------------------------------- */ 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 00388 /* GPIO Alternate functions configuration functions ***************************/ 00389 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF); 00390 00391 #ifdef __cplusplus 00392 } 00393 #endif 00394 00395 #endif /* __STM32F30x_GPIO_H */ 00396 /** 00397 * @} 00398 */ 00399 00400 /** 00401 * @} 00402 */ 00403 00404 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:34:44 by
