#include "main.h" #include "clock_conf.h" #include "rtc_conf.h" #include "led_conf.h" #include "lpuart.h" #include "bc660.h" #include "sleep_conf.h" #include "gpio_conf.h" uint32_t counter = 0; void SystemClock_Config(void); void Configure_PWR(void); void EnterStop2Mode(void); int main(void) { /* Configure the system clock to 80 MHz */ SystemClock_Config(); /* Configure Power IP */ Configure_PWR(); /* Infinite loop */ while (1) { /* Enter Stop mode 2 */ EnterStop2Mode(); /* At this point, MCU just wakes up from Stop mode 2 */ } } void SystemClock_Config(void) { /* HSI configuration and activation */ LL_RCC_HSI_Enable(); while(LL_RCC_HSI_IsReady() != 1) { }; /* Sysclk activation on the HSI */ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) { }; /* Set AHB & APB1 & APB2 prescaler*/ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Disable MSI */ LL_RCC_MSI_Disable(); while(LL_RCC_MSI_IsReady() != 0) { }; /* Set systick to 1ms in using frequency set to 16MHz */ LL_Init1msTick(16000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(16000000); } void Configure_PWR(void) { /* Enable Power Clock */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); /* Ensure that HSI is wake-up system clock */ LL_RCC_SetClkAfterWakeFromStop(LL_RCC_STOP_WAKEUPCLOCK_HSI); } void EnterStop2Mode(void) { /* ######## ENABLE WUT #################################################*/ /* Disable RTC registers write protection */ LL_RTC_DisableWriteProtection(RTC); /* Enable wake up counter and wake up interrupt */ /* Note: Periodic wakeup interrupt should be enabled to exit the device from low-power modes.*/ LL_RTC_EnableIT_WUT(RTC); LL_RTC_WAKEUP_Enable(RTC); /* Enable RTC registers write protection */ LL_RTC_EnableWriteProtection(RTC); /* ######## ENTER IN STANDBY MODE ######################################*/ /** Request to enter STANDBY mode * Following procedure describe in STM32L4xx Reference Manual * See PWR part, section Low-power modes, Standby mode */ /* Reset Internal Wake up flag */ LL_RTC_ClearFlag_WUT(RTC); /* Check that PWR Internal Wake-up is enabled */ if (LL_PWR_IsEnabledFastWakeUp() == 0) { /* Need to enable the Internal Wake-up line */ LL_PWR_EnableFastWakeUp(); } /* Set Stand-by mode */ LL_PWR_SetPowerMode(LL_PWR_MODE_STOP); /* Set SLEEPDEEP bit of Cortex System Control Register */ LL_LPM_EnableDeepSleep(); /* This option is used to ensure that store operations are completed */ #if defined ( __CC_ARM) __force_stores(); #endif /* Request Wait For Interrupt */ __WFI(); } #ifdef USE_FULL_ASSERT void assert_failed(uint8_t *file, uint32_t line) { while (1) { } } #endif