From 91b0f31947f4b85e629380aedf0f9ea47edee87f Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Fri, 1 Mar 2024 19:20:01 +0800 Subject: [PATCH] try low power with PA0 from standby --- Core/Inc/main.h | 1 + Core/Inc/sys_conf.h | 6 +++--- Core/Src/main.c | 39 +++++++++++++++++++++++++++++++++++---- Core/Src/stm32_lpm_if.c | 20 +++++++++++--------- Core/Src/stm32wlxx_it.c | 3 ++- Core/Src/sys_app.c | 4 ++-- 6 files changed, 54 insertions(+), 19 deletions(-) diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 38f24dd..f05fab8 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -28,6 +28,7 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32wlxx_hal.h" +#include "stm32wlxx_nucleo.h" #include "yunhorn_sts_prd_conf.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/Core/Inc/sys_conf.h b/Core/Inc/sys_conf.h index 4941614..a963a2e 100644 --- a/Core/Inc/sys_conf.h +++ b/Core/Inc/sys_conf.h @@ -47,12 +47,12 @@ extern "C" { /** * @brief Verbose level for all trace logs */ -#define VERBOSE_LEVEL VLEVEL_OFF +#define VERBOSE_LEVEL VLEVEL_H /** * @brief Enable trace logs */ -#define APP_LOG_ENABLED 0 +#define APP_LOG_ENABLED 1 /** * @brief Activate monitoring (probes) of some internal RF signals for debug purpose @@ -75,7 +75,7 @@ extern "C" { * @brief Enable/Disable MCU Debugger pins (dbg serial wires) * @note by HW serial wires are ON by default, need to put them OFF to save power */ -#define DEBUGGER_ENABLED 0 +#define DEBUGGER_ENABLED 1 /** * @brief Disable Low Power mode diff --git a/Core/Src/main.c b/Core/Src/main.c index f2085de..2e7ad1b 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -29,6 +29,7 @@ #include "sys_app.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "stm32wlxx_nucleo.h" #include "yunhorn_sts_sensors.h" #include "sts_cmox_hmac_sha.h" #ifdef STS_USE_TOF_VL53L0X @@ -57,7 +58,7 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ - +static void WkupPin1_Config(void); /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -102,6 +103,10 @@ int main(void) SystemClock_Config(); /* USER CODE BEGIN SysInit */ + /* Configure the wake_up pin */ + WkupPin1_Config(); + /* Un-comment to be able to debug after wake-up from Standby. Consumption will be increased */ + //HAL_DBGMCU_EnableDBGStandbyMode(); /* USER CODE END SysInit */ @@ -109,12 +114,27 @@ int main(void) MX_GPIO_Init(); MX_DMA_Init(); - LED_ON; + /* Check if the system was resumed from Standby mode */ + if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) + { + /* Clear Standby flag */ + __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); + HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET); /* LED_BLUE */ + HAL_Delay(300); + HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET); /* LED_BLUE */ - MX_I2C2_Init(); + } else + { - MX_LoRaWAN_Init(); + HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET); /* LED_ */ + HAL_Delay(300); + HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); /* LED_ */ + + MX_I2C2_Init(); + + MX_LoRaWAN_Init(); + } /* USER CODE BEGIN 2 */ @@ -183,6 +203,17 @@ void SystemClock_Config(void) } /* USER CODE BEGIN 4 */ +static void WkupPin1_Config(void) +{ + + /* Configure Button pin and unmask Wakeup with Interrupt request from line 0.*/ + BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI); + + /* Enable wake-up pin pull-up state in Standby mode.*/ + HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_A, PWR_GPIO_BIT_0); + HAL_PWREx_EnablePullUpPullDownConfig(); + +} /* USER CODE END 4 */ diff --git a/Core/Src/stm32_lpm_if.c b/Core/Src/stm32_lpm_if.c index 0743ca7..6f479a2 100644 --- a/Core/Src/stm32_lpm_if.c +++ b/Core/Src/stm32_lpm_if.c @@ -82,9 +82,13 @@ void PWR_EnterOffMode(void) { /* USER CODE BEGIN EnterOffMode_1 */ HAL_SuspendTick(); - /* Clear Status Flag before entering STOP/STANDBY Mode */ - LL_PWR_ClearFlag_C1STOP_C1STB(); - //__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); + + /* Enable WakeUp Pin PWR_WAKEUP_PIN1 connected to PA0 */ + HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW); + + /* Clear all related wakeup flags*/ + __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1); + HAL_PWR_EnterSTANDBYMode(); /* USER CODE END EnterOffMode_1 */ } @@ -93,12 +97,10 @@ void PWR_ExitOffMode(void) { /* USER CODE BEGIN ExitOffMode_1 */ HAL_ResumeTick(); - /* - __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); - __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); - HAL_PWR_EnableBkUpAccess(); - __HAL_RCC_RTCAPB_CLK_ENABLE(); - */ + + /* Clear Standby flag */ + __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); + /* USER CODE END ExitOffMode_1 */ } diff --git a/Core/Src/stm32wlxx_it.c b/Core/Src/stm32wlxx_it.c index 3bb6950..33b1dda 100644 --- a/Core/Src/stm32wlxx_it.c +++ b/Core/Src/stm32wlxx_it.c @@ -209,8 +209,9 @@ void SysTick_Handler(void) /* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */ + HAL_IncTick(); /* USER CODE BEGIN SysTick_IRQn 1 */ - + HAL_SYSTICK_IRQHandler(); /* USER CODE END SysTick_IRQn 1 */ } diff --git a/Core/Src/sys_app.c b/Core/Src/sys_app.c index 2839e9d..79cee28 100644 --- a/Core/Src/sys_app.c +++ b/Core/Src/sys_app.c @@ -122,8 +122,8 @@ void SystemApp_Init(void) /*Init low power manager*/ UTIL_LPM_Init(); /* Disable Stand-by mode */ - //UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE); - UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_ENABLE); + UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE); + //UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_ENABLE); #if defined (LOW_POWER_DISABLE) && (LOW_POWER_DISABLE == 1) /* Disable Stop Mode */