STM32F0xx Standard Peripherals Firmware Library: main.c Source File

STM32F0xx Standard Peripherals Library

STM32F0xx_StdPeriph_Examples/EXTI/EXTI_Example/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    EXTI/EXTI_Example/main.c
00004   * @author  MCD Application Team
00005   * @version V1.4.0
00006   * @date    24-July-2014
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "main.h"
00030 
00031 /** @addtogroup STM32F0xx_StdPeriph_Examples
00032   * @{
00033   */
00034 
00035 /** @addtogroup EXTI_Example
00036   * @{
00037   */
00038 
00039 /* Private typedef -----------------------------------------------------------*/
00040 /* Private define ------------------------------------------------------------*/
00041 /* Private macro -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 EXTI_InitTypeDef   EXTI_InitStructure;
00044 GPIO_InitTypeDef   GPIO_InitStructure;
00045 NVIC_InitTypeDef   NVIC_InitStructure;
00046 
00047 /* Private function prototypes -----------------------------------------------*/
00048 static void EXTI0_Config(void);
00049 #ifdef USE_STM32072B_EVAL 
00050 static void EXTI2_3_Config(void);
00051 #endif
00052 static void EXTI4_15_Config(void);
00053 
00054 /* Private functions ---------------------------------------------------------*/
00055 
00056 /**
00057   * @brief  Main program.
00058   * @param  None
00059   * @retval None
00060   */
00061 int main(void)
00062 {
00063   /*!< At this stage the microcontroller clock setting is already configured, 
00064        this is done through SystemInit() function which is called from startup
00065        file (startup_stm32f0xx.s) before to branch to application main.
00066        To reconfigure the default setting of SystemInit() function, refer to
00067        system_stm32f0xx.c file
00068      */
00069 
00070   /* Initialize LEDs mounted on EVAL board */
00071   STM_EVAL_LEDInit(LED1);
00072   STM_EVAL_LEDInit(LED2);
00073   STM_EVAL_LEDInit(LED3);
00074   STM_EVAL_LEDInit(LED4);
00075 
00076   /* Configure PA0 in interrupt mode */
00077   EXTI0_Config();
00078 
00079   /* Configure PE3, PE2 in interrupt mode only for STM32072B devices*/  
00080 #ifdef USE_STM32072B_EVAL
00081   EXTI2_3_Config();
00082 #endif
00083   
00084   /* Configure PC13 in interrupt mode */
00085   EXTI4_15_Config();
00086 
00087   /* Generate software interrupt: simulate a falling edge applied on EXTI8 line */
00088   EXTI_GenerateSWInterrupt(EXTI_Line8);
00089 
00090   /* Infinite loop */
00091   while (1)
00092   {
00093   }
00094 }
00095 
00096 /**
00097   * @brief  Configure PA0 in interrupt mode
00098   * @param  None
00099   * @retval None
00100   */
00101 static void EXTI0_Config(void)
00102 {
00103   /* Enable GPIOA clock */
00104   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
00105 
00106   /* Configure PA0 pin as input floating */
00107   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
00108   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
00109   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
00110   GPIO_Init(GPIOA, &GPIO_InitStructure);
00111 
00112   /* Enable SYSCFG clock */
00113   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
00114   /* Connect EXTI0 Line to PA0 pin */
00115   SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
00116 
00117   /* Configure EXTI0 line */
00118   EXTI_InitStructure.EXTI_Line = EXTI_Line0;
00119   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00120   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
00121   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00122   EXTI_Init(&EXTI_InitStructure);
00123 
00124   /* Enable and set EXTI0 Interrupt */
00125   NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
00126   NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
00127   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00128   NVIC_Init(&NVIC_InitStructure);
00129 }
00130 
00131 /**
00132   * @brief  Configure PE3, PE0in interrupt mode
00133   * @param  None
00134   * @retval None
00135   */
00136 #ifdef USE_STM32072B_EVAL 
00137 static void EXTI2_3_Config(void)
00138 {
00139   /* Enable GPIOE clock */
00140   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);
00141 
00142   /* Configure PE3 and PE2 pins as input floating */
00143   
00144   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;
00145   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
00146   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
00147   GPIO_Init(GPIOE, &GPIO_InitStructure);
00148 
00149   /* Enable SYSCFG clock */
00150   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
00151 
00152   /* Connect EXTI3 Line to PE3 pin */
00153   SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource3);
00154 
00155   /* Connect EXTI2 Line to PE2 pin */
00156   SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource2);
00157 
00158   /* Configure EXTI3 line */
00159   EXTI_InitStructure.EXTI_Line = EXTI_Line3;
00160   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00161   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
00162   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00163   EXTI_Init(&EXTI_InitStructure);
00164 
00165   /* Configure EXTI2 line */
00166   EXTI_InitStructure.EXTI_Line = EXTI_Line2;
00167   EXTI_Init(&EXTI_InitStructure);
00168 
00169   /* Enable and set EXTI2_3 Interrupt */
00170   NVIC_InitStructure.NVIC_IRQChannel = EXTI2_3_IRQn;
00171   NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
00172   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00173   NVIC_Init(&NVIC_InitStructure);
00174 
00175 }
00176 #endif
00177 
00178 /**
00179   * @brief  Configure PC13 in interrupt mode
00180   * @param  None
00181   * @retval None
00182   */
00183 static void EXTI4_15_Config(void)
00184 {
00185   /* Enable GPIOC clock */
00186   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
00187 
00188   /* Enable SYSCFG clock */
00189   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
00190 
00191 #ifdef USE_STM320518_EVAL 
00192   /* Configure PC9 pin as input floating */
00193   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
00194   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
00195   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
00196   GPIO_Init(GPIOC, &GPIO_InitStructure);
00197   
00198   /* Connect EXTI9 Line to PC9 pin */
00199   SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource9);
00200   
00201   /* Configure EXTI9 line */
00202   EXTI_InitStructure.EXTI_Line = EXTI_Line9;
00203   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00204   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
00205   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00206   EXTI_Init(&EXTI_InitStructure);
00207 
00208 #endif
00209   
00210   /* Configure PC8 and PC13 pins as input floating */
00211   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_13;
00212   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
00213   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
00214   GPIO_Init(GPIOC, &GPIO_InitStructure);
00215   
00216    /* Connect EXTI8 Line to PC8 pin */
00217   SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource8);
00218   
00219   /* Connect EXTI13 Line to PC13 pin */
00220   SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource13);
00221   
00222   /* Configure EXTI8 line */
00223   EXTI_InitStructure.EXTI_Line = EXTI_Line8;  
00224   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00225   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
00226   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00227   EXTI_Init(&EXTI_InitStructure);
00228   
00229   /* Configure EXTI13 line */
00230   EXTI_InitStructure.EXTI_Line = EXTI_Line13;
00231   EXTI_Init(&EXTI_InitStructure);
00232   
00233   /* Enable and set EXTI4_15 Interrupt */
00234   NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;
00235   NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
00236   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00237   NVIC_Init(&NVIC_InitStructure);
00238 
00239 }
00240 #ifdef  USE_FULL_ASSERT
00241 
00242 /**
00243   * @brief  Reports the name of the source file and the source line number
00244   *         where the assert_param error has occurred.
00245   * @param  file: pointer to the source file name
00246   * @param  line: assert_param error line source number
00247   * @retval None
00248   */
00249 void assert_failed(uint8_t* file, uint32_t line)
00250 {
00251   /* User can add his own implementation to report the file name and line number,
00252      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00253 
00254   /* Infinite loop */
00255   while (1)
00256   {
00257   }
00258 }
00259 #endif
00260 
00261 /**
00262   * @}
00263   */
00264 
00265 /**
00266   * @}
00267   */
00268 
00269 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

 For complete documentation on STM32 Microcontrollers visit www.st.com/STM32