STM32F0xx Standard Peripherals Firmware Library: main.c Source File

STM32F0xx Standard Peripherals Library

STM32F0xx_StdPeriph_Examples/IWDG/IWDG_WindowMode/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    IWDG/IWDG_WindowMode/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 IWDG_WindowMode
00036   * @{
00037   */
00038 
00039 /* Private typedef -----------------------------------------------------------*/
00040 /* Private define ------------------------------------------------------------*/
00041 /* Private typedef -----------------------------------------------------------*/
00042 /* Private define ------------------------------------------------------------*/
00043 /* Private macro -------------------------------------------------------------*/
00044 /* Private variables ---------------------------------------------------------*/
00045 __IO uint32_t TimingDelay = 0;
00046 
00047 /* Private function prototypes -----------------------------------------------*/
00048 /* Private functions ---------------------------------------------------------*/
00049 
00050 /**
00051   * @brief  Main program.
00052   * @param  None
00053   * @retval None
00054   */
00055 int main(void)
00056 {
00057   /*!< At this stage the microcontroller clock setting is already configured, 
00058        this is done through SystemInit() function which is called from startup
00059        file (startup_stm32f0xx.s) before to branch to application main.
00060        To reconfigure the default setting of SystemInit() function, refer to
00061        system_stm32f0xx.c file
00062      */ 
00063   /* Initialize LEDs and Tamper Button mounted on EVAL board */       
00064   STM_EVAL_LEDInit(LED1);
00065   STM_EVAL_LEDInit(LED2);
00066   STM_EVAL_LEDInit(LED3);
00067   STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI);
00068 
00069   /* Check if the system has resumed from IWDG reset */
00070   if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
00071   { 
00072     /* IWDGRST flag set */
00073     /* Turn on LED1 */
00074     STM_EVAL_LEDOn(LED1);
00075 
00076     /* Clear reset flags */
00077     RCC_ClearFlag();
00078   }
00079   else
00080   {
00081     /* IWDGRST flag is not set */
00082     /* Turn off LED1 */
00083     STM_EVAL_LEDOff(LED1);
00084    }
00085   
00086   /* Setup SysTick Timer for 1 msec interrupts  */
00087   if (SysTick_Config(SystemCoreClock / 1000))
00088   { 
00089     /* Capture error */ 
00090     while (1)
00091     {}
00092   }
00093   
00094   /********************* IWDG configuration ***********************************/
00095   /* Enable IWDG, set reload and window values to 2000 and 1000, respectively. 
00096      In this case the refresh window is:
00097      (2000-1000) / (LSI/16) = ~400 ms < refresh window < 2000 / (LSI/16) = ~800 ms
00098 
00099         Note: the refresh window may varies due to LSI frequency dispersion 
00100         ----
00101      */
00102 
00103   /* Enable IWDG (the LSI oscillator will be enabled by hardware) */
00104   IWDG_Enable();
00105 
00106   /* Enable write access to IWDG_PR and IWDG_RLR registers */
00107   IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
00108 
00109   /* Set IWDG Prescaler value to 16 */
00110   IWDG_SetPrescaler(IWDG_Prescaler_16);
00111 
00112   /* Set IWDG Reload value to 2000 */
00113   IWDG_SetReload(2000);
00114   
00115   /* Wait until RVU flag is reset to be sure that the reload value
00116      update operation is completed */
00117   while(IWDG_GetFlagStatus(IWDG_FLAG_RVU) != RESET);
00118   
00119   /* Set the IWDG window value to 1000 */
00120   IWDG_SetWindowValue(1000);
00121    
00122   while (1)
00123   {
00124     /* Toggle LED2 */
00125     STM_EVAL_LEDToggle(LED2);
00126 
00127     /* Insert 750 ms delay */
00128     Delay(750);
00129     
00130     /* Reload IWDG counter */
00131     IWDG_ReloadCounter();
00132   }
00133 }
00134 
00135 /**
00136   * @brief  Inserts a delay time.
00137   * @param  nTime: specifies the delay time length, in 1 ms.
00138   * @retval None
00139   */
00140 void Delay(__IO uint32_t nTime)
00141 {
00142   TimingDelay = nTime;
00143 
00144   while(TimingDelay != 0);
00145 }
00146 
00147 /**
00148   * @brief  Decrements the TimingDelay variable.
00149   * @param  None
00150   * @retval None
00151   */
00152 void TimingDelay_Decrement(void)
00153 {
00154   if (TimingDelay != 0x00)
00155   { 
00156     TimingDelay--;
00157   }
00158 }
00159 
00160 #ifdef  USE_FULL_ASSERT
00161 
00162 /**
00163   * @brief  Reports the name of the source file and the source line number
00164   *         where the assert_param error has occurred.
00165   * @param  file: pointer to the source file name
00166   * @param  line: assert_param error line source number
00167   * @retval None
00168   */
00169 void assert_failed(uint8_t* file, uint32_t line)
00170 { 
00171   /* User can add his own implementation to report the file name and line number,
00172      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00173 
00174   /* Infinite loop */
00175   while (1)
00176   {
00177   }
00178 }
00179 #endif
00180 
00181 /**
00182   * @}
00183   */
00184 
00185 /**
00186   * @}
00187   */
00188 
00189 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

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