4

I'm attempting to cause an STM32WL (currently on a WL55JC1 devboard) to sleep using the shutdown mode, and am running into a an issue where the MCU immediately exits sleep after it enters it.

Here's what I'm using to get into sleep:

                    Radio.Sleep();
                    HAL_SUBGHZ_MspDeInit(&hsubghz);
                    LL_RCC_RF_EnableReset();
                    __disable_irq();
                    HAL_SuspendTick();
                    HAL_PWREx_DisableSRAMRetention();
                    HAL_PWREx_EnableFlashPowerDown(PWR_FLASHPD_LPSLEEP);
                    HAL_PWR_DisablePVD();
                    HAL_SUBGHZ_ExecSetCmd(&hsubghz, RADIO_SET_SLEEP, 0x0000, 2);
                    HAL_Delay(3000);

                    HAL_PWREx_EnterSHUTDOWNMode();

When going into sleep, I attempt to suspend the systick, and then use the HAL macro to enter the shutdown sleep mode. From what I've read this seems to be all I need, but obviously not in this case.

The exit from sleep happens regardless of the onboard ST-Link module on my devboard being powered or not.

NRST is currently floating, since when I pull it to ground the chip shuts down and pulls 700uA. Another puzzle to figure out.

Edit: Not sure if it will help, but here's my system clock config:

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure LSE Drive Capability
  */
  HAL_PWR_EnableBkUpAccess();
  __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
  /** Configure the main internal regulator output voltage
  */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3|RCC_CLOCKTYPE_HCLK
                              |RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
                              |RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}
Todd Rylaarsdam
  • 438
  • 6
  • 19
  • What should trigger the wake up for you? In your main code, you just resuming tick after entering shutdown mode... Resume Tick generates an interrupt so it might be the one waking the system up. – Shravya Boggarapu Dec 17 '21 at 13:30
  • I'm triggering wakeup via the NRST pin. I've updated the code snippets to reflect what I'm currently trying. At this point I get down to about 3mA of power consumption (so the module is in some sort of sleep, just not shutdown), but can't get it any lower. – Todd Rylaarsdam Dec 17 '21 at 21:03
  • Apparently unlikely, but what about some pending interrupt before you go sleep? – WITC Oct 19 '22 at 09:20

1 Answers1

0

Turns out I just needed to clear a few flags before going to sleep. It's also important to set all GPIO to GPIO_PIN_RESET. I wasn't able to measure a difference but that's the word from my ST FAE.

Radio.Sleep();

/* Enable wake-up pin pull-up state in Standby mode.*/
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);

/* Clear all related wakeup flags*/
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WRFBUSY);

/* Enter the Standby mode */
HAL_PWREx_EnterSHUTDOWNMode();
Todd Rylaarsdam
  • 438
  • 6
  • 19