STM32F10x_StdPeriph_Examples/WWDG/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    WWDG/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body.
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm32f10x.h"
00024 #include "stm32_eval.h"
00025 
00026 /** @addtogroup STM32F10x_StdPeriph_Examples
00027   * @{
00028   */
00029 
00030 /** @addtogroup WWDG_Example
00031   * @{
00032   */ 
00033 
00034 /* Private typedef -----------------------------------------------------------*/
00035 /* Private define ------------------------------------------------------------*/
00036 /* Private macro -------------------------------------------------------------*/
00037 /* Private variables ---------------------------------------------------------*/
00038 /* Private function prototypes -----------------------------------------------*/
00039 void NVIC_Configuration(void);
00040 
00041 /* Private functions ---------------------------------------------------------*/
00042 
00043 /**
00044   * @brief  Main program.
00045   * @param  None
00046   * @retval None
00047   */
00048 int main(void)
00049 {
00050   /*!< At this stage the microcontroller clock setting is already configured, 
00051        this is done through SystemInit() function which is called from startup
00052        file (startup_stm32f10x_xx.s) before to branch to application main.
00053        To reconfigure the default setting of SystemInit() function, refer to
00054        system_stm32f10x.c file
00055      */     
00056 
00057   /* Initialize LED1 and Key Button mounted on STM3210X-EVAL board */       
00058   STM_EVAL_LEDInit(LED1);
00059   STM_EVAL_LEDInit(LED2);
00060   STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
00061 
00062 
00063   /* Check if the system has resumed from WWDG reset */
00064   if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
00065   { 
00066     /* WWDGRST flag set */
00067     /* Turn on LED1 */
00068     STM_EVAL_LEDOn(LED1);
00069 
00070     /* Clear reset flags */
00071     RCC_ClearFlag();
00072   }
00073   else
00074   {
00075     /* WWDGRST flag is not set */
00076     /* Turn off LED1 */
00077     STM_EVAL_LEDOff(LED1);
00078   }
00079 
00080   /* NVIC configuration */
00081   NVIC_Configuration();
00082 
00083   /* WWDG configuration */
00084   /* Enable WWDG clock */
00085   RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
00086 
00087 /* On Value line devices, WWDG clock counter = (PCLK1 (24MHz)/4096)/8 = 732 Hz (~1366 ęs)  */
00088 /* On other devices, WWDG clock counter = (PCLK1(36MHz)/4096)/8 = 1099 Hz (~910 ęs)  */
00089   WWDG_SetPrescaler(WWDG_Prescaler_8);
00090 
00091   /* Set Window value to 65 */
00092   WWDG_SetWindowValue(65);
00093 
00094   /* On Value line devices, Enable WWDG and set counter value to 127, WWDG timeout = ~1366 ęs * 64 = 87.42 ms */
00095   /* On other devices, Enable WWDG and set counter value to 127, WWDG timeout = ~910 ęs * 64 = 58.25 ms */
00096   WWDG_Enable(127);
00097 
00098   /* Clear EWI flag */
00099   WWDG_ClearFlag();
00100 
00101   /* Enable EW interrupt */
00102   WWDG_EnableIT();
00103 
00104   while (1)
00105   {
00106   }
00107 }
00108 
00109 /**
00110   * @brief  Configures NVIC.
00111   * @param  None
00112   * @retval None
00113   */
00114 void NVIC_Configuration(void)
00115 {
00116   NVIC_InitTypeDef NVIC_InitStructure;
00117   
00118   /* 1 bits for pre-emption priority and 3 bits for subpriority */
00119   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
00120 
00121   /* Set Button EXTI Interrupt priority to 0 (highest) */
00122   NVIC_SetPriority(KEY_BUTTON_EXTI_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0,0));
00123 
00124   /* Set WWDG interrupt vector Preemption Priority to 1 */
00125   NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
00126   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
00127   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
00128   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00129   NVIC_Init(&NVIC_InitStructure);
00130 }
00131 
00132 #ifdef  USE_FULL_ASSERT
00133 /**
00134   * @brief  Reports the name of the source file and the source line number
00135   *         where the assert_param error has occurred.
00136   * @param  file: pointer to the source file name
00137   * @param  line: assert_param error line source number
00138   * @retval None
00139   */
00140 void assert_failed(uint8_t* file, uint32_t line)
00141 {
00142   /* User can add his own implementation to report the file name and line number,
00143      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00144 
00145   /* Infinite loop */
00146   while (1)
00147   {}
00148 }
00149 #endif
00150 
00151 /**
00152   * @}
00153   */ 
00154 
00155 /**
00156   * @}
00157   */ 
00158 
00159 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32