Showing results for 
Search instead for 
Did you mean: 

Partially configure GPIO using HAL

Bumsik Kim
Posted on December 19, 2016 at 01:18


I am trying to change pullup/down in GPIO. However, it looks like HAL_GPIO_Init() doesn't allow partial configuration of GPIO pin.

Is there any way to configure pullup/down only using HAL? Should I change registers directly?

#hal-driver #stm32 #hal #gpio
Posted on December 20, 2016 at 11:33

The pullup/pulldown can be configured via the 'Pull' field into the GPIO_InitTypeDef structure. It can be set to:





Bumsik Kim
Posted on December 20, 2016 at 12:02


Thank you for reply.

But using HAL_GPIO_Init() and GPIO_InitTypeDef will force you configure other settings such asGPIO Mode.The following code will trigger HAL assert or unexpectedly change other settings of the GPIO:

GPIO_InitTypeDefgpio_settings = {

.Pin = GPIO_PIN_0,



HAL_GPIO_Init(GPIOA, &gpio_settings);

In the case above I need to fully declarespeed and mode of the GPIO otherwise it will throwerror.

I would like to know other ways to configurepulldown/pullup only

Senior II
Posted on December 20, 2016 at 15:14

Hi ,

In some STM32Cube package (like F0, F3, L4, L0 and other families will comes) , you can user

The Low Layer (LL) drivers which are designed to offer a fast light-weight expert-oriented layer which is closer to the hardware than the HAL.

The Low Layer drivers provide hardware services based on the available features of the STM32 peripherals. These services reflect exactly the hardware capabilities and provide one-shot operations that must be called following the programming model described in the microcontroller line reference manual.

In your case toconfigure gpio pull-up or pull-down for a dedicated pin on a dedicated port, you can youse the following:

void LL_GPIO_SetPinPull (GPIO_TypeDef * GPIOx, uint32_t Pin, uint32_t Pull);�?

For GPIO or other peripheral low level drivers' macros/functions , you should check the relevant user manual like the

foe STM32L4xx

-Walid F-