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.
}
}
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):
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.
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.
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.
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?
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?
I came back to this topic because the issue is still there.
Currently I am using mbed-os-5.15 because last project did’t work at all so I decided to start againg with an updated OS. Mbed 6 was no an option for this.
I am using Mbed Studio with ARMC6.
I have 5mA of current consumption with an empty main()