cancel
Showing results for 
Search instead for 
Did you mean: 

How to minimize the power consumption in low power mode: An example using NUCLEO-F401RE board

KDJEM.1
ST Employee

1. Introduction

Optimizing power consumption is one of the biggest challenges when designing an MCU based application.
In this article we selected the STM32F401 MCU that can be configured in four different modes: Run mode, Sleep mode, Stop mode and Standby mode. In our test, the NUCLEO-F401RE is configured in the Stop mode.
The purpose of this article is to share tips for power consumption optimization while describing steps to achieve it.
 

2. Prerequisites

2.1. Hardware

Mini-B USB cable used to power the Nucleo board from a host machine and to load the code into the STM32.
NUCLEO-F401RE.

1653.png

2.2. Software

STM32CubeIDE.


3. Steps

1. Open STM32CubeIDE.
2. Create a new project using the NUCLEO-F401RE board.
Select NUCLEO-F401RE boar using Board Selector:

1654.png


3. Enter a name for the project, for example "LowPowerConsumption".

1655.png


4. Initialize all peripherals with their default Mode?
Answer No to minimize power consumption as below:

1656.png


5. Clear pinouts as shown in the below figures or by using "Ctrl+p".

1657.png

1658.png


6. Set all free pins as analog (to optimize the power consumption).
In Project Manager tab, select code generator and click on Set all free pins as analog (to optimize the power consumption).

1659.png


Note that this feature allows the addition of these code lines in the Mx_GPIO_Init function in the main.c file:

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();

  /*Configure GPIO pins : PC13 PC14 PC15 PC0
                           PC1 PC2 PC3 PC4
                           PC5 PC6 PC7 PC8
                           PC9 PC10 PC11 PC12 */
  GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0
                          |GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4
                          |GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8
                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pins : PH0 PH1 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);

  /*Configure GPIO pins : PA0 PA1 PA2 PA3
                           PA4 PA5 PA6 PA7
                           PA8 PA9 PA10 PA11
                           PA12 PA13 PA14 PA15 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
                          |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
                          |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PB0 PB1 PB2 PB10
                           PB12 PB13 PB14 PB15
                           PB3 PB4 PB5 PB6
                           PB7 PB8 PB9 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10
                          |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
                          |GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
                          |GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : PD2 */
  GPIO_InitStruct.Pin = GPIO_PIN_2;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}


7. Generate Code.
Save the project and generate the code by clicking "Ctrl+s".

1660.png
1661.png


8. Insert the following lines between /* USER CODE BEGIN 2 */ and /* USER CODE END 2 */ to enter stop mode:

/* FLASH Deep Power Down Mode enabled */
HAL_PWREx_EnableFlashPowerDown();

/* Enter Stop Mode*/
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

9. Build the project and run the code as shown in the below figures.

1662.png
1664.png


10. To measure the consumption current, just remove jumper 6 and place a multimeter instead of it.
11. In this case the power consumption will be equal to 17µA. This value is similar to the value shared in the datasheet .

1665.png

Notes:

  1. When we don’t use the feature of set all free pins as analog (to optimize the power consumption) a supplementary consumption will be added, in our case, 133µA.
  2. The NUCLEO-F401RE and the stop mode is an example. This power consumption optimization method can be applied for different boards working on different modes.


4. Related links

Comments
Thomcheh
Associate

/* FLASH Deep Power Down Mode enabled */

 HAL_PWREx_EnableFlashPowerDown();

What should I put instead of this for an STM32L073RZ? 

KDJEM.1
ST Employee

Hello @Thomcheh​ ,

To minimize the consumption in Stop mode with STM32F4 MCU, FLASH can be powered off before entering the Stop mode using the HAL_PWREx_EnableFlashPowerDown() function.

To get the lowest consumption in Stop mode with STM32L0 MCU, the internal Flash memory also enters low power mode. When the Flash memory is in power-down mode, an additional startup delay is incurred when waking up from Stop mode.

In your case, try to check the consumption, when all pins are set as analog and without used "HAL_PWREx_EnableFlashPowerDown()" function.

Thank you.

Kaouthar

KKIM.6
Senior

What is the commnend to enter normal mode?

 

Kikwan

BarryWhit
Senior III

@KDJEM.1 , since this option applies only to unused pins, what's the rationale for not having it as the default? What is the context in which you wouldn't want to set your unused pins to a power-saving configuration?

KDJEM.1
ST Employee

Hello @BarryWhit ,

To optimize the power consumption it is recommended to set all free pins as analog.

For the STM32 Ultra Low Power MCUs  like as STM32L4 the reset state of the GPIO port mode is analog mode.

KDJEM1_1-1722588187906.png

--> since this option applies only to unused pins, what's the rationale for not having it as the default?

I reported this request internally.

The internal ticket 187991 (not accessible by community users) has been opened to confirm and fix the issue.

Thank you for your sharing and for your contribution in STCommunity 🙂.

Kaouthar 

BarryWhit
Senior III

@KDJEM.1 

 

Actually, I was legit just asking why this was the case and assumed that there actually is a good reason. I was not suggesting it should be default, since I obviously don't know what I don't know.

Version history
Last update:
‎2024-06-27 04:27 AM
Updated by:
Contributors