2 ******************************************************************************
3 * @file stm32f30x_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
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 2014 STMicroelectronics</center></h2>
65 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
66 * You may not use this file except in compliance with the License.
67 * You may obtain a copy of the License at:
69 * http://www.st.com/software_license_agreement_liberty_v2
71 * Unless required by applicable law or agreed to in writing, software
72 * distributed under the License is distributed on an "AS IS" BASIS,
73 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
74 * See the License for the specific language governing permissions and
75 * limitations under the License.
77 ******************************************************************************
80 /* Includes ------------------------------------------------------------------*/
81 #include "stm32f30x_exti.h"
83 /** @addtogroup STM32F30x_StdPeriph_Driver
88 * @brief EXTI driver modules
93 /* Private typedef -----------------------------------------------------------*/
94 /* Private define ------------------------------------------------------------*/
95 #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
97 /* Private macro -------------------------------------------------------------*/
98 /* Private variables ---------------------------------------------------------*/
99 /* Private function prototypes -----------------------------------------------*/
100 /* Private functions ---------------------------------------------------------*/
102 /** @defgroup EXTI_Private_Functions
106 /** @defgroup EXTI_Group1 Initialization and Configuration functions
107 * @brief Initialization and Configuration functions
110 ===============================================================================
111 ##### Initialization and Configuration functions #####
112 ===============================================================================
119 * @brief Deinitializes the EXTI peripheral registers to their default reset
124 void EXTI_DeInit(void)
126 EXTI
->IMR
= 0x1F800000;
127 EXTI
->EMR
= 0x00000000;
128 EXTI
->RTSR
= 0x00000000;
129 EXTI
->FTSR
= 0x00000000;
130 EXTI
->SWIER
= 0x00000000;
131 EXTI
->PR
= 0xE07FFFFF;
132 EXTI
->IMR2
= 0x0000000C;
133 EXTI
->EMR2
= 0x00000000;
134 EXTI
->RTSR2
= 0x00000000;
135 EXTI
->FTSR2
= 0x00000000;
136 EXTI
->SWIER2
= 0x00000000;
137 EXTI
->PR2
= 0x00000003;
141 * @brief Initializes the EXTI peripheral according to the specified
142 * parameters in the EXTI_InitStruct.
143 * EXTI_Line specifies the EXTI line (EXTI0....EXTI35).
144 * EXTI_Mode specifies which EXTI line is used as interrupt or an event.
145 * EXTI_Trigger selects the trigger. When the trigger occurs, interrupt
146 * pending bit will be set.
147 * EXTI_LineCmd controls (Enable/Disable) the EXTI line.
148 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure that
149 * contains the configuration information for the EXTI peripheral.
154 void EXTI_Init(EXTI_InitTypeDef
* EXTI_InitStruct
)
158 /* Check the parameters */
159 assert_param(IS_EXTI_MODE(EXTI_InitStruct
->EXTI_Mode
));
160 assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct
->EXTI_Trigger
));
161 assert_param(IS_EXTI_LINE_ALL(EXTI_InitStruct
->EXTI_Line
));
162 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct
->EXTI_LineCmd
));
164 tmp
= (uint32_t)EXTI_BASE
;
166 if (EXTI_InitStruct
->EXTI_LineCmd
!= DISABLE
)
168 /* Clear EXTI line configuration */
169 *(__IO
uint32_t *) (((uint32_t) &(EXTI
->IMR
)) + ((EXTI_InitStruct
->EXTI_Line
) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct
->EXTI_Line
& 0x1F));
170 *(__IO
uint32_t *) (((uint32_t) &(EXTI
->EMR
)) + ((EXTI_InitStruct
->EXTI_Line
) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct
->EXTI_Line
& 0x1F));
172 tmp
+= EXTI_InitStruct
->EXTI_Mode
+ (((EXTI_InitStruct
->EXTI_Line
) >> 5 ) * 0x20);
174 *(__IO
uint32_t *) tmp
|= (uint32_t)(1 << (EXTI_InitStruct
->EXTI_Line
& 0x1F));
176 tmp
= (uint32_t)EXTI_BASE
;
178 /* Clear Rising Falling edge configuration */
179 *(__IO
uint32_t *) (((uint32_t) &(EXTI
->RTSR
)) + ((EXTI_InitStruct
->EXTI_Line
) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct
->EXTI_Line
& 0x1F));
180 *(__IO
uint32_t *) (((uint32_t) &(EXTI
->FTSR
)) + ((EXTI_InitStruct
->EXTI_Line
) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct
->EXTI_Line
& 0x1F));
182 /* Select the trigger for the selected interrupts */
183 if (EXTI_InitStruct
->EXTI_Trigger
== EXTI_Trigger_Rising_Falling
)
185 /* Rising Falling edge */
186 *(__IO
uint32_t *) (((uint32_t) &(EXTI
->RTSR
)) + ((EXTI_InitStruct
->EXTI_Line
) >> 5 ) * 0x20) |= (uint32_t)(1 << (EXTI_InitStruct
->EXTI_Line
& 0x1F));
187 *(__IO
uint32_t *) (((uint32_t) &(EXTI
->FTSR
)) + ((EXTI_InitStruct
->EXTI_Line
) >> 5 ) * 0x20) |= (uint32_t)(1 << (EXTI_InitStruct
->EXTI_Line
& 0x1F));
191 tmp
+= EXTI_InitStruct
->EXTI_Trigger
+ (((EXTI_InitStruct
->EXTI_Line
) >> 5 ) * 0x20);
193 *(__IO
uint32_t *) tmp
|= (uint32_t)(1 << (EXTI_InitStruct
->EXTI_Line
& 0x1F));
199 tmp
+= EXTI_InitStruct
->EXTI_Mode
+ (((EXTI_InitStruct
->EXTI_Line
) >> 5 ) * 0x20);
201 /* Disable the selected external lines */
202 *(__IO
uint32_t *) tmp
&= ~(uint32_t)(1 << (EXTI_InitStruct
->EXTI_Line
& 0x1F));
208 * @brief Fills each EXTI_InitStruct member with its reset value.
209 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
213 void EXTI_StructInit(EXTI_InitTypeDef
* EXTI_InitStruct
)
215 EXTI_InitStruct
->EXTI_Line
= EXTI_LINENONE
;
216 EXTI_InitStruct
->EXTI_Mode
= EXTI_Mode_Interrupt
;
217 EXTI_InitStruct
->EXTI_Trigger
= EXTI_Trigger_Rising_Falling
;
218 EXTI_InitStruct
->EXTI_LineCmd
= DISABLE
;
222 * @brief Generates a Software interrupt on selected EXTI line.
223 * @param EXTI_Line: specifies the EXTI line on which the software interrupt
225 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
228 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line
)
230 /* Check the parameters */
231 assert_param(IS_EXTI_LINE_EXT(EXTI_Line
));
233 *(__IO
uint32_t *) (((uint32_t) &(EXTI
->SWIER
)) + ((EXTI_Line
) >> 5 ) * 0x20) |= (uint32_t)(1 << (EXTI_Line
& 0x1F));
241 /** @defgroup EXTI_Group2 Interrupts and flags management functions
242 * @brief EXTI Interrupts and flags management functions
245 ===============================================================================
246 ##### Interrupts and flags management functions #####
247 ===============================================================================
249 This section provides functions allowing to configure the EXTI Interrupts
250 sources and check or clear the flags or pending bits status.
257 * @brief Checks whether the specified EXTI line flag is set or not.
258 * @param EXTI_Line: specifies the EXTI line flag to check.
259 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
260 * @retval The new state of EXTI_Line (SET or RESET).
262 FlagStatus
EXTI_GetFlagStatus(uint32_t EXTI_Line
)
264 FlagStatus bitstatus
= RESET
;
266 /* Check the parameters */
267 assert_param(IS_GET_EXTI_LINE(EXTI_Line
));
269 if ((*(__IO
uint32_t *) (((uint32_t) &(EXTI
->PR
)) + ((EXTI_Line
) >> 5 ) * 0x20)& (uint32_t)(1 << (EXTI_Line
& 0x1F))) != (uint32_t)RESET
)
281 * @brief Clears the EXTI's line pending flags.
282 * @param EXTI_Line: specifies the EXTI lines flags to clear.
283 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
286 void EXTI_ClearFlag(uint32_t EXTI_Line
)
288 /* Check the parameters */
289 assert_param(IS_EXTI_LINE_EXT(EXTI_Line
));
291 *(__IO
uint32_t *) (((uint32_t) &(EXTI
->PR
)) + ((EXTI_Line
) >> 5 ) * 0x20) = (1 << (EXTI_Line
& 0x1F));
295 * @brief Checks whether the specified EXTI line is asserted or not.
296 * @param EXTI_Line: specifies the EXTI line to check.
297 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
298 * @retval The new state of EXTI_Line (SET or RESET).
300 ITStatus
EXTI_GetITStatus(uint32_t EXTI_Line
)
302 ITStatus bitstatus
= RESET
;
304 /* Check the parameters */
305 assert_param(IS_GET_EXTI_LINE(EXTI_Line
));
307 if ((*(__IO
uint32_t *) (((uint32_t) &(EXTI
->PR
)) + ((EXTI_Line
) >> 5 ) * 0x20)& (uint32_t)(1 << (EXTI_Line
& 0x1F))) != (uint32_t)RESET
)
320 * @brief Clears the EXTI's line pending bits.
321 * @param EXTI_Line: specifies the EXTI lines to clear.
322 * This parameter can be any combination of EXTI_Linex where x can be (0..20).
325 void EXTI_ClearITPendingBit(uint32_t EXTI_Line
)
327 /* Check the parameters */
328 assert_param(IS_EXTI_LINE_EXT(EXTI_Line
));
330 *(__IO
uint32_t *) (((uint32_t) &(EXTI
->PR
)) + ((EXTI_Line
) >> 5 ) * 0x20) = (1 << (EXTI_Line
& 0x1F));
349 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/