on
2022-11-15
04:20 AM
- edited on
2024-06-27
04:27 AM
by
Laurids_PETERSE
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.
Mini-B USB cable used to power the Nucleo board from a host machine and to load the code into the STM32.
NUCLEO-F401RE.
STM32CubeIDE.
1. Open STM32CubeIDE.
2. Create a new project using the NUCLEO-F401RE board.
Select NUCLEO-F401RE boar using Board Selector:
3. Enter a name for the project, for example "LowPowerConsumption".
4. Initialize all peripherals with their default Mode?
Answer No to minimize power consumption as below:
5. Clear pinouts as shown in the below figures or by using "Ctrl+p".
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).
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".
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.
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 .
Notes:
/* FLASH Deep Power Down Mode enabled */
HAL_PWREx_EnableFlashPowerDown();
What should I put instead of this for an STM32L073RZ?
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
What is the commnend to enter normal mode?
Kikwan
@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?
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.
--> 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
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.