STM32F10x_StdPeriph_Examples/IWDG/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    IWDG/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 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x.h"
00023 #include "stm32_eval.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Examples
00026   * @{
00027   */
00028 
00029 /** @addtogroup IWDG_Example
00030   * @{
00031   */ 
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 /* Private macro -------------------------------------------------------------*/
00036 /* Private variables ---------------------------------------------------------*/
00037 /* Private function prototypes -----------------------------------------------*/
00038 void SysTick_Configuration(void);
00039 
00040 /* Private functions ---------------------------------------------------------*/
00041 
00042 /**
00043   * @brief  Main program.
00044   * @param  None
00045   * @retval None
00046   */
00047 int main(void)
00048 {
00049   /*!< At this stage the microcontroller clock setting is already configured, 
00050        this is done through SystemInit() function which is called from startup
00051        file (startup_stm32f10x_xx.s) before to branch to application main.
00052        To reconfigure the default setting of SystemInit() function, refer to
00053        system_stm32f10x.c file
00054      */     
00055        
00056   /* Initialize LED1 and Key Button mounted on STM3210X-EVAL board */       
00057   STM_EVAL_LEDInit(LED1);
00058   STM_EVAL_LEDInit(LED2);
00059   STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
00060 
00061   /* Configure SysTick to generate an interrupt each 250ms */
00062   SysTick_Configuration();
00063 
00064   /* 1 bits for pre-emption priority and 3 bits for subpriority */
00065   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
00066 
00067   /* Set Button EXTI Interrupt priority to 0 (highest) */
00068   NVIC_SetPriority(KEY_BUTTON_EXTI_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0,0));
00069 
00070   /* Set SysTick interrupt vector Preemption Priority to 1 */
00071   NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),1,0));
00072 
00073 
00074   /* Check if the system has resumed from IWDG reset */
00075   if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
00076   {
00077     /* IWDGRST flag set */
00078     /* Turn on LED1 */
00079     STM_EVAL_LEDOn(LED1);
00080 
00081     /* Clear reset flags */
00082     RCC_ClearFlag();
00083   }
00084   else
00085   {
00086     /* IWDGRST flag is not set */
00087     /* Turn off LED1 */
00088     STM_EVAL_LEDOff(LED1);
00089   }
00090 
00091   /* IWDG timeout equal to 280 ms (the timeout may varies due to LSI frequency
00092      dispersion) */
00093   /* Enable write access to IWDG_PR and IWDG_RLR registers */
00094   IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
00095 
00096   /* IWDG counter clock: 40KHz(LSI) / 32 = 1.25 KHz */
00097   IWDG_SetPrescaler(IWDG_Prescaler_32);
00098 
00099   /* Set counter reload value to 349 */
00100   IWDG_SetReload(349);
00101 
00102   /* Reload IWDG counter */
00103   IWDG_ReloadCounter();
00104 
00105   /* Enable IWDG (the LSI oscillator will be enabled by hardware) */
00106   IWDG_Enable();
00107 
00108   while (1)
00109   {}
00110 }
00111 
00112 /**
00113   * @brief  Configures SysTick to generate an interrupt each 250ms.
00114   * @param  None
00115   * @retval None
00116   */
00117 void SysTick_Configuration(void)
00118 {
00119   /* SysTick interrupt each 250ms with counter clock equal to (HCLK/8) */
00120   if (SysTick_Config((SystemCoreClock/8) / 4))
00121   { 
00122     /* Capture error */
00123     while (1);
00124   }
00125 
00126   /* Select HCLK/8 as SysTick clock source */
00127   SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
00128 }
00129 
00130 #ifdef  USE_FULL_ASSERT
00131 /**
00132   * @brief  Reports the name of the source file and the source line number
00133   *         where the assert_param error has occurred.
00134   * @param  file: pointer to the source file name
00135   * @param  line: assert_param error line source number
00136   * @retval None
00137   */
00138 void assert_failed(uint8_t* file, uint32_t line)
00139 {
00140   /* User can add his own implementation to report the file name and line number,
00141      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00142 
00143   /* Infinite loop */
00144   while (1)
00145   {}
00146 }
00147 #endif
00148 
00149 /**
00150   * @}
00151   */
00152 
00153 /**
00154   * @}
00155   */
00156 
00157 /******************* (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