HAL GPIO Overview

Introducing GPIO

group GPIO_Introduction

The GPIO hardware abstraction layer (HAL) provides a set of APIs to interface with the general-purpose Input/Output (GPIO) peripheral on STM32 microcontrollers.

This layer simplifies the configuration, initialization, and management of GPIO pins, allowing multiple pins to be managed simultaneously when they belong to the same port. The GPIO includes the following features:

  • Initialize one or more GPIO pins.

  • Read the value of a pin.

  • Write values to one or more pins.

  • Toggle the state of pins.

  • Lock pins configuration.

  • Lock a set of pins.

This abstraction layer ensures portability and ease of use across different STM32 series microcontrollers.

Module and files

The following diagram illustrates the GPIO module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the GPIO module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.

@startuml
<style>
componentDiagram {
   arrow {
      FontSize 8
   }
}
</style>

title GPIO Software Component Diagram

package "HAL" {
    [HAL_SERVICES]
    [HAL_GPIO]
}

package "Low Layer" {
    [LL_GPIO]
    [CMSIS]
}

package "HW" {
    [STM32_HW]
}

[Appli] --> [HAL_GPIO] : HAL GPIO API
[Appli] <-- [HAL_GPIO] : GPIO pins states
[HAL_GPIO] --> [LL_GPIO] : LL GPIO API

[LL_GPIO] --> [CMSIS]:GPIO register definition
[STM32_HW] <-u--> [CMSIS] : GPIO registers R/W
@enduml

Configuration table

The following table lists the configuration defines for the HAL GPIO module, specifying their locations, default values, and descriptions:

group GPIO_Configuration_Table

Configuration inside the GPIO driver

Config defines

Description

Default value

Note

USE_HAL_GPIO_MODULE

hal_conf.h

1

When set, HAL GPIO module is enabled

USE_HAL_CHECK_PARAM

hal_conf.h

0

When set, parameters are checked at runtime

USE_ASSERT_DBG_PARAM

PreProcessor env

NA

When defined, enable the params assert

USE_HAL_GPIO_CLK_ENABLE_MODEL

hal_conf.h

HAL_CLK_ENABLE_NO

Enable GPIO port clock in HAL_GPIO_Init