Electronic – How to obtain exactly the same state after deepsleep() mdbed function on a STM32L073RZ

low-powermbednucleortcstm32

I try to configure my STM32 to obtain the lowest power consumption. For that I'm using deepsleep() function from mbed librairies. Before that I disable GPIO with this function


void SystemPower_Config(void)
{
  /* Enable Power Control clock */
  __HAL_RCC_PWR_CLK_ENABLE();

  /* Enable Ultra low power mode */
  HAL_PWREx_EnableUltraLowPower();
  //pc.printf("1\r\n");

  /* Enable the fast wake up from Ultra low power mode */
  HAL_PWREx_EnableFastWakeUp();

  GPIO_InitTypeDef GPIO_InitStructure = {0};
  GPIO_InitStructure.Pin = GPIO_PIN_All;
  GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStructure.Pull = GPIO_NOPULL;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
  HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
  HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
  HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
  HAL_GPIO_Init(GPIOH, &GPIO_InitStructure);
  HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);
}

My main look like that


int main()
{
    Board_Init();
    while(1)
    {
        SystemPower_Config();
        wait(0.1);
        deepsleep();
    }
}

To generate interuption I use RTC alarms to leave the deepSleep mode. This part work fine but the problem is, the first time(during the first deepSleep) my consumption is equals to 1uA. After that my consumption is around 2.5uA on each deepSleep. So I think the deepSleep function change something the first time in the registrers or something like that. Have you any idea ?

Thank you very much for your help angain.

Simon NOWAK

Best Answer

I finally find the solution. Instead of using the function deepsleep I use HAL_PWR_EnterSTOPMode() function with the clear wake up flag. Like that

HAL_PWR_EnterSTOPMode(PWR_CR_LPSDSR | PWR_CR_CWUF, PWR_STOPENTRY_WFI);