Skip to main content
Andrew Neil
Super User
July 16, 2026
Question

CubeF0 Low-Power Examples: Why set GPIO high speed mode?

  • July 16, 2026
  • 4 replies
  • 79 views

In the STM32CubeF0 pack, PWR/PWR_CurrentConsumption example for Nucleo-F030R8:

void SleepMode_Measure(void)
{
GPIO_InitTypeDef GPIO_InitStruct;

/* Configure all GPIO as analog to reduce current consumption on non used IOs */
/* Enable GPIOs clock */
/* Warning : Reconfiguring all GPIO will close the connection with the debugger */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();

GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; // <<< Here!
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = GPIO_PIN_All;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
void StopMode_Measure(void)
{
GPIO_InitTypeDef GPIO_InitStruct;

/* Configure all GPIO as analog to reduce current consumption on non used IOs */
/* Warning : Reconfiguring all GPIO will close the connection with the debugger */
/* Enable GPIOs clock */

__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();


GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; // <<< Here!
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = GPIO_PIN_All;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);

https://github.com/STMicroelectronics/STM32CubeF0/blob/master/Projects/STM32F030R8-Nucleo/Examples/PWR/PWR_CurrentConsumption/Src/stm32f0xx_lp_modes.c#L144

 

Why set the speed mode to High ?

The default is Low.

 

I guess it doesn’t actually make any difference, as the speed is irrelevant in Analogue mode?

So does it actually need to be explicitly set at all ?

4 replies

waclawek.jan
Super User
July 16, 2026

Let me guess: the code was copypasted from somewhere where it did matter?

The digital output setting is irrelevant when the port is set to Analog, but the struct has to be filled in completely.

JW

Andrew Neil
Super User
July 16, 2026

The digital output setting is irrelevant when the port is set to Analog

I thought so.

And that should also apply to the pull-up/down:

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
waclawek.jan
Super User
July 16, 2026

Yes.

Basically, you could rewrite the above code as

RCC->AHBENR |= (0
| RCC_AHBENR_IOPAEN
| RCC_AHBENR_IOPBEN
| RCC_AHBENR_IOPCEN
| RCC_AHBENR_IOPDEN
| RCC_AHBENR_IOPEEN
| RCC_AHBENR_IOPFEN
);
GPIOA->MODER = 0xFFFFFFFF; // all pins Analog -> 0b11
GPIOB->MODER = 0xFFFFFFFF;
GPIOC->MODER = 0xFFFFFFFF;
GPIOD->MODER = 0xFFFFFFFF;
GPIOE->MODER = 0xFFFFFFFF;
GPIOF->MODER = 0xFFFFFFFF;

(Is there any difference between those two snippets you gave above?)

JW

Andrew Neil
Super User
July 16, 2026

Is there any difference between those two snippets you gave above?

Not in the bits I showed - the difference in the full code is whether they subsequently go to SLEEP or STOP mode.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.