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

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

• Isn't the implementation of the STM32 libraries open source? The easiest is probably to have a look at the deepSleep code, the answer should be there. If you find it, be sure to answer your own question here. – dim Dec 19 '16 at 16:33
• I allready try to find something in the HAL_PWR_EnterSTOPMode function. But I did not see anything. – Simon NOWAK Dec 20 '16 at 8:37
• You should post your answer as an answer... – Sean Houlihane Dec 23 '16 at 0:16

HAL_PWR_EnterSTOPMode(PWR_CR_LPSDSR | PWR_CR_CWUF, PWR_STOPENTRY_WFI);