1 /** 2 ****************************************************************************** 3 * @file stm32f2xx_exti.c 4 * @author MCD Application Team 5 * @version V1.1.2 6 * @date 05-March-2012 7 * @brief This file provides firmware functions to manage the following 8 * functionalities of the EXTI peripheral: 9 * - Initialization and Configuration 10 * - Interrupts and flags management 11 * 12 * @verbatim 13 * 14 * =================================================================== 15 * EXTI features 16 * =================================================================== 17 * 18 * External interrupt/event lines are mapped as following: 19 * 1- All available GPIO pins are connected to the 16 external 20 * interrupt/event lines from EXTI0 to EXTI15. 21 * 2- EXTI line 16 is connected to the PVD Output 22 * 3- EXTI line 17 is connected to the RTC Alarm event 23 * 4- EXTI line 18 is connected to the USB OTG FS Wakeup from suspend event 24 * 5- EXTI line 19 is connected to the Ethernet Wakeup event 25 * 6- EXTI line 20 is connected to the USB OTG HS (configured in FS) Wakeup event 26 * 7- EXTI line 21 is connected to the RTC Tamper and Time Stamp events 27 * 8- EXTI line 22 is connected to the RTC Wakeup event 28 * 29 * =================================================================== 30 * How to use this driver 31 * =================================================================== 32 * 33 * In order to use an I/O pin as an external interrupt source, follow 34 * steps below: 35 * 1- Configure the I/O in input mode using GPIO_Init() 36 * 2- Select the input source pin for the EXTI line using SYSCFG_EXTILineConfig() 37 * 3- Select the mode(interrupt, event) and configure the trigger 38 * selection (Rising, falling or both) using EXTI_Init() 39 * 4- Configure NVIC IRQ channel mapped to the EXTI line using NVIC_Init() 40 * 41 * @note SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx 42 * registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); 43 * 44 * @endverbatim 45 * 46 ****************************************************************************** 47 * @attention 48 * 49 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> 50 * 51 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 52 * You may not use this file except in compliance with the License. 53 * You may obtain a copy of the License at: 54 * 55 * http://www.st.com/software_license_agreement_liberty_v2 56 * 57 * Unless required by applicable law or agreed to in writing, software 58 * distributed under the License is distributed on an "AS IS" BASIS, 59 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 60 * See the License for the specific language governing permissions and 61 * limitations under the License. 62 * 63 ****************************************************************************** 64 */ 65 66 /* Includes ------------------------------------------------------------------*/ 67 #include "stm32f2xx_exti.h" 68 69 /** @addtogroup STM32F2xx_StdPeriph_Driver 70 * @{ 71 */ 72 73 /** @defgroup EXTI 74 * @brief EXTI driver modules 75 * @{ 76 */ 77 78 /* Private typedef -----------------------------------------------------------*/ 79 /* Private define ------------------------------------------------------------*/ 80 81 #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */ 82 83 /* Private macro -------------------------------------------------------------*/ 84 /* Private variables ---------------------------------------------------------*/ 85 /* Private function prototypes -----------------------------------------------*/ 86 /* Private functions ---------------------------------------------------------*/ 87 88 /** @defgroup EXTI_Private_Functions 89 * @{ 90 */ 91 92 /** @defgroup EXTI_Group1 Initialization and Configuration functions 93 * @brief Initialization and Configuration functions 94 * 95 @verbatim 96 =============================================================================== 97 Initialization and Configuration functions 98 =============================================================================== 99 100 @endverbatim 101 * @{ 102 */ 103 104 /** 105 * @brief Deinitializes the EXTI peripheral registers to their default reset values. 106 * @param None 107 * @retval None 108 */ EXTI_DeInit(void)109void EXTI_DeInit(void) 110 { 111 EXTI->IMR = 0x00000000; 112 EXTI->EMR = 0x00000000; 113 EXTI->RTSR = 0x00000000; 114 EXTI->FTSR = 0x00000000; 115 EXTI->PR = 0x007FFFFF; 116 } 117 118 /** 119 * @brief Initializes the EXTI peripheral according to the specified 120 * parameters in the EXTI_InitStruct. 121 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure 122 * that contains the configuration information for the EXTI peripheral. 123 * @retval None 124 */ EXTI_Init(EXTI_InitTypeDef * EXTI_InitStruct)125void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct) 126 { 127 uint32_t tmp = 0; 128 129 /* Check the parameters */ 130 assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode)); 131 assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger)); 132 assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line)); 133 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd)); 134 135 tmp = (uint32_t)EXTI_BASE; 136 137 if (EXTI_InitStruct->EXTI_LineCmd != DISABLE) 138 { 139 /* Clear EXTI line configuration */ 140 EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line; 141 EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line; 142 143 tmp += EXTI_InitStruct->EXTI_Mode; 144 145 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 146 147 /* Clear Rising Falling edge configuration */ 148 EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line; 149 EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line; 150 151 /* Select the trigger for the selected external interrupts */ 152 if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) 153 { 154 /* Rising Falling edge */ 155 EXTI->RTSR |= EXTI_InitStruct->EXTI_Line; 156 EXTI->FTSR |= EXTI_InitStruct->EXTI_Line; 157 } 158 else 159 { 160 tmp = (uint32_t)EXTI_BASE; 161 tmp += EXTI_InitStruct->EXTI_Trigger; 162 163 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 164 } 165 } 166 else 167 { 168 tmp += EXTI_InitStruct->EXTI_Mode; 169 170 /* Disable the selected external lines */ 171 *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line; 172 } 173 } 174 175 /** 176 * @brief Fills each EXTI_InitStruct member with its reset value. 177 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will 178 * be initialized. 179 * @retval None 180 */ EXTI_StructInit(EXTI_InitTypeDef * EXTI_InitStruct)181void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct) 182 { 183 EXTI_InitStruct->EXTI_Line = EXTI_LINENONE; 184 EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt; 185 EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling; 186 EXTI_InitStruct->EXTI_LineCmd = DISABLE; 187 } 188 189 /** 190 * @brief Generates a Software interrupt on selected EXTI line. 191 * @param EXTI_Line: specifies the EXTI line on which the software interrupt 192 * will be generated. 193 * This parameter can be any combination of EXTI_Linex where x can be (0..22) 194 * @retval None 195 */ EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)196void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line) 197 { 198 /* Check the parameters */ 199 assert_param(IS_EXTI_LINE(EXTI_Line)); 200 201 EXTI->SWIER |= EXTI_Line; 202 } 203 204 /** 205 * @} 206 */ 207 208 /** @defgroup EXTI_Group2 Interrupts and flags management functions 209 * @brief Interrupts and flags management functions 210 * 211 @verbatim 212 =============================================================================== 213 Interrupts and flags management functions 214 =============================================================================== 215 216 @endverbatim 217 * @{ 218 */ 219 220 /** 221 * @brief Checks whether the specified EXTI line flag is set or not. 222 * @param EXTI_Line: specifies the EXTI line flag to check. 223 * This parameter can be EXTI_Linex where x can be(0..22) 224 * @retval The new state of EXTI_Line (SET or RESET). 225 */ EXTI_GetFlagStatus(uint32_t EXTI_Line)226FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line) 227 { 228 FlagStatus bitstatus = RESET; 229 /* Check the parameters */ 230 assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 231 232 if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET) 233 { 234 bitstatus = SET; 235 } 236 else 237 { 238 bitstatus = RESET; 239 } 240 return bitstatus; 241 } 242 243 /** 244 * @brief Clears the EXTI's line pending flags. 245 * @param EXTI_Line: specifies the EXTI lines flags to clear. 246 * This parameter can be any combination of EXTI_Linex where x can be (0..22) 247 * @retval None 248 */ EXTI_ClearFlag(uint32_t EXTI_Line)249void EXTI_ClearFlag(uint32_t EXTI_Line) 250 { 251 /* Check the parameters */ 252 assert_param(IS_EXTI_LINE(EXTI_Line)); 253 254 EXTI->PR = EXTI_Line; 255 } 256 257 /** 258 * @brief Checks whether the specified EXTI line is asserted or not. 259 * @param EXTI_Line: specifies the EXTI line to check. 260 * This parameter can be EXTI_Linex where x can be(0..22) 261 * @retval The new state of EXTI_Line (SET or RESET). 262 */ EXTI_GetITStatus(uint32_t EXTI_Line)263ITStatus EXTI_GetITStatus(uint32_t EXTI_Line) 264 { 265 ITStatus bitstatus = RESET; 266 uint32_t enablestatus = 0; 267 /* Check the parameters */ 268 assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 269 270 enablestatus = EXTI->IMR & EXTI_Line; 271 if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) 272 { 273 bitstatus = SET; 274 } 275 else 276 { 277 bitstatus = RESET; 278 } 279 return bitstatus; 280 } 281 282 /** 283 * @brief Clears the EXTI's line pending bits. 284 * @param EXTI_Line: specifies the EXTI lines to clear. 285 * This parameter can be any combination of EXTI_Linex where x can be (0..22) 286 * @retval None 287 */ EXTI_ClearITPendingBit(uint32_t EXTI_Line)288void EXTI_ClearITPendingBit(uint32_t EXTI_Line) 289 { 290 /* Check the parameters */ 291 assert_param(IS_EXTI_LINE(EXTI_Line)); 292 293 EXTI->PR = EXTI_Line; 294 } 295 296 /** 297 * @} 298 */ 299 300 /** 301 * @} 302 */ 303 304 /** 305 * @} 306 */ 307 308 /** 309 * @} 310 */ 311 312 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 313