Skip to main content
SZano
Associate III
October 22, 2021
Solved

HAL bug in GPIO deinit (STM32L0)

in software package STM32L0 1.12.1

in file stm32l0xx_hal_gpio.c

in function void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)

The pin is deinited by setting it as input floating:

/* Configure IO Direction in Input Floting Mode */
GPIOx->MODER |= (GPIO_MODER_MODE0 << (position * 2U));

But on STM32L0x3 all the pins are configured as ANALOG after a reset.

See also the reference manual RM0367 (Section "9.4.1 GPIO port mode register (GPIOx_MODER)").

The code above should be replaced with

/* Configure IO Direction as Analog Mode */
GPIOx->MODER |= (GPIO_MODER_MODE3 << (position * 2U));

I'm assuming that all the devices in the L0 family have pins defaulting to ANALOG; otherwise, the code above should be tailored to the various subfamilies.

This topic has been closed for replies.
Piranha
PiranhaBest answer
Principal III
October 23, 2021

This one is not a bug. Floating mode is the analog mode. The zero in "MODE0" is a pin number, not an I/O mode. The GPIO_MODER_MODE0 is a bit field mask with a value 3. Look at the code:

https://github.com/STMicroelectronics/STM32CubeL0/blob/00db5bdf2702687f645b65cd800ddc19c6e55878/Drivers/CMSIS/Device/ST/STM32L0xx/Include/stm32l073xx.h#L2560

P.S. Semantically using a bit field mask doesn't make sense. Instead they should use the reset value, which is just a simple number 3, or define something like GPIO_MODER_MODE_ANALOG or GPIO_MODER_MODE_RESET.

3 replies

Piranha
PiranhaBest answer
Principal III
October 23, 2021

This one is not a bug. Floating mode is the analog mode. The zero in "MODE0" is a pin number, not an I/O mode. The GPIO_MODER_MODE0 is a bit field mask with a value 3. Look at the code:

https://github.com/STMicroelectronics/STM32CubeL0/blob/00db5bdf2702687f645b65cd800ddc19c6e55878/Drivers/CMSIS/Device/ST/STM32L0xx/Include/stm32l073xx.h#L2560

P.S. Semantically using a bit field mask doesn't make sense. Instead they should use the reset value, which is just a simple number 3, or define something like GPIO_MODER_MODE_ANALOG or GPIO_MODER_MODE_RESET.

SZano
SZanoAuthor
Associate III
October 25, 2021

You're right, I mistook the meaning of MODE0.

Also the comment about "input floating" - which to me means "input mode without pull-up or pull-down", not "analog" - contributed to the confusion.

Indeed, other families' files (h7, f4, l4) have an appropriate comment, either "Input Floating" (0x0) or "Analog" (0x3)

Thanks

Amel NASRI
ST Technical Moderator
October 25, 2021

Hi @Community member​ & @Piranha​ ,

I tracked your proposals in Internal ticket number: 116446 (This is an internal tracking number and is not accessible or usable by customers).

Thanks for sharing your thoughts.

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.