Controllerstech-Co
Controllerstech-Co
Ad
There are 3 Low Poer Modes available in STM32, and they are as follows
ADVERTISEMENT
Ads by
SLEEP MODE
I will first start with the simplest one, which is SLEEP MODE. In this mode, CPU CLK
is turned OFF and there is no effect on other clocks or analog clock sources. The
current consumption is HIGHEST in this mode, compared to other Low Power
Modes.
Entry
In order to enter the SLEEP MODE, we must disable the systick interrupt first, or
else this interrupt will wake the MCU every time the interrupt gets triggered.
HAL_SuspendTick();
Next, we will enter the sleep mode by executing the WFI (Wait For Interrupt), or WFE
(Wait For Event) instructions. If the WFI instruction was used to enter the SLEEP
MODE, any peripheral interrupt acknowledged by the NVIC can wake up the device.
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
Wakeup
As mentioned above, I have entered the SLEEP MODE using the WFI instruction, so
the device will wakeup whenever any interrupt is triggered.
Inside the callback function we can resume the systick, so that we can use the
delay function again for the rest of the code.
SLEEPONEXIT
This is another feature available in SLEEP MODE, where the MCU will wake up
when the interrupt is triggered, it will process the ISR, and go back to sleep when the
ISR exits. This is useful when we want the controller to run only in the interrupt
mode.
HAL_PWR_EnableSleepOnExit ();
The above function must be called before going into the SLEEP MODE to activate
the sleeponexit feature. We can disable it by calling
HAL_PWR_DisableSleepOnExit ();
The entire code for the SLEEP MODE, with SLEEPONEXIT feature is shown below
main function
uint8_t Rx_data;
int main ()
{
......
......
HAL_UART_Receive_IT(&huart2, &Rx_data, 1);
while (1)
Basically, when the MCU wakes up because of the UART interrupt, it goes back to
sleep after processing the ISR (i.e after printing the string), but when it wakes up due
to the EXTI, the SLEEPONEXIT is disabled, and rest of the main function is
executed as usual.
STOP MODE
In Stop mode, all clocks in the 1.2 V domain are stopped, the PLLs, the HSI and the
HSE RC oscillators are disabled. Internal SRAM and register contents are
preserved. STOP MODE have may different categories depending on what should
be turned off. Below is the picture from the STM32F446RE reference manual
stop mode f4
Entry
Just like sleep mode, In order to enter the STOP MODE, we must disable the
systick interrupt, or else this interrupt will wake the MCU every time the interrupt
gets triggered.
HAL_SuspendTick();
Next, we will enter the sleep mode by executing the WFI (Wait For Interrupt), or WFE
(Wait For Event) instructions. If the WFI instruction was used to enter the STOP
MODE, EXTI, Independent watchdog (IWDG), or RTC can wake up the device. Also
I am using the first mode as shown in the picture above i.e. The main Regulator will
be turned off and only the LOW Power Regulator will be running.
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
Wakeup
As mentioned above, I have entered the STOP MODE using the WFI instruction, so
the device will wakeup whenever any interrupt is triggered by an EXTI, Independent
watchdog (IWDG), or RTC.
We must reconfigure the SYSTEM CLOCKS after wakeup, as they were disabled
when entering the STOP MODE. Also don’t forget to resume the systick.
SLEEPONEXIT
SleeponExit works the same way as it does for the SLEEP mode. You can check the
implementation above under the SLEEP mode.
main function
int main ()
{
The RTC Setup is very long, and it is explained in the VIDEO. DO check the video
below to understand it.
When the MCU enters the STOP MODE, it can be woken up by either RTC periodic
trigger, or by EXTI line. When the former wakes the MCU, the interrupt is
processed, where it will print the string, and than goes back in the STOP MODE.
Whereas, when the EXTI line wakes the device, the sleeponexit will be disabled,
and the main loop will run.
Ad
STANDBY MODE
The Standby mode allows to achieve the lowest power consumption. It is based on
the Cortex®-M4 with FPU deepsleep mode, with the voltage regulator disabled. The
1.2 V domain is consequently powered off. The PLLs, the HSI oscillator and the HSE
oscillator are also switched off.
Entry
Before entering the STANDBY MODE, we must disable the wakeup flags as shown
below
/* Clear the WU FLAG */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
Next, enable the wakeup pin, or the RTC periodic wakeup (if you want to use RTC)
HAL_PWR_EnterSTANDBYMode();
Wakeup
The standby wakeup is same as a system RESET. The entire code runs from the
beginning just as if it was a RESET. The only difference between a reset and a
STANDBY wakeup is that, when the MCU wakesup, The SBF status flag in the
PWR power control/status register (PWR_CSR) is set. The wakeup can be
triggered by WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC
wakeup, tamper event, time stamp event, external reset in NRST pin, IWDG reset.
main function
int main ()
{
..............
.............
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); // clear the flag
Ad
Ad
DOWNLOAD DONATE
Related Posts:
17 Comments. Leave
new
Reply
DJSG
April 24, 2023 2:08 PM
Reply
Liz
June 20, 2022 10:19 PM
Reply
admin
June 20, 2022 11:33 PM
The definition of
HAL_RTCEx_SetWakeUpTimer_IT
function is as follows:
HAL_RTCEx_SetWakeUpTimer_IT
(RTC_HandleTypeDef * hrtc,
uint32_t WakeUpCounter,
uint32_t WakeUpClock)
The “WakeUpCounter” is 32 bit
variable, so you can’t input
higher value than that.
You can adjust the clock and
other things as mentioned in the
comment section (where I have
used this function) to set the
time as per your need.
Reply
Liz
June 21, 2022 8:41 PM
Thanks!
Reply
Mariusz
March 27, 2022 2:07 AM
Reply
Tuan
June 16, 2022 11:52 AM
==> WakeUpCounter =
~5s/0.0005s = 10000 = 0x2710
Reply
zekoli
February 9, 2022 1:07 PM
HAL_GPIO_DeInit(GPIOC,
GPIO_PIN_13);
HAL_GPIO_DeInit(GPIOA,
SDIO_Pin);
HAL_GPIO_DeInit(GPIOA,GPO3_Pin);
HAL_GPIO_DeInit(GPIOA,BUZZER_Pin);
HAL_GPIO_DeInit(GPIOA,
GPIO_PIN_0);
HAL_GPIO_DeInit(GPIOA,
CSB_Pin);
HAL_GPIO_DeInit(GPIOA,FCSB_Pin);
HAL_GPIO_DeInit(GPIOA,SCLK_Pin);
HAL_UART_DeInit(&hlpuart1);
HAL_I2C_DeInit(&hi2c1);
HAL_ADC_DeInit(&hadc);
HAL_PWR_EnterSTANDBYMode();
Reply
Dhamodharan Krishnan
August 23, 2021 7:43 AM
Awesome explanation!
Reply
Muhammad Ahmed
June 1, 2021 3:26 PM
Thanks
Reply
Darryl
December 22, 2020 4:56 AM
Reply
Alex
November 30, 2020 2:29 AM
Many thanks!
But, I tried to wakeup stm32L053
(nucleo stm32l053) from ALARM A
and… nothing! Of course, I used the
directives:
__HAL_RTC_ALARM_CLEAR_FLAG(&hrtc,
RTC_FLAG_ALRAF);
__HAL_RTC_ALARMA_ENABLE(&hrtc)
before
HAL_PWR_EnterSTANDBYMode().
Reply
adam
September 5, 2020 3:22 PM
Reply
admin
September 6, 2020 10:03 AM
Reply
abdullah
June 27, 2020 4:46 PM
Reply
admin
June 28, 2020 12:12 AM
Reply
Mati
May 27, 2020 5:19 PM
Reply
Leave a Reply
Your email address will not be
published. Required fields are
marked *
Comment *
Name *
Email *
Post Comment
HOME
ABOUT US
Privacy Policy
SHOP WITH US
DONATE HERE
CONTACT US
email
Search