2 ******************************************************************************
3 * @file stm32f30x_exti.c
4 * @author MCD Application Team
6 * @date 27-February-2014
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
13 ===============================================================================
14 ##### EXTI features #####
15 ===============================================================================
16 [..] External interrupt/event lines are mapped as following:
17 (#) All available GPIO pins are connected to the 16 external
18 interrupt/event lines from EXTI0 to EXTI15.
19 (#) EXTI line 16 is connected to the PVD output
20 (#) EXTI line 17 is connected to the RTC Alarm event
21 (#) EXTI line 18 is connected to USB Device wakeup event
22 (#) EXTI line 19 is connected to the RTC Tamper and TimeStamp events
23 (#) EXTI line 20 is connected to the RTC wakeup event
24 (#) EXTI line 21 is connected to the Comparator 1 wakeup event
25 (#) EXTI line 22 is connected to the Comparator 2 wakeup event
26 (#) EXTI line 23 is connected to the I2C1 wakeup event
27 (#) EXTI line 24 is connected to the I2C2 wakeup event
28 (#) EXTI line 25 is connected to the USART1 wakeup event
29 (#) EXTI line 26 is connected to the USART2 wakeup event
30 (#) EXTI line 27 is reserved
31 (#) EXTI line 28 is connected to the USART3 wakeup event
32 (#) EXTI line 29 is connected to the Comparator 3 event
33 (#) EXTI line 30 is connected to the Comparator 4 event
34 (#) EXTI line 31 is connected to the Comparator 5 event
35 (#) EXTI line 32 is connected to the Comparator 6 event
36 (#) EXTI line 33 is connected to the Comparator 7 event
37 (#) EXTI line 34 is connected for thr UART4 wakeup event
38 (#) EXTI line 35 is connected for the UART5 wakeup event
40 ##### How to use this driver #####
41 ===============================================================================
42 [..] In order to use an I/O pin as an external interrupt source,
44 (#) Configure the I/O in input mode using GPIO_Init().
45 (#) Select the input source pin for the EXTI line using
46 SYSCFG_EXTILineConfig().
47 (#) Select the mode(interrupt, event) and configure the trigger
48 selection (Rising, falling or both) using EXTI_Init(). For the
49 internal interrupt, the trigger selection is not needed
50 (the active edge is always the rising one).
51 (#) Configure NVIC IRQ channel mapped to the EXTI line using NVIC_Init().
52 (#) Optionally, you can generate a software interrupt using the function
53 EXTI_GenerateSWInterrupt().
55 (@) SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx
56 registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
60 ******************************************************************************
63 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
65 * Redistribution and use in source and binary forms, with or without modification,
66 * are permitted provided that the following conditions are met:
67 * 1. Redistributions of source code must retain the above copyright notice,
68 * this list of conditions and the following disclaimer.
69 * 2. Redistributions in binary form must reproduce the above copyright notice,
70 * this list of conditions and the following disclaimer in the documentation
71 * and/or other materials provided with the distribution.
72 * 3. Neither the name of STMicroelectronics nor the names of its contributors
73 * may be used to endorse or promote products derived from this software
74 * without specific prior written permission.
76 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
77 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
79 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
80 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
81 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
82 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
83 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
84 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
85 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87 ******************************************************************************
90 /* Includes ------------------------------------------------------------------*/
91 #include "stm32f30x_exti.h"
93 /** @addtogroup STM32F30x_StdPeriph_Driver
98 * @brief EXTI driver modules
103 /* Private typedef -----------------------------------------------------------*/
104 /* Private define ------------------------------------------------------------*/
105 #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
107 /* Private macro -------------------------------------------------------------*/
108 /* Private variables ---------------------------------------------------------*/
109 /* Private function prototypes -----------------------------------------------*/
110 /* Private functions ---------------------------------------------------------*/
112 /** @defgroup EXTI_Private_Functions
116 /** @defgroup EXTI_Group1 Initialization and Configuration functions
117 * @brief Initialization and Configuration functions
120 ===============================================================================
121 ##### Initialization and Configuration functions #####
122 ===============================================================================
129 * @brief Deinitializes the EXTI peripheral registers to their default reset
134 void EXTI_DeInit(void)
136 EXTI->IMR = 0x1F800000;
137 EXTI->EMR = 0x00000000;
138 EXTI->RTSR = 0x00000000;
139 EXTI->FTSR = 0x00000000;
140 EXTI->SWIER = 0x00000000;
141 EXTI->PR = 0xE07FFFFF;
142 EXTI->IMR2 = 0x0000000C;
143 EXTI->EMR2 = 0x00000000;
144 EXTI->RTSR2 = 0x00000000;
145 EXTI->FTSR2 = 0x00000000;
146 EXTI->SWIER2 = 0x00000000;
147 EXTI->PR2 = 0x00000003;
151 * @brief Initializes the EXTI peripheral according to the specified
152 * parameters in the EXTI_InitStruct.
153 * EXTI_Line specifies the EXTI line (EXTI0....EXTI35).
154 * EXTI_Mode specifies which EXTI line is used as interrupt or an event.
155 * EXTI_Trigger selects the trigger. When the trigger occurs, interrupt
156 * pending bit will be set.
157 * EXTI_LineCmd controls (Enable/Disable) the EXTI line.
158 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure that
159 * contains the configuration information for the EXTI peripheral.
164 void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
168 /* Check the parameters */
169 assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
170 assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
171 assert_param(IS_EXTI_LINE_ALL(EXTI_InitStruct->EXTI_Line));
172 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
174 tmp = (uint32_t)EXTI_BASE;
176 if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
178 /* Clear EXTI line configuration */
179 *(__IO uint32_t *) (((uint32_t) &(EXTI->IMR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
180 *(__IO uint32_t *) (((uint32_t) &(EXTI->EMR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
182 tmp += EXTI_InitStruct->EXTI_Mode + (((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20);
184 *(__IO uint32_t *) tmp |= (uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
186 tmp = (uint32_t)EXTI_BASE;
188 /* Clear Rising Falling edge configuration */
189 *(__IO uint32_t *) (((uint32_t) &(EXTI->RTSR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
190 *(__IO uint32_t *) (((uint32_t) &(EXTI->FTSR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
192 /* Select the trigger for the selected interrupts */
193 if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
195 /* Rising Falling edge */
196 *(__IO uint32_t *) (((uint32_t) &(EXTI->RTSR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) |= (uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
197 *(__IO uint32_t *) (((uint32_t) &(EXTI->FTSR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) |= (uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
201 tmp += EXTI_InitStruct->EXTI_Trigger + (((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20);
203 *(__IO uint32_t *) tmp |= (uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
209 tmp += EXTI_InitStruct->EXTI_Mode + (((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20);
211 /* Disable the selected external lines */
212 *(__IO uint32_t *) tmp &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
218 * @brief Fills each EXTI_InitStruct member with its reset value.
219 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
223 void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
225 EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
226 EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
227 EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Rising_Falling;
228 EXTI_InitStruct->EXTI_LineCmd = DISABLE;
232 * @brief Generates a Software interrupt on selected EXTI line.
233 * @param EXTI_Line: specifies the EXTI line on which the software interrupt
235 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
238 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
240 /* Check the parameters */
241 assert_param(IS_EXTI_LINE_EXT(EXTI_Line));
243 *(__IO uint32_t *) (((uint32_t) &(EXTI->SWIER)) + ((EXTI_Line) >> 5 ) * 0x20) |= (uint32_t)(1 << (EXTI_Line & 0x1F));
251 /** @defgroup EXTI_Group2 Interrupts and flags management functions
252 * @brief EXTI Interrupts and flags management functions
255 ===============================================================================
256 ##### Interrupts and flags management functions #####
257 ===============================================================================
259 This section provides functions allowing to configure the EXTI Interrupts
260 sources and check or clear the flags or pending bits status.
267 * @brief Checks whether the specified EXTI line flag is set or not.
268 * @param EXTI_Line: specifies the EXTI line flag to check.
269 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
270 * @retval The new state of EXTI_Line (SET or RESET).
272 FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
274 FlagStatus bitstatus = RESET;
276 /* Check the parameters */
277 assert_param(IS_GET_EXTI_LINE(EXTI_Line));
279 if ((*(__IO uint32_t *) (((uint32_t) &(EXTI->PR)) + ((EXTI_Line) >> 5 ) * 0x20)& (uint32_t)(1 << (EXTI_Line & 0x1F))) != (uint32_t)RESET)
291 * @brief Clears the EXTI's line pending flags.
292 * @param EXTI_Line: specifies the EXTI lines flags to clear.
293 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
296 void EXTI_ClearFlag(uint32_t EXTI_Line)
298 /* Check the parameters */
299 assert_param(IS_EXTI_LINE_EXT(EXTI_Line));
301 *(__IO uint32_t *) (((uint32_t) &(EXTI->PR)) + ((EXTI_Line) >> 5 ) * 0x20) = (1 << (EXTI_Line & 0x1F));
305 * @brief Checks whether the specified EXTI line is asserted or not.
306 * @param EXTI_Line: specifies the EXTI line to check.
307 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
308 * @retval The new state of EXTI_Line (SET or RESET).
310 ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
312 ITStatus bitstatus = RESET;
314 /* Check the parameters */
315 assert_param(IS_GET_EXTI_LINE(EXTI_Line));
317 if ((*(__IO uint32_t *) (((uint32_t) &(EXTI->PR)) + ((EXTI_Line) >> 5 ) * 0x20)& (uint32_t)(1 << (EXTI_Line & 0x1F))) != (uint32_t)RESET)
330 * @brief Clears the EXTI's line pending bits.
331 * @param EXTI_Line: specifies the EXTI lines to clear.
332 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
335 void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
337 /* Check the parameters */
338 assert_param(IS_EXTI_LINE_EXT(EXTI_Line));
340 *(__IO uint32_t *) (((uint32_t) &(EXTI->PR)) + ((EXTI_Line) >> 5 ) * 0x20) = (1 << (EXTI_Line & 0x1F));
359 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/