99 lines
2.2 KiB
C
99 lines
2.2 KiB
C
|
|
#include "main.h"
|
|
#include "pwr_user.h"
|
|
#include "rtc.h"
|
|
#include "usart.h"
|
|
|
|
|
|
extern uint8_t Usart2_RxBuff[USART_RX_LENGTH];
|
|
|
|
|
|
/**
|
|
* @brief System Power Configuration
|
|
* The system Power is configured as follow :
|
|
* + Regulator in LP mode
|
|
* + VREFINT OFF, with fast wakeup enabled
|
|
* + HSI as SysClk after Wake Up
|
|
* + No IWDG
|
|
* + Automatic Wakeup using RTC clocked by LSI (after ~4s)
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void SystemPower_Config(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
/* Enable Ultra low power mode */
|
|
HAL_PWREx_EnableUltraLowPower();
|
|
|
|
/* Enable the fast wake up from Ultra low power mode */
|
|
HAL_PWREx_EnableFastWakeUp();
|
|
|
|
/* Select HSI as system clock source after Wake Up from Stop mode */
|
|
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
|
|
|
|
/* Enable GPIOs clock */
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
|
|
/* Configure all GPIO port pins in Analog Input mode (floating input trigger OFF) */
|
|
GPIO_InitStructure.Pin = GPIO_PIN_All;
|
|
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
|
|
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
|
// HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
|
|
HAL_GPIO_Init(GPIOH, &GPIO_InitStructure);
|
|
|
|
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|
|
|
/* Disable GPIOs clock */
|
|
__HAL_RCC_GPIOA_CLK_DISABLE();
|
|
__HAL_RCC_GPIOB_CLK_DISABLE();
|
|
__HAL_RCC_GPIOC_CLK_DISABLE();
|
|
__HAL_RCC_GPIOD_CLK_DISABLE();
|
|
__HAL_RCC_GPIOH_CLK_DISABLE();
|
|
|
|
}
|
|
|
|
void low_power_set(uint32_t WakeUpCounter_t)
|
|
{
|
|
SystemPower_Config();
|
|
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
|
|
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, WakeUpCounter_t, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
|
|
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|