Arm Mbed and Pelion Device Management support forum

NUCLEO-L073RZ Sleep mode & current consumption

Hello, I am trying to sleep my NUCLEO-L073RZ without success. What I really want is to set the device in to a “Stop mode 0.86 µA” I have not clue how to do it. I was looking everywhere for documentation regarding mbed-OS (last version) but nothing worked for me.
I used sleep(), deepsleep(), HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE),thread_sleep_for(), etc… and nothing worked, the device is consumption is always arround 1.5mA.

The main:

#include “mbed.h”
int main(){
printf(“Starting…\r\n” );
while(1) {
printf(“Hello!\r\n” );
thread_sleep_for(20000); //sleep for 20 seconds.
}
}

mbed_app.json:

{
    "config": {
        "thread_stack_size": { "value": 1024 },
        "main_stack_size": { "value": 1024 }
    },
    "target_overrides": {
        "*": {
            "platform.stdio-convert-newlines": true,
            "platform.stdio-baud-rate": 115200,
            "platform.default-serial-baud-rate": 115200,
            "target.stdio_uart_tx": "PA_9",
            "target.stdio_uart_rx": "PA_10",
            "target.lpticker_lptim": 0,
            "events.use-lowpower-timer-ticker": true
        }
    },
    "macros": []
}

Any idea how to sleep the device?

Regards

There’s actually quite a lot to do in most cases to reduce power consumption to the stated levels. You have to remember that the levels stated in the datasheets are the absolute minimum.

For example, you’ll need to set your GPIO pins to high impedance to minimise leakage currents (you’ll need it for all ports):

__HAL_RCC_GPIOA_CLK_ENABLE();

GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin = GPIO_PIN_All;
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

__HAL_RCC_GPIOA_CLK_DISABLE();

You’ll need to clear the reset flags in the CR register:

__HAL_RCC_CLEAR_RESET_FLAGS();
SET_BIT(PWR->CR, PWR_CR_CWUF);

Enable ultra-low power:

HAL_PWREx_EnableUltraLowPower();

I think you need to ensure the RTC is initialised. It may or may not prevent you from actually going into a deep sleep mode:

rtc_init();

And then you’re pretty much ready to get into a low power mode, in this case Standby:

HAL_PWR_EnterSTANDBYMode();

Of course; if you’ve other peripherals on the board (such as LEDs or regulators) then you need to consider these parts and their impact on your measurements.

Hope this helps,
Adam

Hello @amitchone I was all day trying the code you provided me without success, in most cases the device restarts itself without crashing ( seems to loop the main() function very rare… ).
Will be fine to get the source/info of those __HAL…functions(), it’s interesting that nothing about is documented in the ARM Mbed website.
I just need to set the device into sleep for a 10 minutes. It will be fine if I reach at least ~8 µA while sleeping.

Any additional info will be appreciated.

Thank you.

Hey Johnny,

Here’s a library that you may find extremely useful. It will put your device into Standby mode for a specified number of seconds. I seem to recall using this a while ago and it just working.

The source for the __HAL() functions can be found in mbed-os/targets/TARGET_STM/TARGET_STM32L0/device. You’ll be most interested in stm32l0xx_hal_pwr and pwr_ex. You may also find some useful stuff in rcc and rcc_ex.

It seems strange that your device restarts in a loop; can you check the reset reason? There’s an Mbed ResetReason API but you can also check the RCC and CSR registers if you need to.

Hope this helps,
Adam

Hi Adam, with your instructions I am actually close to get a conclusion (I will post it, were involved HW issues too) about this issue.
Now I am arround ~8 µA while sleeping so it is fine.
The new issue is the “RawSerial myserial(PA_2, PA_3)” when I add this to the code the device sucks ~20mA , it seem to be always awake. I just do a short myserial.putc(0x01).
What I have to do to sleep after using the Serial?

Thank you.

Hey Johnny,

I’m glad you’re getting close! The issue you are having with your UART sounds strangely similar to this issue that I had a while back. It was to do with an incorrect pin mapping in the Targets’ pinmap. You’ll have to check this against the alternate function table in the processor’s datasheet.

If this isn’t the issue I’d then assume that, when creating the RawSerial object, it initialises some clock or peripheral that you’ll need to manually turn off when entering the sleep mode? What happens when the object is destructed?

Hope this helps,
Adam

My STDIO pins are:
“target.stdio_uart_tx”: “PA_9”,
“target.stdio_uart_rx”: “PA_10”,
and the RawSerial pins:
PA_2 and PA_3

I didn’t see any pin conflict there.
I think it is something ralated with the sleep lock or something like that.