Example #1
1
/**
* @brief  Main program
* @param  None
* @retval None
*/
int main(void)
{
  /* STM32L0xx HAL library initialization:
       - Configure the Flash prefetch, Flash preread and Buffer caches
       - Systick timer is configured by default as source of time base, but user 
             can eventually implement his proper time base source (a general purpose 
             timer for example or other time source), keeping in mind that Time base 
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
             handled in milliseconds basis.
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure LED3 */
  BSP_LED_Init(LED3);

    /* Disable Prefetch Buffer */
  __HAL_FLASH_PREFETCH_BUFFER_DISABLE();

  /* Configure the system clock @ 32 KHz */
  SystemClock_Config();

  /* Configure the system Power */
  SystemPower_Config();

  while (1)
  {
    /*  Configure Key Button*/
    BSP_PB_Init(BUTTON_KEY,BUTTON_MODE_GPIO);

    /* Wait Until Key button pressed */
    while(BSP_PB_GetState(BUTTON_KEY) == RESET)
    {
    }
    /* Wait Until Key button pressed */
    while(BSP_PB_GetState(BUTTON_KEY) != RESET)
    {
    }

    /* Key button (EXTI_Line13) will be used to wakeup the system from SLEEP mode */
    BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);

    /* Enable the power down mode during Sleep mode */
    __HAL_FLASH_SLEEP_POWERDOWN_ENABLE();

      /*Suspend Tick increment to prevent wakeup by Systick interrupt. 
      Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/
    HAL_SuspendTick();
    
    /* Enter Sleep Mode , wake up is done once Key push button is pressed */
    HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
 
    /* Resume Tick interrupt if disabled prior to sleep mode entry*/
    HAL_ResumeTick();

  }
}
Example #2
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{

    /* STM32F3xx HAL library initialization:
         - Configure the Flash prefetch
         - Configure the Systick to generate an interrupt each 1 msec
         - Set NVIC Group Priority to 4
         - Low Level Initialization
       */
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /* Configure LED1 */
    BSP_LED_Init(LED1);

    /* Disable Prefetch Buffer */
    __HAL_FLASH_PREFETCH_BUFFER_DISABLE();


    while (1)
    {
        /* Insert 5 seconds delay */
        HAL_Delay(5000);

        /* Configure the system Power */
        SystemPower_Config();

        /* User push-button (line 15_10) will be used to wakeup the system from SLEEP mode */
        BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);

        /*Suspend Tick increment to prevent wakeup by Systick interrupt.
        Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/
        HAL_SuspendTick();

        /* Enter Sleep Mode , wake up is done once User push-button is pressed */
        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

        /* Resume Tick interrupt if disabled prior to SLEEP mode entry */
        HAL_ResumeTick();

        /* Re-configure LED1 */
        BSP_LED_Init(LED1);
    }
}