comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/EXTI/EXTI_Config/main.c @ 0:c59513fd84fb

Initial commit of STM32 test code.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 03 Oct 2011 21:19:15 +1030
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c59513fd84fb
1 /**
2 ******************************************************************************
3 * @file EXTI/EXTI_Config/main.c
4 * @author MCD Application Team
5 * @version V3.5.0
6 * @date 08-April-2011
7 * @brief Main program body
8 ******************************************************************************
9 * @attention
10 *
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 *
18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
20 */
21
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x.h"
24 #include "stm32_eval.h"
25
26 /** @addtogroup STM32F10x_StdPeriph_Examples
27 * @{
28 */
29
30 /** @addtogroup EXTI_Config
31 * @{
32 */
33
34 /* Private typedef -----------------------------------------------------------*/
35 /* Private define ------------------------------------------------------------*/
36 /* Private macro -------------------------------------------------------------*/
37 /* Private variables ---------------------------------------------------------*/
38 EXTI_InitTypeDef EXTI_InitStructure;
39 GPIO_InitTypeDef GPIO_InitStructure;
40 NVIC_InitTypeDef NVIC_InitStructure;
41
42 /* Private function prototypes -----------------------------------------------*/
43 void EXTI0_Config(void);
44 void EXTI9_5_Config(void);
45
46 /* Private functions ---------------------------------------------------------*/
47
48 /**
49 * @brief Main program.
50 * @param None
51 * @retval None
52 */
53 int main(void)
54 {
55 /*!< At this stage the microcontroller clock setting is already configured,
56 this is done through SystemInit() function which is called from startup
57 file (startup_stm32f10x_xx.s) before to branch to application main.
58 To reconfigure the default setting of SystemInit() function, refer to
59 system_stm32f10x.c file
60 */
61
62 /* Initialize LED1 and Key Button mounted on STM3210X-EVAL board */
63 STM_EVAL_LEDInit(LED1);
64 STM_EVAL_LEDInit(LED2);
65
66 /* Configure PA.00 in interrupt mode */
67 EXTI0_Config();
68
69 /* Configure PB.09 or PG.08 in interrupt mode */
70 EXTI9_5_Config();
71
72 /* Generate software interrupt: simulate a falling edge applied on EXTI0 line */
73 EXTI_GenerateSWInterrupt(EXTI_Line0);
74
75 while (1)
76 {
77 }
78 }
79
80 /**
81 * @brief Configure PA.00 in interrupt mode
82 * @param None
83 * @retval None
84 */
85 void EXTI0_Config(void)
86 {
87 /* Enable GPIOA clock */
88 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
89
90 /* Configure PA.00 pin as input floating */
91 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
92 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
93 GPIO_Init(GPIOA, &GPIO_InitStructure);
94
95 /* Enable AFIO clock */
96 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
97
98 /* Connect EXTI0 Line to PA.00 pin */
99 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
100
101 /* Configure EXTI0 line */
102 EXTI_InitStructure.EXTI_Line = EXTI_Line0;
103 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
104 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
105 EXTI_InitStructure.EXTI_LineCmd = ENABLE;
106 EXTI_Init(&EXTI_InitStructure);
107
108 /* Enable and set EXTI0 Interrupt to the lowest priority */
109 NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
110 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
111 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
112 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
113 NVIC_Init(&NVIC_InitStructure);
114 }
115
116 /**
117 * @brief Configure PB.09 or PG.08 in interrupt mode
118 * @param None
119 * @retval None
120 */
121 void EXTI9_5_Config(void)
122 {
123 #if defined (STM32F10X_HD_VL) || defined (STM32F10X_HD) || defined (STM32F10X_XL)
124 /* Enable GPIOG clock */
125 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);
126
127 /* Configure PG.08 pin as input floating */
128 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
129 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
130 GPIO_Init(GPIOG, &GPIO_InitStructure);
131
132 /* Enable AFIO clock */
133 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
134 /* Connect EXTI8 Line to PG.08 pin */
135 GPIO_EXTILineConfig(GPIO_PortSourceGPIOG, GPIO_PinSource8);
136
137 /* Configure EXTI8 line */
138 EXTI_InitStructure.EXTI_Line = EXTI_Line8;
139 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
140 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
141 EXTI_InitStructure.EXTI_LineCmd = ENABLE;
142 EXTI_Init(&EXTI_InitStructure);
143
144 /* Enable and set EXTI9_5 Interrupt to the lowest priority */
145 NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
146 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
147 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
148 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
149
150 NVIC_Init(&NVIC_InitStructure);
151 #else
152 /* Enable GPIOB clock */
153 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
154
155 /* Configure PB.09 pin as input floating */
156 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
157 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
158 GPIO_Init(GPIOB, &GPIO_InitStructure);
159
160 /* Enable AFIO clock */
161 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
162 /* Connect EXTI9 Line to PB.09 pin */
163 GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
164
165 /* Configure EXTI9 line */
166 EXTI_InitStructure.EXTI_Line = EXTI_Line9;
167 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
168 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
169 EXTI_InitStructure.EXTI_LineCmd = ENABLE;
170 EXTI_Init(&EXTI_InitStructure);
171
172 /* Enable and set EXTI9_5 Interrupt to the lowest priority */
173 NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
174 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
175 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
176 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
177
178 NVIC_Init(&NVIC_InitStructure);
179 #endif
180 }
181
182 #ifdef USE_FULL_ASSERT
183
184 /**
185 * @brief Reports the name of the source file and the source line number
186 * where the assert_param error has occurred.
187 * @param file: pointer to the source file name
188 * @param line: assert_param error line source number
189 * @retval None
190 */
191 void assert_failed(uint8_t* file, uint32_t line)
192 {
193 /* User can add his own implementation to report the file name and line number,
194 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
195
196 /* Infinite loop */
197 while (1)
198 {
199 }
200 }
201
202 #endif
203
204 /**
205 * @}
206 */
207
208 /**
209 * @}
210 */
211
212 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/