Esempio n. 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();

  }
}
Esempio n. 2
0
/**
  * @brief  Configure the system for power optimization
  *
  * @note	This API configures the system to be ready for low power mode
  * 		- Unused GPIO in Analog mode
  * 		- Fast Wakeup
  * 		- Verefint disabled in low power mode
  * 		- FLASH in low power mode
  *
  * @param  None
  * @retval None
  */
void SystemPower_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
  /**
  * Disable FLASH in SLEEP Mode
  */
  __HAL_FLASH_SLEEP_POWERDOWN_ENABLE();

  //SO: TO BE VERIFIED FOR L4
  /* Enable Power Clock */
  __HAL_RCC_PWR_CLK_ENABLE();
  
  /**
  * Enable Ultra low power and Fast wakeup as vrefint is not used in that project
  */
  //SO: TO BE VERIFIED FOR L4 (these APIs are not available for L4)
  //HAL_PWREx_EnableUltraLowPower();
  //HAL_PWREx_EnableFastWakeUp();

  /*
  * Select HSI as system clock source after Wake Up from Stop mode
  */
    //__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_StopWakeUpClock_MSI); //SO: TO BE VERIFIED FOR L4 (why not this?)
  __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_StopWakeUpClock_HSI);
  
  /*
  * Disable all GPIOs clock in SLEEP mode
  */
#if (JTAG_SUPPORTED == 0)
  __GPIOA_CLK_SLEEP_DISABLE();
#endif
  __GPIOB_CLK_SLEEP_DISABLE();
  __GPIOC_CLK_SLEEP_DISABLE();
  __GPIOD_CLK_SLEEP_DISABLE();
  __GPIOE_CLK_SLEEP_DISABLE(); //SO: TO BE VERIFIED FOR L4
  __GPIOF_CLK_SLEEP_DISABLE(); //SO: TO BE VERIFIED FOR L4
  __GPIOG_CLK_SLEEP_DISABLE(); //SO: TO BE VERIFIED FOR L4
  __GPIOH_CLK_SLEEP_DISABLE();
  
  /*
  * Enable GPIOs clock
  */
  __GPIOA_CLK_ENABLE();
  __GPIOB_CLK_ENABLE();
  __GPIOC_CLK_ENABLE();
  __GPIOD_CLK_ENABLE();
  __GPIOE_CLK_ENABLE(); //SO: TO BE VERIFIED FOR L4
  __GPIOF_CLK_ENABLE(); //SO: TO BE VERIFIED FOR L4
  __GPIOG_CLK_ENABLE(); //SO: TO BE VERIFIED FOR L4
  __GPIOH_CLK_ENABLE();

  /*
  * Configure all GPIO port pins in Analog mode with no pull
  */
  GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; //SO: TO BE VERIFIED FOR L4
  GPIO_InitStructure.Pull = GPIO_NOPULL;
  GPIO_InitStructure.Pin = GPIO_PIN_All;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
  HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
  HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
  HAL_GPIO_Init(GPIOE, &GPIO_InitStructure); //SO: TO BE VERIFIED FOR L4
  HAL_GPIO_Init(GPIOF, &GPIO_InitStructure); //SO: TO BE VERIFIED FOR L4
  HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); //SO: TO BE VERIFIED FOR L4
  HAL_GPIO_Init(GPIOH, &GPIO_InitStructure);
  
#if (JTAG_SUPPORTED == 1)
  GPIO_InitStructure.Pin = (GPIO_PIN_All ^ (GPIO_PIN_13 | GPIO_PIN_14));
#endif
  HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); 
  
  /*
  * Disable GPIOs clock
  */
  __GPIOA_CLK_DISABLE();
  __GPIOB_CLK_DISABLE();
  __GPIOC_CLK_DISABLE();
  __GPIOD_CLK_DISABLE();
  __GPIOE_CLK_DISABLE(); //SO: TO BE VERIFIED FOR L4
  __GPIOF_CLK_DISABLE(); //SO: TO BE VERIFIED FOR L4
  __GPIOG_CLK_DISABLE(); //SO: TO BE VERIFIED FOR L4
  __GPIOH_CLK_DISABLE();
  
  return;
}