HAL GPIO Functions

HAL GPIO Functions

group GPIO_Exported_Functions

Functions

GPIO_TypeDef * HAL_GPIO_GetLLInstance ( hal_gpio_t gpiox )

Get the selected hardware GPIO instance.

Parameters :

gpiox – HAL_GPIOx: selected GPIO port based on hal_gpio_t.

Return values :

The – selected hardware GPIO instance.

Initialization/de-initialization functions

group GPIO_Exported_Functions_Group1

This subsection provides a set of functions allowing to initialize/de-initialize and configure GPIO ports.

Initialize GPIO pins of a dedicated GPIO port using HAL_GPIO_Init():

  • Provide the GPIO port as a parameter.

  • Specify the GPIO pins to be configured, as a second parameter.

  • Provide the configuration structure containing the configuration to be applied as the third parameter.

De-initialize GPIO pins of a dedicated GPIO port using HAL_GPIO_DeInit():

  • Provide the GPIO port as a first parameter.

  • Specify the GPIO pins to be de-initialized as a second parameter.

Functions

hal_status_t HAL_GPIO_Init ( hal_gpio_t gpiox , uint32_t pins , const hal_gpio_config_t * p_config )

Initialize a pin or a set of pins for a GPIO port according to the specified parameters in the p_config.

Parameters :
  • gpiox – HAL_GPIOx: selected GPIO port based on hal_gpio_t.

  • pins – specifies the port pins to be written. This parameter can be a combination of HAL_GPIO_PIN_x where x can be (0..15).

  • p_config – pointer to a hal_gpio_config_t structure that contains the configuration information for the specified GPIO pins.

Return values :
  • HAL_INVALID_PARAM – p_config is NULL.

  • HAL_OK – GPIO pins has been correctly configured.

void HAL_GPIO_DeInit ( hal_gpio_t gpiox , uint32_t pins )

Reset the configuration of a pin or a set of pins for a GPIO port to the default one.

Parameters :
  • gpiox – HAL_GPIOx: selected GPIO port based on hal_gpio_t.

  • pins – specifies the port pins to be written. This parameter can be a combination of HAL_GPIO_PIN_x where x can be (0..15).

IO operation functions

group GPIO_Exported_Functions_Group2

This subsection contains the APIs managing possible I/O operations on the GPIO pins:

Read the input level of a dedicated input port pin using HAL_GPIO_ReadPin():

  • Provide the GPIO port as a first parameter.

  • Provide the GPIO pin to read as a second parameter.

Set or clear a set of pins of a GPIO port using HAL_GPIO_WritePin():

  • Provide the GPIO port as a first parameter.

  • Specify the pins to be updated as a second parameter.

  • Enter the pin state to be written to the specified pin as the third parameter.

Set and clear several pins of the same GPIO port in a single cycle using HAL_GPIO_WriteMultipleStatePin():

  • Provide the GPIO port as the first parameter.

  • Specify the set of pins to be reset as a second parameter.

  • Specify the set of pins to be set as a third parameter.

Toggle a set of pins of a dedicated GPIO port using HAL_GPIO_TogglePin():

  • Provide the GPIO port as a first parameter.

  • Specify the set of pins to be toggled as a second parameter.

Lock the configuration of a set of pins of a dedicated GPIO port using HAL_GPIO_LockPin():

  • Provide the GPIO port as a first parameter.

  • Specify the set of pins of which to lock the configuration as a second parameter.

To get the selected GPIO hardware instance, use HAL_GPIO_GetLLInstance() function.

Functions

hal_gpio_pin_state_t HAL_GPIO_ReadPin ( hal_gpio_t gpiox , uint32_t pin )

Read the specific input pin for a GPIO port.

Parameters :
  • gpiox – HAL_GPIOx: selected GPIO port based on hal_gpio_t.

  • pin – specifies the port pin to read. This parameter can be one of HAL_GPIO_PIN_x where x can be (0..15).

Return values :
  • HAL_GPIO_PIN_RESET – when the input port pin is low.

  • HAL_GPIO_PIN_SET – when the input port pin is high.

void HAL_GPIO_WritePin ( hal_gpio_t gpiox , uint32_t pins , hal_gpio_pin_state_t pin_state )

Set or clear a pin or a set of pins of a GPIO port.

Note

This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify accesses. In this way, there is no risk of an IRQ occurring between the read and the modify access.

Parameters :
  • gpiox – HAL_GPIOx: selected GPIO port based on hal_gpio_t.

  • pins – specifies the port pins to be written.

  • pin_state – specifies the value to be written to the selected bit. This parameter can be one of the hal_gpio_pin_state_t enum values:

    • HAL_GPIO_PIN_RESET: to clear the port pin.

    • HAL_GPIO_PIN_SET: to set the port pin.

void HAL_GPIO_WriteMultipleStatePin ( hal_gpio_t gpiox , uint32_t pins_reset , uint32_t pins_set )

Set and clear a pin or a set of pins of a GPIO port in same cycle.

Note

This function uses GPIOx_BSRR register to set the level of several pins and reset level of several other pins in the same cycle.

Note

Ensure at least one of the two parameters used to set or reset is different from zero.

Warning

Do not set any common bit in pins_reset and pins_set combinations, otherwise the assert is triggered.

Parameters :
  • gpiox – HAL_GPIOx: selected GPIO port based on hal_gpio_t.

  • pins_reset – specifies the port bits to be reset. This parameter can be any combination of HAL_GPIO_PIN_x where x can be (0..15) or zero.

  • pins_set – specifies the port bits to be set. This parameter can be any combination of HAL_GPIO_PIN_x where x can be (0..15) or zero.

void HAL_GPIO_TogglePin ( hal_gpio_t gpiox , uint32_t pins )

Toggle a specific pin of a GPIO port.

Parameters :
  • gpiox – HAL_GPIOx: selected GPIO port based on hal_gpio_t.

  • pins – specifies the port pins to be toggled. This parameter can be a combination of HAL_GPIO_PIN_x where x can be (0..15).

hal_status_t HAL_GPIO_LockPin ( hal_gpio_t gpiox , uint32_t pins )

Lock the configuration of a pin or a set of pins of a GPIO port.

Note

The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.

Note

The configuration of the locked GPIO pins can no longer be modified until the next reset.

Parameters :
  • gpiox – HAL_GPIOx: selected GPIO port based on hal_gpio_t.

  • pins – specifies the port pins to be locked. This parameter can be any combination of HAL_GPIO_PIN_x where x can be (0..15).

Return values :
  • HAL_OK – pins locked successfully.

  • HAL_ERROR – error occurred during pins lock operation.

GPIO_TypeDef * HAL_GPIO_GetLLInstance ( hal_gpio_t gpiox )

Get the selected hardware GPIO instance.

Parameters :

gpiox – HAL_GPIOx: selected GPIO port based on hal_gpio_t.

Return values :

The – selected hardware GPIO instance.