STM32CubeMX

Table Of Contents

- STM32CubeMX documentation
- CubeMX User Manual
  - 1 STM32Cube overview
  - 2 Getting started with STM32CubeMX
  - 3 Installing and running STM32CubeMX
  - 4 STM32CubeMX user interface
  - 5 STM32CubeMX tools
  - 6 STM32CubeMX C Code generation overview
  - 7 Code generation for dual-core MCUs (STM32H7 dual-core product lines only)
  - 8 Code generation with TrustZone enabled (STM32L5 series only)
  - 9 Device tree generation (STM32MPUs only)
  - 10 Support of additional software components using CMSIS-Pack standard
  - 11 Tutorial 1: From pinout to project C code generation using an MCU of the STM32F4 series
  - 12 Tutorial 2 - Example of FatFs on an SD card using STM32429I-EVAL evaluation board
  - 13 Tutorial 3 - Using the Power Consumption Calculator to optimize the embedded application consumption and more
  - 14 Tutorial 4 - Example of UART communications with an STM32L053xx Nucleo board
  - 15 Tutorial 5: Exporting current project configuration to a compatible MCU
  - 16 Tutorial 6 - Adding embedded software packs to user projects
  - 17 Tutorial 7 - Using the X-Cube-BLE1 software pack
  - 18 Creating LPBAM projects
  - Appendix A STM32CubeMX pin assignment rules
  - Appendix B STM32CubeMX C code generation design choices and limitations
  - Appendix C STM32 microcontrollers power consumption parameters
  - Appendix D STM32Cube embedded software packages
  - Revision history
- Release Notes
  - Release details
  - Release fixes
  - Known limitations
    - Miscellaneous
    - 2.1. When selecting microcontrollers in the STM32C0 series
    - 2.2. When selecting microcontrollers in the STM32G0 series
    - 2.3. When selecting microcontrollers in the STM32G4 series
    - 2.4. When selecting microcontrollers in the STM32H5 series
    - 2.5. When selecting microcontrollers in the STM32H7 series
    - 2.6. When selecting dual-core microcontrollers in the STM32H7 series
    - 2.7. When selecting microcontrollers in the STM32L5 series
    - 3.4. How to improve the wake-up from Stop sequences without relying on the global SystemClock_Config()
    - 3.3. List pinout-compatible microcontrollers
    - 3.2. DDR binaries for the STM32MP1 boards
    - 3.1. Command line authentication required
    - 2.21. Symbolic links on Ubuntu
    - 2.20. User manual
    - 2.19. DDR test suite
    - 2.18. STM32CubeIDE toolchain
    - 2.13. When selecting microcontrollers in the STM32WL series
    - 2.11. When selecting microcontrollers in the STM32WB series
    - 2.17. When using additional software packs
    - 2.16. When using the Example Selector
    - 2.15. When using the Memory Management Tool
    - 2.14. When selecting microprocessors in the STM32MP1 series
    - 2.11.1. When selecting microcontrollers in the STM32WB0 product lines
    - 2.12. When selecting microcontrollers in the STM32WBA series
    - 2.13.1. When selecting microcontrollers in the STM32WL33 product lines
    - 2.10. When selecting microcontrollers in the STM32U5 series
    - 2.9. When selecting microcontrollers in the STM32U3 series
    - 2.8. When selecting microcontrollers in the STM32N6 series
- Running STM32CubeMX in command-line mode
- FAQ
- Community

### On this page

- 13 Tutorial 3 - Using the Power Consumption Calculator to optimize the embedded application consumption and more
  - 13.1 Tutorial overview
  - 13.2 Application example description
  - 13.3 Using the Power Consumption Calculator
    - 13.3.1 Creating a power sequence
      - Figure 651. Power Consumption Calculation example
    - 13.3.2 Optimizing application power consumption
      - Step 1 (Run) - Findings
      - Step 5 (Run, ADC, DMA, RTC)
      - Step 6 (Sleep, DMA, ADC, RTC)
      - Step 7 (Run, DMA, RTC, USART)
      - Step 8 (Stop 0, USART) - Actions
      - Step 10 (RTC, USART) - Actions

# 13 Tutorial 3 - Using the Power Consumption Calculator to optimize the embedded application consumption and more

FATFS_UnLinkDriver(SDPath);

> /* USER CODE END 2 */

> /* Infinite loop */

/* USER CODE BEGIN WHILE */ while (1)

## 13 Tutorial 3 - Using the Power Consumption Calculator to optimize the embedded application consumption and more

### 13.1 Tutorial overview

> This tutorial focuses on STM32CubeMX Power Consumption Calculator (Power Consumption Calculator) feature and its benefits to evaluate the impacts of power-saving techniques on a given application sequence.

> The key considerations to reduce a given application power consumption are:

- Reducing the operating voltage

- Reducing the time spent in energy consuming modes

> It is up to the developer to select a configuration that gives the best compromise between low-power consumption and performance.

- Maximizing the time spent in non-active and low-power modes

- Using the optimal clock configuration

> The core should always operate at relatively good speed, since reducing the operating frequency can increase energy consumption if the microcontroller has to remain for a long time in an active operating mode to perform a given operation.

- Enabling only the peripherals relevant for the current application state and clock-gating the others

- When relevant, using the peripherals with low-power features (e.g. waking up the microcontroller with the I2C)

- Minimizing the number of state transitions

- Optimizing memory accesses during code execution

  - Prefer code execution from RAM to flash memory

  - When relevant, consider aligning CPU frequency with flash memory operating frequency for zero wait states.

> The following tutorial shows how the STM32CubeMX Power Consumption Calculator feature can help to tune an application to minimize its power consumption and extend the battery life.

Note: The Power Consumption Calculator does not account for I/O dynamic current consumption and external board components that can also affect current consumption. For this purpose, an “additional consumption” field is provided for the user to specify such consumption value.

### 13.2 Application example description

> The application is designed using the NUCLEO-L476RG board, based on an STM32L476RGTx device, and supplied by a 2.4 V battery.

> The main purpose of this application is to perform ADC measurements and transfer the conversion results over UART. It uses:

- Multiple low-power modes: Low-power run, Low-power sleep, Sleep, Stop and Standby • Multiple peripherals: USART, DMA, Timer, COMP, DAC and RTC

- The RTC is used to run a calendar and to wake up the CPU from Standby when a specified time has elapsed.

- The DMA transfers ADC measurements from ADC to memory

- The USART is used in conjunction with the DMA to send/receive data via the virtual COM port and to wake up the CPU from Stop mode.

The process to optimize such complex application is to start describing first a functional only sequence then to introduce, on a step by step basis, the low-power features provided by the STM32L476RG microcontroller.

### 13.3 Using the Power Consumption Calculator

#### 13.3.1 Creating a power sequence

> Follow the steps below to create the sequence (see Figure 651):

1. Launch STM32CubeMX.

2. Click new project and select the Nucleo-L476RG board from the Board tab.

3. Click the Power Consumption Calculator tab to select the Power Consumption Calculator view. A first sequence is then created as a reference.

4. Adapt it to minimize the overall current consumption. To do this:

   1. Select 2.4 V VDD power supply. This value can be adjusted on a step by step basis (see Figure 652).

   2. Select the Li-MnO2 (CR2032) battery. This step is optional. The battery type can be changed later on (see Figure 652).

##### Figure 651. Power Consumption Calculation example

5. Enable the Transition checker to ensure the sequence is valid (see Figure 652). This option allows verifying that the sequence respects the allowed transitions implemented within the STM32L476RG.

6. Click the Add button to add steps that match the sequence described in Figure 652.

   - By default the steps last 1 ms each, except for the wake-up transitions preset using the transition times specified in the product datasheet (see Figure 653).

   - Some peripherals for which consumption is unavailable or negligible are highlighted with * (see Figure 653).

7. Click the Save button to save the sequence as SequenceOne.

> The application consumption profile is generated. It shows that the overall sequence consumes an average of 2.01 mA for 9 ms, and that the battery lifetime is only four days (see Figure 654).

> Figure 654. sequence results before optimization

#### 13.3.2 Optimizing application power consumption

> Let us now take actions to optimize the overall consumption and the battery lifetime. These actions are performed on steps 1, 4, 5, 6, 7, 8, and 10.

> The next figures show on the left the original step, and on the right the step updated with optimization actions.

##### Step 1 (Run) - Findings

> All peripherals are enabled although the application requires only the RTC.

- Actions

  - Lower the operating frequency

  - Enable only the RTC peripheral

  - To reduce the average current consumption, reduce the time spent in this mode

- Result

> The current is reduced from 9.05 to 2.16 mA (see Figure 655).

> Figure 655. Step 1 optimization

Step 4 (Run, RTC) - Action

> Reduce the time spent in this mode to 0.1 ms

##### Step 5 (Run, ADC, DMA, RTC)

- Actions

  - Change to Low-power run mode

  - Lower the operating frequency

- Results

> The current consumption is reduced from 6.17 mA to 271 µA (see Figure 656).

> Figure 656. Step 5 optimization

##### Step 6 (Sleep, DMA, ADC, RTC)

- Actions

  - Switch to Lower-power sleep mode (BAM mode)

  - Reduce the operating frequency to 2 MHz

- Results

> The current consumption is reduced from 703 µA to 93 µA (see Figure 657).

> Figure 657. Step 6 optimization

##### Step 7 (Run, DMA, RTC, USART)

- Actions

  - Switch to Low-power run mode

  - Use the power efficient LPUART peripheral

  - Reduce the operating frequency to 1 MHz using the interpolation feature

- Results

> The current consumption is reduced from 1.92 mA to 42 µA (see Figure 658).

> Figure 658. Step 7 optimization

##### Step 8 (Stop 0, USART) - Actions

- Switch to Stop1 low-power mode

- Use the power-efficient LPUART peripheral

- Results

  > The current consumption is reduced (see Figure 659).

  > Figure 659. Step 8 optimization

##### Step 10 (RTC, USART) - Actions

- Use the power-efficient LPUART peripheral

- Reduce the operating frequency to 1 MHz

- Results

  > The current consumption is reduced from 1.89 mA to 234 µA (see Figure 660).

  > The example given in Figure 661 shows an average current consumption reduction of 155 µA.