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