try low power with PA0 from standby

This commit is contained in:
Yunhorn 2024-03-01 19:20:01 +08:00
parent 506aed609d
commit 91b0f31947
6 changed files with 54 additions and 19 deletions

View File

@ -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 */

View File

@ -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

View File

@ -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 */

View File

@ -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 */
}

View File

@ -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 */
}

View File

@ -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 */