cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WL3 status when wakeup from deep sleep not working

ola
Associate III

1. [Part Number] STM32WL33CC1
2. [Environment] Windows OS, STM32CubeIDE version 1.18.0, Firmware package STM32Cube FW_WL3 V1.1.0
3. [Schematics] STM32 Nucleo-64 development board
4. [Details] See below.
5. [Expected behavior] When the device is woken up from deep sleep the LD2 turns on
6. [How to reproduce]  Run ST PWR_DEEPSTOP example
7. [Occurrence] Consistent
8. [Sanity checks] I have tried reading various registers to see if I can see a difference in behaviour.

The following code is based on the ST PWR_DEEPSTOP example, with minor modifications, as indicated in the comments. However, it does not behave as expected.

Ideally, after a power-on reset, the device should blink LD1 for 5 seconds before entering deep sleep. It appears to do so, as the debugger disconnects likely due to various peripherals shutting down to conserve power.

The issue arises when the device is woken up by pressing the B1 button on the Nucleo-WL33 board. While the device does wake up as expected, it never reaches the section of code intended to check if it was woken from deep sleep.

Since debugging is not possible after waking up, I added code to turn on LD2 upon entering this block and turn it off afterward. However, this behavior is never observed, indicating that the block is never executed.

if (__HAL_PWR_GET_FLAG(PWR_FLAG_DEEPSTOPF) != RESET)
{
  BSP_LED_Off(LD2);
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_DEEPSTOPF);
}

 When program is ran, the LD2 comes on as expected but never gets turned off even though I am assuming that I am waking-up from a deep-sleep.

Question is what am I missing?

See full code below. I have slightly modified the standard ST example but adding the LD2 as explain alread.

 

#include "main.h"
#define LED_TOGGLE_DELAY         100UL
PWR_DEEPSTOPTypeDef sConfigDEEPSTOP;
static uint32_t TimingDelay = LED_TOGGLE_DELAY;

void SystemClock_Config(void);
void PeriphCommonClock_Config(void);
static void MX_GPIO_Init(void);

int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Configure the peripherals common clocks */
  PeriphCommonClock_Config();

  /* USER CODE BEGIN SysInit */

  /* Uncomment to be able to debug after wake-up from Deepstop. Consumption will be increased */
  //HAL_DBGMCU_EnableDBGDeepstopMode();

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */

  /* Configure LD1 */
  BSP_LED_Init(LD1);

  /* Configure LD2 */
  BSP_LED_Init(LD2);
  BSP_LED_On(LD2); 

  /* Configure LD3 for error handler */
  BSP_LED_Init(LD3);

  /* Check if the system was resumed from Deepstop mode */
  if (__HAL_PWR_GET_FLAG(PWR_FLAG_DEEPSTOPF) != RESET)
  {
    /* Turn off LD2 */
    BSP_LED_Off(LD2);

    /* Clear Deepstop flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_DEEPSTOPF);

    /* Check and Clear the Wakeup flag */
    if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUFA12) != RESET)
    {
      __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUFA12);
    }

    /* Wait that user release the USER push-button */
    BSP_PB_Init(B1, BUTTON_MODE_GPIO);
    while (BSP_PB_GetState(B1) == GPIO_PIN_RESET) {}
  }
 
  /* Initialize the USER push-button to generate external interrupts */
  BSP_PB_Init(B1, BUTTON_MODE_EXTI);

  /* Turn on LD1 */
  BSP_LED_On(LD1);
  /* Insert 5 seconds delay */
  HAL_Delay(5000);

  /* The Following Wakeup sequence is highly recommended prior to Deepstop mode entry
     - Enable wakeup
     - Clear wake up pin flag depending in edge detection & pin level.
     - Enter the Deepstop mode.
  */

  /* Enable WakeUp Pin PWR_WAKEUP_PIN0 connected to  */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PORTA, PWR_WAKEUP_PIN0, PWR_WUP_RISIEDG);
   /* Clear all related wakeup flags*/
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUFA12);
  sConfigDEEPSTOP.deepStopMode = PWR_DEEPSTOP_WITH_SLOW_CLOCK_ON;

  /* Enter the Deepstop mode */
  HAL_PWR_ConfigDEEPSTOP(&sConfigDEEPSTOP);
  HAL_PWR_EnterDEEPSTOPMode();

  /* USER CODE END 2 */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

Many thanks in advance.

 

Ola

0 REPLIES 0