This article explains Low-power modes, and provides code examples.
1. Introduction to LPBAM
The LPBAM (low-power batch autonomous mode) is an operating mode that allows peripherals to be functional and autonomous independently from the device power modes, down to Stop 2 mode, without any software running. The LPBAM subsystem can chain different operations thanks to DMA linked-list transfers. The DMA operations can be related to:
- Peripheral data transfer
- Peripheral reconfiguration
1.1. Smart Run Domain (SRD)
1.2. Peripherals supporting LPBAM
1.3. LPBAM main use cases
2. LPBAM Example Overview
2.1. Block Diagram
2.2. Objectives
2.3. STM32CubeMX LPBAM Configuration
2.4. Code configuration
2.5. Power Consumption measurement
3. References
4. Sleep mode
4.1. Definition
In sleep mode, the CPU clock is OFF and there is no effect on other clocks or analog clock sources. All peripherals continue to operate and can wake up the CPU when an interrupt/event occurs.
4.2. Configure the sleep mode
4.2.1. STM32CubeMX configuration
The system clock is set to 80 MHz.
File:PWR clock configuration sleep.png
- An EXTI line is connected to the user button through PC13
- LED2 connected to PA5 pin
4.2.2. Code configuration
- Open the project from EXTI overview
- Open main.c
- Add a function to enter Sleep mode.
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(1000);
HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON,PWR_SLEEPENTRY_WFI);
HAL_ResumeTick();
}
/* USER CODE END 3 */
- Set all GPIO to analog state to reduce power consumption as shown in the following picture
4.3. Compile and flash
4.4. Measure consumption
- Stop any debug session and do a full-power cycle
- Use an amperemeter on the IDD connector (JP6 on NUCLEO-L476RG - for other boards check their user manual)
- Check the current consumption while in Sleep mode
- Press the configured user button on the Nucleo board to see the consumption increase as the MCU is waken up from sleep mode.
- Referring to the datasheet, in Sleep mode at 25°C, VDD = 3V and fHCLK= 80MHz , the current consumption should be 2.96mA
- Using the the STM32 Power shield and STM32CubeMonPwr we measured :
5. Low power run mode
5.1. Definition
This mode is achieved when the system clock frequency is reduced below 2 MHz. The code is executed from the SRAM or the Flash memory. The regulator is in low-power mode to minimize the regulator's operating current.
5.2. Configure the low power run mode
5.2.1. STM32CubeMX configuration
The system clock is limited to 2 MHz maximum. The MSI internal RC oscillator can be selected as it supports several frequency ranges
5.2.2. Code configuration
- Open the project from EXTI overview
- Open main.c
- Add a function to enter low power run mode.
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(2000);
HAL_SuspendTick();
HAL_PWREx_EnableLowPowerRunMode();
HAL_ResumeTick();
}
/* USER CODE END 3 */
5.3. Compile and flash
5.4. Measure the current consumption
- Referring to the datasheet, in Low power Run mode at 25°C, Fhclk = 100kHz and VDD = 3V, the current consumption should be 42μA.
- Using the STM32Cube Monitor-Power, we measured :
6. Low Power Sleep mode
6.1. Definition
This mode is entered from the low-power run mode. Only the CPU clock is stopped. When wakeup is triggered by an event or an interrupt, the system reverts to the low power run mode.
6.2. Configure the low power sleep mode
- Open the project from EXTI overview
- Open main.c
- Add a function to enter Low power Sleep mode.
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(2000);
HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
HAL_ResumeTick();
}
/* USER CODE END 3 */
6.3. Compile and flash
6.4. Measure the current consumption
- Referring to the datasheet, in Low power Sleep mode at 25°C and VDD = 3V, the current consumption should be 33mA
File:PWR datasheet lpsleep.png
- Using the STM32Cube Monitor-Power, we measured :
7. Stop0, Stop1 and Stop2 modes
7.1. Definition
Stop mode achieves the lowest power consumption while retaining the content of SRAM and registers. All clocks in the VCORE domain are stopped, the PLL, the MSI RC, the HSI16 RC and the HSE crystal oscillators are disabled. The LSE or LSI can be kept running.
7.2. Stop0 mode
Open the project from EXTI overview
- Open main.c
- Add a function to suspend the Systick (the SysTick is typically set to raise an interrupt every 1 ms).
- Add a function to enter Stop0 mode
- Add a function to resume the Systick on wakeup.
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(1000);
HAL_SuspendTick();
HAL_PWREx_EnterSTOP0Mode(PWR_SLEEPENTRY_WFI);
HAL_ResumeTick();
}
/* USER CODE END 3 */
7.2.1. Compile and flash
7.2.2. Measure the current consumption
- Referring to the datasheet, in Stop0 mode at 25°C and VDD = 3.6V, the current consumption should be 113μA
- Using the STM32Cube Monitor-Power, we measured :
7.3. Stop1 mode
Stop 1 offers the largest number of active peripherals and wakeup sources, a smaller wakeup time but a higher consumption than Stop 2.
- Change only this line in the code :
HAL_PWREx_EnterSTOP1Mode(PWR_SLEEPENTRY_WFI);
7.3.1. Compile and flash
7.3.2. Measure the current consumption
- Referring to the datasheet, in Stop1 mode at 25°C and VDD = 3.6V, the current consumption should be 6.70μA
- Using the STM32Cube Monitor-Power, we measured :
7.4. Stop2 mode
In Stop 2 mode, most of the VCORE domain is put in a lower leakage mode.
- Change only this line in the code :
HAL_PWREx_EnterSTOP2Mode(PWR_SLEEPENTRY_WFI);
7.4.1. Compile and flash
7.4.2. Measure the current consumption
- Referring to the datasheet, in Stop2 mode at 25°C and VDD = 3.6V, the current consumption should be 1.26μA
- Using the STM32Cube Monitor-Power, we measured :
To exit from Stop2 mode, RTC (Real-Time Clock) peripheral can be used to periodically wake it up, please check this article about How to configure the RTC to wake up the STM32 periodically from Low Power modes
8. Standby mode
8.1. Definition
The Standby mode is used to achieve the lowest power consumption with brown-out reset. The internal regulator is switched off so that the VCORE domain is powered off. The PLL, the MSI RC, the HSI16 RC and the HSE crystal oscillators are also switched off.
RTC can remain active (Standby mode with RTC, Standby mode without RTC).
Brown-out reset (BOR) always remains active in Standby mode.
The state of each I/O during standby mode can be selected by software: I/O with internal pull-up, internal pull-down or floating.
The system can be woken up from standby mode using a SYS_WKUP pin, an RTC event (alarm or timer), IWDG, or an external reset in NRST pin.
After waking up from Standby mode, program execution restarts in the same way as after a Reset (boot pin sampling, option bytes loading, reset vector is fetched, etc.).
File:PWR standby mode.png
8.2. HAL library workflow summary
8.3. Configure the Standby Mode
- Open the project from EXTI overview
- Open main.c
/* Initialize all configured peripherals */
/* USER CODE BEGIN 2 */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
/* USER CODE END 2 */
- Add a function to enter Standby mode.
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(2000);
HAL_PWR_EnterSTANDBYMode();
}
/* USER CODE END 3 */
8.4. Compile and flash
8.5. Measure the current consumption
- Referring to the datasheet, in Standby mode at 25°C and VDD = 3V, the current consumption should be 150nA
- Using the STM32Cube Monitor-Power, we measured :
9. Shutdown mode
9.1. Definition
The Shutdown mode allows to achieve the lowest power consumption. The internal regulator is switched off so that the VCORE domain is powered off. The PLL, the HSI16, the MSI, the LSI and the HSE oscillators are also switched off.
The system can be woken up from shutdown mode using a SYS_WKUP pin, an RTC event (alarm or timer), or external reset in NRST pin.
After waking up from Shutdown mode, program execution restarts in the same way as after a Reset (boot pin sampling, option bytes loading, reset vector is fetched, etc.).
9.2. Configure the Shutdown Mode
- Open the project from EXTI overview
- Open main.c
- Add a function to enter Shutdown mode.
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(2000);
HAL_PWREx_EnterSHUTDOWNMode();
}
/* USER CODE END 3 */
9.3. Compile and flash
9.4. Measure the current consumption
- Referring to the datasheet, in Shutdown mode at 25°C and VDD = 3V, the current consumption should be 64.1nA
- Using the STM32Cube Monitor-Power, we measured :
10. References
- STM32CubeMonPwr
- STM32 Power Shield
- Power shield user manual
- STM32L476 Datasheet
- RM0351 Reference Manuel
[[category:Getting_started_with_STM32_system_peripherals | 25]]