Exemple #1
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{

  /* Initialize LED1 and LED2 mounted on STM8L152X-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);

  /* Initialize Key and Joystick down push-buttons mounted on STM8L152X-EVAL board */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI);

  /* enable interrupts */
  enableInterrupts();

  /* Check if the MCU has resumed from WWDG reset */
  if (RST_GetFlagStatus(RST_FLAG_WWDGF) != RESET)
  {
    /* WWDGF flag set */
    /* Toggle LED1 */
    for (Index = 7; Index != 0; Index--)
    {
      STM_EVAL_LEDToggle(LED1);
      Delay(0x7FFF);
    }
    /* Clear WWDGF Flag */
    RST_ClearFlag(RST_FLAG_WWDGF);
  }

  /* WWDG Configuration */
  WWDG_Config();

  while (1)
  {
    /* Check if WWDG counter refresh is allowed in Allowed window */
    if (AllowedRefresh != DISABLE)
    {
      /* get WWDG counter value */
      /* wait until WWDG counter becomes lower than window value */
      while ((WWDG_GetCounter() & 0x7F) > WINDOW_VALUE);
      /* Refresh WWDG counter during allowed window so no MCU reset will occur */
      WWDG_SetCounter(COUNTER_INIT);
    }

    /* Check if WWDG counter refresh is allowed in non Allowed window */
    if (NonAlowedRefresh != DISABLE)
    {
      /* wait until WWDG counter becomes higher than window value */
      while ((WWDG_GetCounter() & 0x7F) < WINDOW_VALUE);
      /* Refresh WWDG counter during non allowed window so MCU reset will occur */
      WWDG_SetCounter(COUNTER_INIT);
    }
    /* Toggle LED2 */
    STM_EVAL_LEDToggle(LED2);
    Delay(0x6FFF);
  }
}
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */ 
  /* Initialize LEDs and Tamper Button mounted on EVAL board */       
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI);

  /* Check if the system has resumed from WWDG reset */
  if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
  { 
    /* WWDGRST flag set */
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);

    /* Clear reset flags */
    RCC_ClearFlag();
  }
  else
  {
    /* WWDGRST flag is not set */
    /* Turn off LED1 */
    STM_EVAL_LEDOff(LED1);
   }
  
  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(SystemCoreClock / 1000))
  { 
    /* Capture error */ 
    while (1)
    {}
  }
  
  /* Configure WWDG */
  WWDG_Config();
   
  while (1)
  {
    /* Toggle LED2 */
    STM_EVAL_LEDToggle(LED2);

    /* Insert 33 ms delay */
    Delay(33);

    /* Update WWDG counter */
    WWDG_SetCounter(127);
  }
}