2 ******************************************************************************
3 * @file stm32f4xx_exti.c
4 * @author MCD Application Team
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
14 * ===================================================================
16 * ===================================================================
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
29 * ===================================================================
30 * How to use this driver
31 * ===================================================================
33 * In order to use an I/O pin as an external interrupt source, follow
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()
41 * @note SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx
42 * registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
46 ******************************************************************************
49 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
50 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
51 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
52 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
53 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
54 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
56 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
57 ******************************************************************************
60 /* Includes ------------------------------------------------------------------*/
61 #include "stm32f4xx_exti.h"
63 /** @addtogroup STM32F4xx_StdPeriph_Driver
68 * @brief EXTI driver modules
72 /* Private typedef -----------------------------------------------------------*/
73 /* Private define ------------------------------------------------------------*/
75 #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
77 /* Private macro -------------------------------------------------------------*/
78 /* Private variables ---------------------------------------------------------*/
79 /* Private function prototypes -----------------------------------------------*/
80 /* Private functions ---------------------------------------------------------*/
82 /** @defgroup EXTI_Private_Functions
86 /** @defgroup EXTI_Group1 Initialization and Configuration functions
87 * @brief Initialization and Configuration functions
90 ===============================================================================
91 Initialization and Configuration functions
92 ===============================================================================
99 * @brief Deinitializes the EXTI peripheral registers to their default reset values.
103 void EXTI_DeInit(void)
105 EXTI->IMR = 0x00000000;
106 EXTI->EMR = 0x00000000;
107 EXTI->RTSR = 0x00000000;
108 EXTI->FTSR = 0x00000000;
109 EXTI->PR = 0x007FFFFF;
113 * @brief Initializes the EXTI peripheral according to the specified
114 * parameters in the EXTI_InitStruct.
115 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
116 * that contains the configuration information for the EXTI peripheral.
119 void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
123 /* Check the parameters */
124 assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
125 assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
126 assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
127 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
129 tmp = (uint32_t)EXTI_BASE;
131 if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
133 /* Clear EXTI line configuration */
134 EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
135 EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
137 tmp += EXTI_InitStruct->EXTI_Mode;
139 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
141 /* Clear Rising Falling edge configuration */
142 EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
143 EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
145 /* Select the trigger for the selected external interrupts */
146 if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
148 /* Rising Falling edge */
149 EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
150 EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
154 tmp = (uint32_t)EXTI_BASE;
155 tmp += EXTI_InitStruct->EXTI_Trigger;
157 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
162 tmp += EXTI_InitStruct->EXTI_Mode;
164 /* Disable the selected external lines */
165 *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
170 * @brief Fills each EXTI_InitStruct member with its reset value.
171 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
175 void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
177 EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
178 EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
179 EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
180 EXTI_InitStruct->EXTI_LineCmd = DISABLE;
184 * @brief Generates a Software interrupt on selected EXTI line.
185 * @param EXTI_Line: specifies the EXTI line on which the software interrupt
187 * This parameter can be any combination of EXTI_Linex where x can be (0..22)
190 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
192 /* Check the parameters */
193 assert_param(IS_EXTI_LINE(EXTI_Line));
195 EXTI->SWIER |= EXTI_Line;
202 /** @defgroup EXTI_Group2 Interrupts and flags management functions
203 * @brief Interrupts and flags management functions
206 ===============================================================================
207 Interrupts and flags management functions
208 ===============================================================================
215 * @brief Checks whether the specified EXTI line flag is set or not.
216 * @param EXTI_Line: specifies the EXTI line flag to check.
217 * This parameter can be EXTI_Linex where x can be(0..22)
218 * @retval The new state of EXTI_Line (SET or RESET).
220 FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
222 FlagStatus bitstatus = RESET;
223 /* Check the parameters */
224 assert_param(IS_GET_EXTI_LINE(EXTI_Line));
226 if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
238 * @brief Clears the EXTI's line pending flags.
239 * @param EXTI_Line: specifies the EXTI lines flags to clear.
240 * This parameter can be any combination of EXTI_Linex where x can be (0..22)
243 void EXTI_ClearFlag(uint32_t EXTI_Line)
245 /* Check the parameters */
246 assert_param(IS_EXTI_LINE(EXTI_Line));
248 EXTI->PR = EXTI_Line;
252 * @brief Checks whether the specified EXTI line is asserted or not.
253 * @param EXTI_Line: specifies the EXTI line to check.
254 * This parameter can be EXTI_Linex where x can be(0..22)
255 * @retval The new state of EXTI_Line (SET or RESET).
257 ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
259 ITStatus bitstatus = RESET;
260 uint32_t enablestatus = 0;
261 /* Check the parameters */
262 assert_param(IS_GET_EXTI_LINE(EXTI_Line));
264 enablestatus = EXTI->IMR & EXTI_Line;
265 if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
277 * @brief Clears the EXTI's line pending bits.
278 * @param EXTI_Line: specifies the EXTI lines to clear.
279 * This parameter can be any combination of EXTI_Linex where x can be (0..22)
282 void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
284 /* Check the parameters */
285 assert_param(IS_EXTI_LINE(EXTI_Line));
287 EXTI->PR = EXTI_Line;
306 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/