STM32 Low Power Modes: Sleep, Stop and Standby with HAL
Battery life is often what decides whether a prototype can become a product. STM32 microcontrollers offer three hardware low power modes, which are Sleep, Stop, and Standby. Together they cover a range of current from a few milliamps down to about 2 µA, and each mode makes a different trade-off between wake-up speed, available peripherals, and memory retention.
This tutorial explains all three modes with complete HAL code. It includes working wake-up examples that use an external interrupt, the UART, the RTC wake-up timer, and the wake-up pin, and it shows the current measured on an STM32F103 Blue Pill. Each mode has its own section and its own video, so you can jump to the mode you need or read the sections in order.
The three modes differ in the following way:
- Sleep mode stops the CPU, while all the peripherals keep running.
- Stop mode stops all the internal clocks and keeps the contents of the RAM and the registers, which reduces the power consumption a lot.
- Standby mode powers off the 1.2 V domain, which gives the lowest power consumption. Almost all internal state is lost, except for the backup registers, the backup SRAM, and the RTC when they are powered.
Several examples use the UART and the RTC. If you need a refresher, the STM32 UART interrupt receive tutorial and the STM32 internal RTC tutorial cover those parts in detail.
Table of contents
STM32 Low Power Modes Overview
STM32 microcontrollers offer several low power modes so that the current can be reduced while the device is idle. The right mode depends on how quickly the device must react and how much state it must keep. This choice matters most in battery-powered and energy-sensitive designs.
Sleep, Stop and Standby Compared
In Sleep mode, the CPU is halted while the peripheral clocks keep running. Timers, the UART, and the ADC stay active, and the MCU resumes quickly on an interrupt. This mode suits short idle periods that need a low wake-up latency.
In Stop mode, all the clocks, including the system clock, are switched off, while the contents of the RAM and the registers are kept. The voltage regulator can run in main or low-power mode, and the MCU can wake up through an external interrupt, the RTC, or the independent watchdog. This mode suits applications that wake up at regular intervals.
In Standby mode, the 1.2 V domain is powered off, so the CPU, most peripherals, and the SRAM lose their contents. Only the backup domain and the RTC survive. When the MCU wakes up, it starts from a reset. This mode suits devices that stay idle for long periods and can afford a full restart.
Power Consumption of the STM32F103
The table below gives typical values for an STM32F103 on a Blue Pill at 3.3 V. The exact numbers depend on the mode, the regulator setting, and the board. You can measure the current with an ammeter in series with VDD.
| Mode | Typical current | Wake-up time | Keeps RAM | Typical use |
|---|---|---|---|---|
| Sleep | About 2 to 5 mA | Fast | Yes | Short idle periods with active timers |
| Stop | About 20 to 100 µA | Medium | Yes | Periodic wake-up, sleeping sensors |
| Standby | About 1 to 5 µA | Slow | No | Battery-powered deep sleep |
STM32 Low Power Modes Feature Comparison
The table below compares the three modes in more detail.
| Feature | Sleep mode | Stop mode | Standby mode |
|---|---|---|---|
| CPU | Stopped | Stopped | Powered off |
| Voltage regulator | On | Main or low-power regulator, selectable | Off |
| Clocks | Running unless disabled by hand | HSI, HSE, and PLL off, RTC, LSI, and LSE can stay on | All off except LSI or LSE when the RTC is used |
| SRAM and registers | Kept | Kept | Lost, except the backup domain and the RTC |
| Wake-up sources | Any interrupt | EXTI, RTC, IWDG | Wake-up pin, RTC, NRST, IWDG |
| Wake-up time | Very short | Moderate | Long, because of the reset sequence |
| Power saving | Lowest | Medium | Highest |
| Reset on wake-up | No | No | Yes, similar to a power-on reset |
Sleep is the right choice for short idle periods, Stop is the right choice for a low current with a quick resume, and Standby is the right choice for the highest saving when the MCU can restart on every wake-up.
STM32 Sleep Mode with HAL
Sleep mode is the simplest low power mode. Only the CPU clock is stopped, and the other clocks and the analog sources are not affected. For that reason, the current in this mode is the highest of the three low power modes.
Enter Sleep Mode
The SysTick interrupt must be suspended before the MCU enters Sleep mode. Otherwise the periodic SysTick interrupt wakes the MCU up again after a millisecond.
HAL_SuspendTick(); // Disable the SysTick interruptThe MCU then enters Sleep mode with either the WFI (Wait For Interrupt) or the WFE (Wait For Event) instruction. With WFI, any peripheral interrupt that the NVIC accepts wakes the device.
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);Wake Up from Sleep Mode
Because the MCU entered Sleep mode with WFI, any enabled interrupt wakes it up. A GPIO external interrupt is one example. The callback below resumes the SysTick, so that delays and other time-based functions work again after the wake-up.
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
HAL_ResumeTick(); // Re-enable SysTick after wake-up
}SLEEPONEXIT in Sleep Mode
STM32 devices have a feature called SLEEPONEXIT, which sends the MCU back to Sleep mode automatically after it has served an interrupt. It works in three steps:
- The MCU wakes up when an interrupt occurs.
- It runs the interrupt service routine (ISR).
- When the ISR ends, the MCU goes straight back to Sleep mode, and it does not return to the main loop.
This is useful in event-driven applications where the CPU only has to handle interrupts and has no background work in the main loop. Enable the feature with the first function below, and disable it again with the second one:
HAL_PWR_EnableSleepOnExit();HAL_PWR_DisableSleepOnExit();Use SLEEPONEXIT with care. If the main loop is empty or never reached, the MCU never runs it again, so the feature is best suited for interrupt-only applications such as ultra-low-power sensor nodes.
Full Sleep Mode Code Example
The example below combines Sleep mode with SLEEPONEXIT. The MCU wakes up from either a UART interrupt or an external interrupt on the user button.
char *str;
uint8_t Rx_data;
// SleepOnExit will be applicable when the MCU is wake up by UART
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(huart, &Rx_data, 1);
str = "WakeUP from SLEEP by UART\r\n";
HAL_UART_Transmit(&huart2, (uint8_t *)str, strlen (str), HAL_MAX_DELAY);
}
// SleepOnExit will be disabled when the MCU is wake up by EXTI
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
str = "WakeUP from SLEEP by EXTI\r\n";
HAL_UART_Transmit(&huart2, (uint8_t *)str, strlen (str), HAL_MAX_DELAY);
HAL_PWR_DisableSleepOnExit ();
}
int main ()
{
......
......
HAL_UART_Receive_IT(&huart2, &Rx_data, 1);
while (1)
{
str = "Going into SLEEP MODE in 5 seconds\r\n";
HAL_UART_Transmit(&huart2, (uint8_t *)str, strlen (str), HAL_MAX_DELAY);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 1);
HAL_Delay(5000);
/* Suspend Tick increment to prevent wakeup by Systick interrupt.
Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)
*/
HAL_SuspendTick();
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 0); // Just to indicate that the sleep mode is activated
HAL_PWR_EnableSleepOnExit ();
// Enter Sleep Mode , wake up is done once User push-button is pressed
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
// Resume Tick interrupt if disabled prior to sleep mode entry
HAL_ResumeTick();
str = "WakeUP from SLEEP\r\n";
HAL_UART_Transmit(&huart2, (uint8_t *)str, strlen (str), HAL_MAX_DELAY);
for (int i=0; i<20; i++)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(100);
}
}
}Sleep Mode Test Result
The image above shows the MCU entering Sleep mode and waking up again. The black arrow marks a wake-up by the UART interrupt. After the ISR has printed its string, the MCU goes back to sleep without running any code of the main loop, which shows that SLEEPONEXIT works.
The blue and green arrows mark wake-ups by the external interrupt. The EXTI callback disables SLEEPONEXIT, so the MCU returns to the main loop and runs the rest of the code as usual.
Video Tutorial: STM32 Sleep Mode
The video below demonstrates Sleep mode on a Blue Pill. It covers entering Sleep with HAL_PWR_EnterSLEEPMode(), suspending the SysTick to prevent unwanted wake-ups, using SLEEPONEXIT, waking up from the UART and an EXTI, and measuring the current.
STM32 Stop Mode with RTC Wake-Up
Stop mode saves much more power than Sleep mode. All the clocks of the 1.2 V domain are stopped, and the PLLs and the HSI and HSE oscillators are disabled. With the low-power regulator selected, the main regulator is off as well. The contents of the SRAM and the registers are preserved, so the program can continue where it stopped after the wake-up.
Stop mode comes in several variants, depending on which parts of the chip are switched off. The image below is taken from the STM32F446RE reference manual and lists them.
Enter Stop Mode
As in Sleep mode, the SysTick interrupt must be suspended first, so that it does not wake the MCU.
HAL_SuspendTick(); // Disable SysTick to avoid unwanted wake-upsThe MCU then enters Stop mode with WFI or WFE. With WFI, an interrupt from the EXTI, the RTC, or the IWDG wakes the MCU. With WFE, an event wakes it. The example below uses WFI with the low-power regulator.
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);Wake Up from Stop Mode
When the MCU enters Stop mode with WFI, the following sources can wake it up:
- An external interrupt (EXTI)
- The independent watchdog (IWDG)
- An RTC alarm or wake-up event
The system clocks are not restored automatically after the wake-up. The code must therefore configure the system clock again and resume the SysTick:
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == GPIO_PIN_13) // Example: wake-up by button on pin 13
{
SystemClock_Config(); // Reconfigure system clocks
HAL_ResumeTick(); // Resume SysTick
}
}If the clock is not configured again, the core and the peripherals run from the default oscillator, so the baud rates, the timers, and the delays behave in unexpected ways.
SLEEPONEXIT in Stop Mode
SLEEPONEXIT works in Stop mode in the same way as in Sleep mode. The MCU wakes up on an interrupt, runs the ISR, and goes back to Stop mode as soon as the ISR ends. The calls are the same as before:
HAL_PWR_EnableSleepOnExit();HAL_PWR_DisableSleepOnExit();Full Stop Mode Code Example
The example below puts the MCU into Stop mode with two wake-up sources, which are the RTC wake-up timer and an external interrupt on pin 13.
// SleepOnExit will be applicable when the MCU is wake up by RTC
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
{
SystemClock_Config ();
HAL_ResumeTick();
char *str = "WAKEUP FROM RTC\n NOW GOING IN STOP MODE AGAIN\n\n";
HAL_UART_Transmit(&huart2, (uint8_t *) str, strlen (str), HAL_MAX_DELAY);
}
// SleepOnExit will be disabled when the MCU is wake up by EXTI
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == GPIO_PIN_13)
{
SystemClock_Config ();
HAL_ResumeTick();
char *str = "WAKEUP FROM EXTII\n\n";
HAL_UART_Transmit(&huart2, (uint8_t *) str, strlen (str), HAL_MAX_DELAY);
HAL_PWR_DisableSleepOnExit();
}
}
int main ()
{
.......
.......
.......
/*## Configure the Wake up timer ###########################################*/
/* RTC Wake-up Interrupt Generation:
Wake-up Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI))
==> WakeUpCounter = Wake-up Time / Wake-up Time Base
To configure the wake up timer to 10s the WakeUpCounter is set to 0x4E20:
RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16
Wake-up Time Base = 16 /(32KHz) = 0.0005 seconds
==> WakeUpCounter = ~10s/0.0005s = 20000 = 0x4E20 */
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x4E20, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
/****** Suspend the Ticks before entering the STOP mode or else this can wake the device up **********/
HAL_SuspendTick();
HAL_PWR_EnableSleepOnExit();
/* Enter Stop Mode */
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
for (int i=0; i<10; i++)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(1000);
}
while (1)
{
.....
}
}The RTC wake-up timer used here is available on families such as the STM32F4, L4, and G4. The STM32F103 does not have it. On an F103, use the RTC alarm as the wake-up source instead.
The parts of the code work as follows:
HAL_RTCEx_WakeUpTimerEventCallback()runs when the RTC wake-up timer expires. It configures the system clock again, resumes the SysTick, and sends a message over the UART. Because SLEEPONEXIT is enabled, the MCU then returns to Stop mode on its own.HAL_GPIO_EXTI_Callback()runs when the button on pin 13 is pressed. It also configures the clock, resumes the SysTick, and sends a message. In addition, it callsHAL_PWR_DisableSleepOnExit(), so the MCU stays awake and the main program continues.- The setup in
main()configures the RTC wake-up timer for about 10 seconds with a counter of0x4E20and the LSI clock divided by 16. It suspends the SysTick, enables SLEEPONEXIT, and enters Stop mode with the low-power regulator.
After the MCU leaves Stop mode, the code disables the wake-up timer, toggles an LED 10 times, and continues into the infinite loop.
Stop Mode Test Result
The RTC setup is long, and the video below walks through it step by step.
The red arrow marks the point where the MCU enters Stop mode. The yellow arrow marks a wake-up by the RTC. The ISR runs, and the MCU goes back to Stop mode, which shows that SLEEPONEXIT works. The blue arrow marks a wake-up by the external interrupt. In this case the ISR disables SLEEPONEXIT, so the MCU does not return to Stop mode and continues with the main loop.
Video Tutorial: STM32 Stop Mode
The video below covers Stop mode in detail. It shows how to enter Stop with HAL_PWR_EnterSTOPMode(), how to configure the RTC wake-up timer, how to restore the system clock after the wake-up, how SLEEPONEXIT behaves with the RTC and EXTI sources, and how to measure the current.
STM32 Standby Mode with HAL
Standby mode gives the lowest power consumption of all the modes. The voltage regulator is disabled, which powers off the 1.2 V domain. The PLLs and the HSI and HSE oscillators are switched off. Only the backup registers, the RTC, and the standby circuitry keep their state. The mode is based on the deep-sleep state of the Cortex-M core, and it is meant for devices that stay idle most of the time and wake up only now and then.
Enter Standby Mode
The wake-up flags must be cleared before the MCU enters Standby mode. A flag that is still set causes an immediate wake-up.
/* Clear wake-up flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
/* Clear RTC wake-up flag */
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);Next, configure the wake-up source. It can be the wake-up pin (PA0 on this board), the RTC wake-up timer, or both. The example below enables both, with a timer of about 5 seconds:
/* Enable wake-up pin */
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
/* Configure RTC wake-up timer for ~5s */
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x2710, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
{
Error_Handler();
}The counter value comes from the same formula as in Stop mode. The time base is 16 / 32 kHz = 0.5 ms, so 5 s divided by 0.5 ms gives a counter of 10,000, which is 0x2710.
Finally, enter Standby mode:
HAL_PWR_EnterSTANDBYMode();Wake Up from Standby Mode
A wake-up from Standby mode is the same as a system reset. The program starts again at the reset vector, as after a power-on or a hardware reset. The only sign that the reset came from Standby mode is the SBF flag in the PWR_CSR register.
The following events can wake the MCU up:
- A rising edge on a wake-up pin (WKUP)
- An RTC alarm A or B, or an RTC wake-up event
- A tamper or timestamp event
- A reset on the NRST pin
- The independent watchdog (IWDG)
Full Standby Mode Code Example
The program below enters Standby mode and wakes up through the RTC or the wake-up pin.
int main(void)
{
...
/* Check if waking from Standby */
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); // Clear flag
char *str = "Wakeup from STANDBY MODE\n\n";
HAL_UART_Transmit(&huart2, (uint8_t *)str, strlen(str), HAL_MAX_DELAY);
/* Blink LED */
for (int i = 0; i < 20; i++)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(200);
}
/* Disable wake-up pin and RTC wake-up */
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
}
/* Prepare for Standby */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
char *str = "About to enter STANDBY MODE\n\n";
HAL_UART_Transmit(&huart2, (uint8_t *)str, strlen(str), HAL_MAX_DELAY);
for (int i = 0; i < 5; i++)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(750);
}
/* Enable wake-up pin */
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
/* Enable RTC wake-up (5s) */
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x2710, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
{
Error_Handler();
}
char *str2 = "STANDBY MODE is ON\n\n";
HAL_UART_Transmit(&huart2, (uint8_t *)str2, strlen(str2), HAL_MAX_DELAY);
/* Enter Standby mode */
HAL_PWR_EnterSTANDBYMode();
while (1)
{
// Should never reach here
}
}The program runs through the following steps:
- It checks whether the MCU woke up from Standby mode. If it did, the program clears the SBF flag, sends a UART message, blinks an LED, and disables the wake-up sources.
- It clears the old wake-up flags and sends a UART message that Standby mode is about to start.
- It enables the wake-up pin and configures the RTC wake-up timer for about 5 seconds.
- It enters Standby mode. The MCU shuts down almost completely, and on the wake-up the code starts again from
main().
Standby Mode Test Result
The log in the image shows the MCU entering Standby mode and waking up each time that a wake-up event occurs. During Standby, the measured current drops to about 2 µA on the Blue Pill.
Three points are worth remembering when you use Standby mode:
- Standby mode erases the SRAM and the state of the peripherals, which is different from Stop mode.
- The SBF flag must be checked after every reset to find out whether the MCU woke up from Standby mode.
- Data that must survive Standby mode has to be kept in the RTC backup registers or in flash, as shown in the STM32 flash programming tutorial.
Video Tutorial: STM32 Standby Mode
The video below walks through Standby mode. It shows how to clear the wake-up flags before entering Standby, how to configure the RTC wake-up timer and the wake-up pin on PA0, how to detect a Standby wake-up with the SBF flag in main(), and how to measure the current of about 2 µA.
Conclusion
STM32 microcontrollers offer three steps of power saving, and each step trades some convenience for a lower current. Sleep mode stops only the CPU, so it wakes up quickly and keeps every peripheral running, but it saves the least power. Stop mode switches off the clocks and keeps the SRAM and the registers, which lowers the current a lot, but the system clock has to be configured again after the wake-up. Standby mode reaches about 2 µA, but it resets the MCU on every wake-up, so the program starts again from main() and has to check the SBF flag to find out why.
A few habits apply to all three modes. The SysTick interrupt must be suspended before the MCU goes to sleep, and it must be resumed after the wake-up. The wake-up flags must be cleared before entering Standby mode. SLEEPONEXIT is useful in interrupt-driven designs, because it sends the MCU back to sleep after each ISR, and the ISR can disable it when the main loop has to run again.
The measured current also depends on the board. The onboard regulator and the LEDs of a development board such as the Blue Pill add several milliamps on top of the current of the MCU, so the bare MCU has to be powered directly for an accurate measurement. Peripherals that stay enabled and GPIO pins that float can raise the current as well, so it helps to switch off what the application does not need before it sleeps.
To go further, the STM32 internal RTC tutorial explains the RTC setup behind the wake-up timer and the alarms. Data that must survive Standby mode can be kept in the RTC backup registers or in the internal flash, as described in the STM32 flash programming tutorial. The UART tutorials cover the interrupt-driven reception that wakes the MCU from Sleep mode, the timer tutorials show other ways to run periodic tasks, and the STM32 FreeRTOS tutorials are the next step for larger applications that need both multitasking and low power.
Download Project Here
Download the CubeMX project files and HAL source code — all tested on real hardware.
If you find this useful, you can support us with a Donation as well.
Browse More STM32 Tutorials
Arun is an embedded systems engineer with 10+ years of experience in STM32, ESP32, and AVR microcontrollers. He created ControllersTech to share practical tutorials on embedded software, HAL drivers, RTOS, and hardware design — grounded in real industrial automation experience.
Recommended Tools
Essential dev tools
Categories
Browse by platform





Hi, I am using the STM32L073 microcontroller and implementing Standby mode with RTC wake-up, but it is exiting the mode immediately. how to solve this?
Make sure to clear all flags before entering standby
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
Also confirm if RTC is configured properly. You can try waking up with only the wakeup pin first, not relying on RTC at all.
In stm32f103c8t6 how can we exit from stand by mode using Auto wake up. can u please make a video on that?
using the RTC Alarm. It is already explained in the tutorial.
Hello , isue a dual-core st ( stm32h7) i need put all system in standby mode , but i only use m4core. My m7 core don´t have app yet.
I use the hal function ( HAL_PWR_EnterStandbyMode), my consumption does not go down, which means that the system does not go to full standby..
how can i do?
For sleep mode, you use an arbitrary GPIO pin to wake up MCU. Can I use any pin to wake it up from standby mode?
Hi! Using this example is possible to standby minutes or hours?? Because I tried to change the time of the standby and it only works from 1-30 seconds
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.
Thanks!
==> WakeUpCounter = ~5s/0.0005s = 20000 = 0x2710
????
==> WakeUpCounter = ~5s/0.0005s = 10000 = 0x2710
Hi. I boot with stm32L010C6Tx. I am in standby mode. While waiting in standby mode, it shows between 3.1 micro amps and 50 micro amps 50 microamps is too high, I can’t use it like this. . I turned off all peripherals. What else should I turn off? Why coul
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_LPUART1_UART_Init(void);
static void MX_I2C1_Init(void);
static void MX_ADC_Init(void);
static void MX_RTC_Init(void);
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
printf(“Wakeup from the STANDBY MODE\n\n”);
for (int i = 0; i < 20; i++) {
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(200);
}
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
}
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
printf(“About to enter the STANDBY MODE\n\n”);
for (int i = 0; i < 5; i++) {
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(750);
}
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x5A55, RTC_WAKEUPCLOCK_RTCCLK_DIV16)
!= HAL_OK) {
Error_Handler();
}
printf(“STANDBY MODE is ON\n\n”);
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();
Awesome explanation!
Thanks
I tried pay pal for donation but it failed. will try something else
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().
(The line “if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x2710, … ” was commented to eleminate effects of WakeUpTimer).
Why this problem appeared?
Thanks your time for your excellent explanation. I found some problem for the standby. Each time when turn on the MCU, it will print “wakeup from standby”, Actually it should not happen until enter standby then exit from standby mode. Also each time when wake up by Wakeup pin (rising PA0 ) it prints “wakeup from standby” twice. So far I haven’t found how to fix that.
that’s an unusual behavior. I would recommend that you debug your code. reset the mcu and step over each function. while doing so, check the contents of PWR_CSR register. The SBF bit is set when the mcu wakes up from standby. SO in case of reset, this shouldn’t be set.
stand_by modda 2mA e kadar düşüyor. vidyoda uA seviyelerinde görünüyor. kod aynı olduğu halde 2mA görüyorum. yardım edermisiniz
maybe urs is not entering the standby.. blink some LED before entering the sleep mode so that you can confirm this
Really nice work. You deserve for much more viewers :O