13. General-purpose I/Os (GPIO)

13.1 Introduction

Each general-purpose I/O port has four 32-bit configuration registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR and GPIOx_PUPDR), two 32-bit data registers (GPIOx_IDR and GPIOx_ODR) and a 32-bit set/reset register (GPIOx_BSRR). In addition all GPIOs have a 32-bit locking register (GPIOx_LCKR) and two 32-bit alternate function selection registers (GPIOx_AFRH and GPIOx_AFRL).

13.2 GPIO main features

13.3 GPIO functional description

Subject to the specific hardware characteristics of each I/O port listed in the datasheet, each port bit of the general-purpose I/O (GPIO) ports can be individually configured by software in several modes:

Each I/O port bit is freely programmable, however the I/O port registers have to be accessed as 32-bit words, half-words or bytes. The purpose of the GPIOx_BSRR register is to allow atomic read/modify accesses to any of the GPIOx_ODR registers. In this way, there is no risk of an IRQ occurring between the read and the modify access.

Figure 116 and Figure 117 show the basic structures of a standard and a 5-Volt tolerant I/O port bit, respectively. Table 82 gives the possible port bit configurations.

Figure 116. Basic structure of an I/O port bit

Schematic diagram of the basic structure of an I/O port bit showing the input driver with Schmitt trigger, output driver with P-MOS and N-MOS transistors, pull-up and pull-down resistors, protection diodes, input/output data registers, bit set/reset registers, and connections to analog and alternate functions.

ai15938

Schematic diagram of the basic structure of an I/O port bit showing the input driver with Schmitt trigger, output driver with P-MOS and N-MOS transistors, pull-up and pull-down resistors, protection diodes, input/output data registers, bit set/reset registers, and connections to analog and alternate functions.

Figure 117. Basic structure of a 5-Volt tolerant I/O port bit

Schematic diagram of the basic structure of a 5-Volt tolerant I/O port bit showing TTL Schmitt trigger input driver, output driver with P-MOS/N-MOS push-pull/open-drain, pull-up/pull-down resistors, protection diodes connected to VDD_FT(1), registers, and alternate function/analog connections.

ai15939b

Schematic diagram of the basic structure of a 5-Volt tolerant I/O port bit showing TTL Schmitt trigger input driver, output driver with P-MOS/N-MOS push-pull/open-drain, pull-up/pull-down resistors, protection diodes connected to VDD_FT(1), registers, and alternate function/analog connections.

1. \(V_{\text{DD\_FT}}\) is a potential specific to five-volt tolerant I/Os and different from \(V_{\text{DD}}\).

Table 82. Port bit configuration table(1)
MODE(i)
[1:0]
OTYPER(i)OSPEED(i)
[1:0]
PUPD(i)
[1:0]
I/O configuration
010SPEED
[1:0]
00GP outputPP
001GP outputPP + PU
010GP outputPP + PD
011Reserved
100GP outputOD
101GP outputOD + PU
110GP outputOD + PD
111Reserved (GP output OD)
100SPEED
[1:0]
00AFPP
001AFPP + PU
010AFPP + PD
011Reserved
100AFOD
101AFOD + PU
110AFOD + PD
111Reserved
00xxx00InputFloating
xxx01InputPU
xxx10InputPD
xxx11Reserved (input floating)
11xxx00Input/outputAnalog
xxx01Reserved
xxx10Input/outputAnalog, PD
xxx11Reserved

1. GP = general-purpose, PP = push-pull, PU = pull-up, PD = pull-down, OD = open-drain, AF = alternate function.

13.3.1 General-purpose I/O (GPIO)

During and just after reset, the alternate functions are not active and most of the I/O ports are configured in input floating mode.

When the pin is configured as output, the value written to the output data register (GPIOx_ODR) is output on the I/O pin. It is possible to use the output driver in push-pull mode or open-drain mode (only the low level is driven, high level is HI-Z).

The input data register (GPIOx_IDR) captures the data present on the I/O pin at every AHB clock cycle.

All GPIO pins have weak internal pull-up and pull-down resistors, which can be activated or not depending on the value in the GPIOx_PUPDR register.

13.3.2 I/O pin alternate function multiplexer and mapping

The device I/O pins are connected to on-board peripherals/modules through a multiplexer that allows only one peripheral alternate function (AF) connected to an I/O pin at a time. In this way, there can be no conflict between peripherals available on the same I/O pin.

Each I/O pin has a multiplexer with up to sixteen alternate function inputs (AF0 to AF15) that can be configured through the GPIOx_AFRL (for pin 0 to 7) and GPIOx_AFRH (for pin 8 to 15) registers:

In addition to this flexible I/O multiplexing architecture, each peripheral has alternate functions mapped onto different I/O pins to optimize the number of peripherals available in smaller packages.

To use an I/O in a given configuration, the user has to proceed as follows:

Refer to the “Alternate function mapping” table in the device datasheet for the detailed mapping of the alternate function I/O pins.

13.3.3 I/O port control registers

Each of the GPIO ports has four 32-bit memory-mapped control registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR) to configure up to 16 I/Os. The GPIOx_MODER register is used to select the I/O mode (input, output, AF, analog). The GPIOx_OTYPER and GPIOx_OSPEEDR registers are used to select the output type (push-pull or open-drain) and speed. The GPIOx_PUPDR register is used to select the pull-up/pull-down whatever the I/O direction.

13.3.4 I/O port data registers

Each GPIO has two 16-bit memory-mapped data registers: input and output data registers (GPIOx_IDR and GPIOx_ODR). GPIOx_ODR stores the data to be output, it is read/write accessible. The data input through the I/O are stored into the input data register (GPIOx_IDR), a read-only register.

See Section 13.4.5: GPIO port input data register (GPIOx_IDR) (x = A to K, Z) and Section 13.4.6: GPIO port output data register (GPIOx_ODR) (x = A to K, Z) for the register descriptions.

13.3.5 I/O data bitwise handling

The bit set reset register (GPIOx_BSRR) is a 32-bit register which allows the application to set and reset each individual bit in the output data register (GPIOx_ODR). The bit set reset register has twice the size of GPIOx_ODR.

To each bit in GPIOx_ODR, correspond two control bits in GPIOx_BSRR: BS(i) and BR(i). When written to 1, bit BS(i) sets the corresponding ODR(i) bit. When written to 1, bit BR(i) resets the ODR(i) corresponding bit.

Writing any bit to 0 in GPIOx_BSRR does not have any effect on the corresponding bit in GPIOx_ODR. If there is an attempt to both set and reset a bit in GPIOx_BSRR, the set action takes priority.

Using the GPIOx_BSRR register to change the values of individual bits in GPIOx_ODR is a “one-shot” effect that does not lock the GPIOx_ODR bits. The GPIOx_ODR bits can always be accessed directly. The GPIOx_BSRR register provides a way of performing atomic bitwise handling.

There is no need for the software to disable interrupts when programming the GPIOx_ODR at bit level: it is possible to modify one or more bits in a single atomic AHB write access.

13.3.6 GPIO locking mechanism

It is possible to freeze the GPIO control registers by applying a specific write sequence to the GPIOx_LCKR register. The frozen registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.

To write the GPIOx_LCKR register, a specific write / read sequence has to be applied. When the right LOCK sequence is applied to bit 16 in this register, the value of LCKR[15:0] is used to lock the configuration of the I/Os (during the write sequence the LCKR[15:0] value must be the same). When the LOCK sequence has been applied to a port bit, the value of the port bit can no longer be modified until the next MCU reset or peripheral reset. Each GPIOx_LCKR bit freezes the corresponding bit in the control registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH).

The LOCK sequence (refer to Section 13.4.8: GPIO port configuration lock register (GPIOx_LCKR) (x = A to K, Z)) can only be performed using a word (32-bit long) access to the GPIOx_LCKR register due to the fact that GPIOx_LCKR bit 16 has to be set at the same time as the [15:0] bits.

For more details refer to LCKR register description in Section 13.4.8: GPIO port configuration lock register (GPIOx_LCKR) (x = A to K, Z).

13.3.7 I/O alternate function input/output

Two registers are provided to select one of the alternate function inputs/outputs available for each I/O. With these registers, the user can connect an alternate function to some other pin as required by the application.

This means that a number of possible peripheral functions are multiplexed on each GPIO using the GPIOx_AFRL and GPIOx_AFRH alternate function registers. The application can thus select any one of the possible functions for each I/O. The AF selection signal being common to the alternate function input and alternate function output, a single channel is selected for the alternate function input/output of a given I/O.

To know which functions are multiplexed on each GPIO pin refer to the device datasheet.

13.3.8 External interrupt/wakeup lines

All ports have external interrupt capability. To use external interrupt lines, the port must not be configured in analog mode.

Refer to Section 23: Extended interrupt and event controller (EXTI).

13.3.9 Input configuration

When the I/O port is programmed as input:

Figure 118 shows the input configuration of the I/O port bit.

Figure 118. Input floating/pull up/pull down configurations

Block diagram of input floating/pull up/pull down configurations showing the internal structure of a GPIO pin.

The diagram illustrates the internal structure of a GPIO pin for input configurations. It shows the following components and connections:

ai15940b

Block diagram of input floating/pull up/pull down configurations showing the internal structure of a GPIO pin.

13.3.10 Output configuration

When the I/O port is programmed as output:

Figure 119 shows the output configuration of the I/O port bit.

Figure 119. Output configuration

Figure 119: Output configuration diagram. The diagram shows the internal structure of a GPIO output. On the left, 'Read' and 'Write' signals are shown. 'Write' goes to 'Bit set/reset registers', which then feed into an 'Output data register'. 'Read/write' also connects to the 'Output data register'. The 'Output data register' feeds into an 'Output driver' block. Inside the 'Output driver', there is an 'Output control' block connected to a P-MOS and an N-MOS transistor. The P-MOS gate is connected to VDD and the N-MOS gate to VSS. The output of the driver connects to the 'I/O pin'. The 'I/O pin' is also connected to a 'TTL Schmitt trigger' (with an 'on' input) which feeds back into the 'Input data register'. The 'Input data register' is connected to a 'Read' signal. The 'Input data register' also feeds into a 'Bit set/reset registers' block. The 'Input driver' block is shown as a dashed box containing the 'TTL Schmitt trigger'. The 'Output driver' block is also a dashed box containing the 'Output control' and transistors. The 'I/O pin' is connected to 'pull up' and 'pull down' resistors (with 'on/off' controls) and 'protection diodes' to VDD and VSS. The label 'ai15941b' is in the bottom right corner.
Figure 119: Output configuration diagram. The diagram shows the internal structure of a GPIO output. On the left, 'Read' and 'Write' signals are shown. 'Write' goes to 'Bit set/reset registers', which then feed into an 'Output data register'. 'Read/write' also connects to the 'Output data register'. The 'Output data register' feeds into an 'Output driver' block. Inside the 'Output driver', there is an 'Output control' block connected to a P-MOS and an N-MOS transistor. The P-MOS gate is connected to VDD and the N-MOS gate to VSS. The output of the driver connects to the 'I/O pin'. The 'I/O pin' is also connected to a 'TTL Schmitt trigger' (with an 'on' input) which feeds back into the 'Input data register'. The 'Input data register' is connected to a 'Read' signal. The 'Input data register' also feeds into a 'Bit set/reset registers' block. The 'Input driver' block is shown as a dashed box containing the 'TTL Schmitt trigger'. The 'Output driver' block is also a dashed box containing the 'Output control' and transistors. The 'I/O pin' is connected to 'pull up' and 'pull down' resistors (with 'on/off' controls) and 'protection diodes' to VDD and VSS. The label 'ai15941b' is in the bottom right corner.

13.3.11 I/O compensation cell

This cell is used to control the I/O commutation slew rate (\(t_{fall}\) / \(t_{rise}\)) to reduce the I/O noise on power supply.

The cell is split into two blocks:

The I/O compensation cell features 2 voltage ranges: 1.62 to 2.0 V and 2.7 to 3.6 V.

13.3.12 Alternate function configuration

When the I/O port is programmed as alternate function:

Figure 120 shows the Alternate function configuration of the I/O port bit.

Figure 120. Alternate function configuration Figure 120: Alternate function configuration block diagram showing internal connections of GPIO pin with input data register, TTL Schmitt trigger, output driver with P-MOS/N-MOS push-pull/open-drain, pull-up/pull-down resistors, and protection diodes.
Figure 120: Alternate function configuration block diagram showing internal connections of GPIO pin with input data register, TTL Schmitt trigger, output driver with P-MOS/N-MOS push-pull/open-drain, pull-up/pull-down resistors, and protection diodes.

13.3.13 Analog configuration

When the I/O port is programmed as analog configuration:

Figure 121 shows the high-impedance, analog-input configuration of the I/O port bits.

Figure 121. High impedance-analog configuration Figure 121: High impedance-analog configuration block diagram showing disabled TTL Schmitt trigger forced to 0, pull-down resistor controlled by on/off, protection diodes, and analog path connection to on-chip peripheral.
Figure 121: High impedance-analog configuration block diagram showing disabled TTL Schmitt trigger forced to 0, pull-down resistor controlled by on/off, protection diodes, and analog path connection to on-chip peripheral.

Some pins/balls are directly connected to ANA0 and ANA1 ADC analog inputs (see Figure 122): there is a direct path between ANA0/ANA1 and PA0/PA1 pins/balls, through an analog switch (refer to Section 14.3.2: SYSCFG peripheral mode configuration set register (SYSCFG_PMCSETR) for details on how to configure analog switches).

Figure 122. Analog inputs connected to ADC inputs

Figure 122. Analog inputs connected to ADC inputs block diagram

The diagram illustrates the internal structure of a GPIO port and its connection to ADC inputs.
GPIO Section:

ADC Section:The diagram is labeled 'MSv44739V1' in the bottom right corner.

Figure 122. Analog inputs connected to ADC inputs block diagram

1. VDD_FT is a potential specific to 5V tolerant I/Os. It is distinct from VDD.

13.3.14 Using the HSE or LSE oscillator pins as GPIOs

When the HSE or LSE oscillator is switched OFF (default state after reset), the related oscillator pins can be used as normal GPIOs.

When the HSE or LSE oscillator is switched ON (by setting the HSEON or LSEON bit in the RCC_CSR register) the oscillator takes control of its associated pins and the GPIO configuration of these pins has no effect. This is also true in External clock mode.

13.3.15 Using the GPIO pins in the backup supply domain

The PC13, PC14, PC15, and PI8 GPIO functionality is lost when the core supply domain is powered off (for example, when the device enters standby mode).

In this case, if their GPIO configuration (including GPIO pull-up/pull-down and open-drain settings) is not bypassed by any RTC, TAMP, or PWR (WKUP) configuration, these pins are forced into analog mode.

For details about I/O control by the RTC, refer to Section 48.3: RTC functional description.

13.3.16 TrustZone security (only for GPIOZ)

The TrustZone security is always activated On GPIOZ. Each I/O pin of GPIOZ port can be individually configured as secure through the GPIOZ_SECCFGR register.

When the selected I/O pin is configured as secure, its corresponding configuration bits for alternate function AFI, AFO, mode selection, I/O data are secure against a non-secure access:

After reset, all GPIOZ I/O pins are secure.

Table 83 gives a summary of the I/O port secured bits following the security configuration bit in the GPIOZ_SECCFGR register.

Table 83. GPIO secured bits(1)

Secure configuration bitSecured bitRegister nameNon-secure access on secure bits
SECy = 1 in GPIOx_SECCFGRMODEy[1:0]GPIOx_MODERRAZ/WI
OTyGPIOx_OTYPER
OSPEEDy[1:0]GPIOx_OSPEEDR
PUPDy[1:0]GPIOx_PUPDR
IDyGPIOx_IDR
ODyGPIOx_ODR
BSyGPIOx_BSRR
LCKyGPIOx_LCKR
AFSELy[3:0]GPIOx_AFRL
BRyGPIOx_AFRH
GPIOx_BRR

1. GPIOx, x= Z, and y=0..7.

13.4 GPIO registers

This section gives a detailed description of the GPIO registers.

For a summary of register bits, register address offsets and reset values, refer to Table 84.

The peripheral registers can be written in word, half word or byte mode.

13.4.1 GPIO port mode register (GPIOx_MODER)
(x = A to K, Z)

Address offset: 0x00

Reset value: 0xFFFF FFFF

31302928272625242322212019181716
MODER15[1:0]MODER14[1:0]MODER13[1:0]MODER12[1:0]MODER11[1:0]MODER10[1:0]MODER9[1:0]MODER8[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
MODER7[1:0]MODER6[1:0]MODER5[1:0]MODER4[1:0]MODER3[1:0]MODER2[1:0]MODER1[1:0]MODER0[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 MODER[15:0][1:0]: Port x configuration I/O pin y (y = 15 to 0)

These bits are written by software to configure the I/O mode.

00: Input mode

01: General purpose output mode

10: Alternate function mode

11: Analog mode

13.4.2 GPIO port output type register (GPIOx_OTYPER)
(x = A to K, Z)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
OT15OT14OT13OT12OT11OT10OT9OT8
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 OT[15:0]: Port x configuration I/O pin y (y = 15 to 0)

These bits are written by software to configure the I/O output type.

0: Output push-pull (reset state)

1: Output open-drain

13.4.3 GPIO port output speed register (GPIOx_OSPEEDR)
(x = A to K, Z)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
OSPEEDR15
[1:0]
OSPEEDR14
[1:0]
OSPEEDR13
[1:0]
OSPEEDR12
[1:0]
OSPEEDR11
[1:0]
OSPEEDR10
[1:0]
OSPEEDR9
[1:0]
OSPEEDR8
[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
OSPEEDR7
[1:0]
OSPEEDR6
[1:0]
OSPEEDR5
[1:0]
OSPEEDR4
[1:0]
OSPEEDR3
[1:0]
OSPEEDR2
[1:0]
OSPEEDR1
[1:0]
OSPEEDR0
[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
Bits 31:0 OSPEEDR[15:0][1:0] : Port x configuration I/O pin y (y = 15 to 0)

These bits are written by software to configure the I/O output speed.

00: Low speed

01: Medium speed

10: High speed

11: Very high speed

Note: Refer to the product datasheets for the values of OSPEEDRy bits versus VDD range and external load.

13.4.4 GPIO port pull-up/pull-down register (GPIOx_PUPDR)
(x = A to K, Z)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
PUPDR15[1:0]PUPDR14[1:0]PUPDR13[1:0]PUPDR12[1:0]PUPDR11[1:0]PUPDR10[1:0]PUPDR9[1:0]PUPDR8[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
PUPDR7[1:0]PUPDR6[1:0]PUPDR5[1:0]PUPDR4[1:0]PUPDR3[1:0]PUPDR2[1:0]PUPDR1[1:0]PUPDR0[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
Bits 31:0 PUPDR[15:0][1:0] : Port x configuration I/O pin y (y = 15 to 0)

These bits are written by software to configure the I/O pull-up or pull-down

00: No pull-up, pull-down

01: Pull-up

10: Pull-down

11: Reserved

13.4.5 GPIO port input data register (GPIOx_IDR)
(x = A to K, Z)

Address offset: 0x10

Reset value: 0x0000 XXXX

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
IDR15IDR14IDR13IDR12IDR11IDR10IDR9IDR8IDR7IDR6IDR5IDR4IDR3IDR2IDR1IDR0
rrrrrrrrrrrrrrrr

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 IDR[15:0]: Port x input data I/O pin y (y = 15 to 0)

These bits are read-only. They contain the input value of the corresponding I/O port.

13.4.6 GPIO port output data register (GPIOx_ODR)
(x = A to K, Z)

Address offset: 0x14

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
ODR15ODR14ODR13ODR12ODR11ODR10ODR9ODR8ODR7ODR6ODR5ODR4ODR3ODR2ODR1ODR0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 ODR[15:0]: Port output data I/O pin y (y = 15 to 0)

These bits can be read and written by software.

Note: For atomic bit set/reset, the ODR bits can be individually set and/or reset by writing to the GPIOx_BSRR register (x = A..F).

13.4.7 GPIO port bit set/reset register (GPIOx_BSRR)
(x = A to K, Z)

Address offset: 0x18

Reset value: 0x0000 0000

31302928272625242322212019181716
BR15BR14BR13BR12BR11BR10BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0
wwwwwwwwwwwwwwww
1514131211109876543210
BS15BS14BS13BS12BS11BS10BS9BS8BS7BS6BS5BS4BS3BS2BS1BS0
wwwwwwwwwwwwwwww

Bits 31:16 BR[15:0]: Port x reset I/O pin y (y = 15 to 0)

These bits are write-only. A read to these bits returns the value 0x0000.

0: No action on the corresponding ODRx bit

1: Resets the corresponding ODRx bit

Note: If both BSx and BRx are set, BSx has priority.

Bits 15:0 BS[15:0]: Port x set I/O pin y (y = 15 to 0)

These bits are write-only. A read to these bits returns the value 0x0000.

0: No action on the corresponding ODRx bit

1: Sets the corresponding ODRx bit

13.4.8 GPIO port configuration lock register (GPIOx_LCKR)
(x = A to K, Z)

This register is used to lock the configuration of the port bits when a correct write sequence is applied to bit 16 (LCKK). The value of bits [15:0] is used to lock the configuration of the GPIO. During the write sequence, the value of LCKR[15:0] must not change. When the LOCK sequence has been applied on a port bit, the value of this port bit can no longer be modified until the next MCU reset or peripheral reset.

Note: A specific write sequence is used to write to the GPIOx_LCKR register. Only word access (32-bit long) is allowed during this locking sequence.

Each lock bit freezes a specific configuration register (control and alternate function registers).

Address offset: 0x1C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.LCKK
rw
1514131211109876543210
LCK15LCK14LCK13LCK12LCK11LCK10LCK9LCK8LCK7LCK6LCK5LCK4LCK3LCK2LCK1LCK0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:17 Reserved, must be kept at reset value.

Bit 16 LCKK: Lock key

This bit can be read any time. It can only be modified using the lock key write sequence.

0: Port configuration lock key not active

1: Port configuration lock key active. The GPIOx_LCKR register is locked until the next MCU reset or peripheral reset.

LOCK key write sequence:

WR LCKR[16] = '1' + LCKR[15:0]

WR LCKR[16] = '0' + LCKR[15:0]

WR LCKR[16] = '1' + LCKR[15:0]

RD LCKR

RD LCKR[16] = '1' (this read operation is optional but it confirms that the lock is active)

Note: During the LOCK key write sequence, the value of LCK[15:0] must not change.

Any error in the lock sequence aborts the lock.

After the first lock sequence on any bit of the port, any read access on the LCKK bit returns '1' until the next MCU reset or peripheral reset.

Bits 15:0 LCK[15:0]: Port x lock I/O pin y (y = 15 to 0)

These bits are read/write but can only be written when the LCKK bit is '0.

0: Port configuration not locked

1: Port configuration locked

13.4.9 GPIO alternate function low register (GPIOx_AFRL)
(x = A to K, Z)

Address offset: 0x20

Reset value: 0x0000 0000

31302928272625242322212019181716
AFR7[3:0]AFR6[3:0]AFR5[3:0]AFR4[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
AFR3[3:0]AFR2[3:0]AFR1[3:0]AFR0[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 AFR[7:0][3:0]: Alternate function selection for port x I/O pin y (y = 7 to 0)
These bits are written by software to configure alternate function I/Os.
0000: AF0
0001: AF1
0010: AF2
0011: AF3
0100: AF4
0101: AF5
0110: AF6
0111: AF7
1000: AF8
1001: AF9
1010: AF10
1011: AF11
1100: AF12
1101: AF13
1110: AF14
1111: AF15

13.4.10 GPIO alternate function high register (GPIOx_AFRH)
(x = A to K, Z)

Address offset: 0x24

Reset value: 0x0000 0000

31302928272625242322212019181716
AFR15[3:0]AFR14[3:0]AFR13[3:0]AFR12[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
AFR11[3:0]AFR10[3:0]AFR9[3:0]AFR8[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
ST logo
ST logo

Bits 31:0 AFR[15:8][3:0]: Alternate function selection for port x I/O pin y (y = 15 to 8)

These bits are written by software to configure alternate function I/Os.

0000: AF0
0001: AF1
0010: AF2
0011: AF3
0100: AF4
0101: AF5
0110: AF6
0111: AF7
1000: AF8
1001: AF9
1010: AF10
1011: AF11
1100: AF12
1101: AF13
1110: AF14
1111: AF15

13.4.11 GPIO port bit reset register (GPIOx_BRR) (x = A to K, Z)

Address offset: 0x28

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
BR15BR14BR13BR12BR11BR10BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0
wwwwwwwwwwwwwwww

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 BR[15:0]: Port x reset IO pin y (y = 15 to 0)

These bits are write-only. A read to these bits returns the value 0x0000.

0: No action on the corresponding ODx bit

1: Reset the corresponding ODx bit

13.4.12 GPIO secure configuration register (GPIOZ_SECCFGR)

This register provides access security control and can be written only by a secure access. It is used to configure a selected I/O as secure. A non-secure write access to this register is discarded. Read returns the current GPIOZ pin security setting.

Address offset: 0x30

Reset value: 0x0000 00FF

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.SEC7SEC6SEC5SEC4SEC3SEC2SEC1SEC0
rwrwrwrwwrrwrwrw

Bits 31:8 Reserved

Bits 7:0 SEC[7:0]: I/O pin of Port Z secure bit enable y (y= 0..7)

These bits control the security I/O port pin.

0: The I/O pin is non-secure

1: The I/O pin is secure. Refer to Table 83: GPIO secured bits for all corresponding secured bits.

13.4.13 GPIO hardware configuration register 10 (GPIOx_HWCFGR10)
(x = A to K, Z)

Address offset: 0x3C8

Reset value: 0x0000 1240

Reset value: Block Z: 0x0001 1240

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.OR_CFG[3:0]SEC_CFG[3:0]
rrrrrrrr
1514131211109876543210
LOCK_CFG[3:0]SPEED_CFG[3:0]AF_SIZE[3:0]AHB_IOP[3:0]
rrrrrrrrrrrrrrrr

Bits 31:24 Reserved, must be kept at reset value.

Bits 23:20 OR_CFG[3:0]: Option register configuration

0: Non-active

1: Active

Bits 19:16 SEC_CFG[3:0]: Security mechanism activation

0: Non-active

1: Active

Bits 15:12 LOCK_CFG[3:0]: Lock mechanism activation

0: Non-active

1: Active

Bits 11:8 SPEED_CFG[3:0]: Number of speed lines for each I/O

Bits 7:4 AF_SIZE[3:0]: Number of AF available for each I/O

Bits 3:0 AHB_IOP[3:0]: Bus interface configuration

13.4.14 GPIO hardware configuration register 9 (GPIOx_HWCFGR9)
(x = A to K, Z)

Address offset: 0x3CC

Reset value: 0x0000 FFFF

Reset value: Block K: 0x0000 00FF

Reset value: Block Z: 0x0000 00FF

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
EN_IO[15:0]
rrrrrrrrrrrrrrrr

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 EN_IO[15:0]: Presence granularity, each bit indicate the presence of the IO

13.4.15 GPIO hardware configuration register 8 (GPIOx_HWCFGR8)
(x = A to K, Z)

Address offset: 0x3D0

Reset value: 0xFFFF FFFF

Reset value: Block K: 0x0000 0000

Reset value: Block Z: 0x0000 0000

31302928272625242322212019181716
AF_PRIO15[3:0]AF_PRIO14[3:0]AF_PRIO13[3:0]AF_PRIO12[3:0]
rrrrrrrrrrrrrrrr
1514131211109876543210
AF_PRIO11[3:0]AF_PRIO10[3:0]AF_PRIO9[3:0]AF_PRIO8[3:0]
rrrrrrrrrrrrrrrr

Bits 31:28 AF_PRIO15[3:0]: Indicate the priority AF for I/O15 (0 to F)

Bits 27:24 AF_PRIO14[3:0]: Indicate the priority AF for I/O14 (0 to F)

Bits 23:20 AF_PRIO13[3:0]: Indicate the priority AF for I/O13 (0 to F)

Bits 19:16 AF_PRIO12[3:0]: Indicate the priority AF for I/O12 (0 to F)

Bits 15:12 AF_PRIO11[3:0]: Indicate the priority AF for I/O11 (0 to F)

Bits 11:8 AF_PRIO10[3:0]: Indicate the priority AF for I/O10 (0 to F)

Bits 7:4 AF_PRIO9[3:0]: Indicate the priority AF for I/O9 (0 to F)

Bits 3:0 AF_PRIO8[3:0]: Indicate the priority AF for I/O8 (0 to F)

13.4.16 GPIO hardware configuration register 7 (GPIOx_HWCFGR7)
(x = A to K, Z)

Address offset: 0x3D4

Reset value: 0xFFFF FFFF

31302928272625242322212019181716
AF_PRIO7[3:0]AF_PRIO6[3:0]AF_PRIO5[3:0]AF_PRIO4[3:0]
rrrrrrrrrrrrrrrr
1514131211109876543210
AF_PRIO3[3:0]AF_PRIO2[3:0]AF_PRIO1[3:0]AF_PRIO0[3:0]
rrrrrrrrrrrrrrrr

Bits 31:28 AF_PRIO7[3:0]: Indicate the priority AF for I/O7 (0 to F)

Bits 27:24 AF_PRIO6[3:0]: Indicate the priority AF for I/O6 (0 to F)

Bits 23:20 AF_PRIO5[3:0]: Indicate the priority AF for I/O5 (0 to F)

Bits 19:16 AF_PRIO4[3:0]: Indicate the priority AF for I/O4 (0 to F)

Bits 15:12 AF_PRIO3[3:0]: Indicate the priority AF for I/O3 (0 to F)

Bits 11:8 AF_PRIO2[3:0]: Indicate the priority AF for I/O2 (0 to F)

Bits 7:4 AF_PRIO1[3:0]: Indicate the priority AF for I/O1 (0 to F)

Bits 3:0 AF_PRIO0[3:0]: Indicate the priority AF for I/O0 (0 to F)

13.4.17 GPIO hardware configuration register 6 (GPIOx_HWCFGR6)
(x = A to K, Z)

Address offset: 0x3D8

Reset value: 0xFFFF FFFF

31302928272625242322212019181716
MODER_RES[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
MODER_RES[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 MODER_RES[31:0]: MODER register reset value

13.4.18 GPIO hardware configuration register 5 (GPIOx_HWCFGR5)
(x = A to K, Z)

Address offset: 0x3DC

Reset value: 0x0000 0000

31302928272625242322212019181716
PUPDR_RES[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
PUPDR_RES[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 PUPDR_RES[31:0]: Pull-up / pull-down register reset value

13.4.19 GPIO hardware configuration register 4 (GPIOx_HWCFGR4)
(x = A to K, Z)

Address offset: 0x3E0

Reset value: 0x0000 0000

31302928272625242322212019181716
OSPEED_RES[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
OSPEED_RES[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 OSPEED_RES[31:0]: OSPEED register reset value

13.4.20 GPIO hardware configuration register 3 (GPIOx_HWCFGR3)
(x = A to K, Z)

Address offset: 0x3E4

Reset value: 0x0000 0000

31302928272625242322212019181716
OTYPER_RES[15:0]
rrrrrrrrrrrrrrrr
1514131211109876543210
ODR_RES[15:0]
rrrrrrrrrrrrrrrr

Bits 31:16 OTYPER_RES[31:0]: Output type register reset value

Bits 15:0 ODR_RES[31:0]: Output data register reset value

13.4.21 GPIO hardware configuration register 2 (GPIOx_HWCFGR2)
(x = A to K, Z)

Address offset: 0x3E8

Reset value: 0x0000 0000

31302928272625242322212019181716
AFRL_RES[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
AFRL_RES[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 AFRL_RES[31:0]: AF register low reset value

13.4.22 GPIO hardware configuration register 1 (GPIOx_HWCFGR1)
(x = A to K, Z)

Address offset: 0x3EC

Reset value: 0x0000 0000

31302928272625242322212019181716
AFRH_RES[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
AFRH_RES[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 AFRH_RES[31:0]: AF register high reset value

13.4.23 GPIO hardware configuration register 0 (GPIOx_HWCFGR0)
(x = A to K, Z)

Address offset: 0x3F0

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
OR_RES[15:0]
rrrrrrrrrrrrrrrr

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 OR_RES[15:0]: Option register reset value

13.4.24 GPIO version register (GPIOx_VERR) (x = A to K, Z)

Address offset: 0x3F4

Reset value: 0x0000 0040

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.MAJREV[3:0]MINREV[3:0]
rrrrrrrr

Bits 31:8 Reserved, must be kept at reset value.

Bits 7:4 MAJREV[3:0]: Major revision

These bits return the GPIO major revision.

Major revision is 4.

Bits 3:0 MINREV[3:0]: Minor revision

These bits return the GPIO minor revision.

Minor revision is 0.

13.4.25 GPIO identification register (GPIOx_IPIDR) (x = A to K, Z)

Address offset: 0x3F8

Reset value: 0x000F 0003

31302928272625242322212019181716
IPIDR[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
IPIDR[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 IPIDR[31:0]: GPIO identifier

These bits return the GPIO identifier value.

13.4.26 GPIO size identification register (GPIOx_SIDR) (x = A to K, Z)

Address offset: 0x3FC

Reset value: 0xA3C5 DD01

31302928272625242322212019181716
SIDR[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
SIDR[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 SIDR[31:0]: Size identifier register
These bits return the size of the memory region allocated to GPIO registers.

ST logo
ST logo

13.4.27 GPIO register map

The following table gives the GPIO register map and reset values.

Table 84. GPIO register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00GPIOx_MODER
(where x = A to K, Z)
MODER15[1:0]MODER14[1:0]MODER13[1:0]MODER12[1:0]MODER11[1:0]MODER10[1:0]MODER9[1:0]MODER8[1:0]MODER7[1:0]MODER6[1:0]MODER5[1:0]MODER4[1:0]MODER3[1:0]MODER2[1:0]MODER1[1:0]MODER0[1:0]
Reset value11111111111111111111111111111111
0x04GPIOx_OTYPER
(where x = A to K, Z)
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OT15OT14OT13OT12OT11OT10OT9OT8OT7OT6OT5OT4OT3OT2OT1OT0
Reset value000000000000000
0x08GPIOx_OSPEEDR
(where x = A to K, Z)
OSPEEDR15[1:0]OSPEEDR14[1:0]OSPEEDR13[1:0]OSPEEDR12[1:0]OSPEEDR11[1:0]OSPEEDR10[1:0]OSPEEDR9[1:0]OSPEEDR8[1:0]OSPEEDR7[1:0]OSPEEDR6[1:0]OSPEEDR5[1:0]OSPEEDR4[1:0]OSPEEDR3[1:0]OSPEEDR2[1:0]OSPEEDR1[1:0]OSPEEDR0[1:0]
Reset value0000000000000000000000000000000
0x0CGPIOA_PUPDR
(where x = A to K, Z)
PUPDR15[1:0]PUPDR14[1:0]PUPDR13[1:0]PUPDR12[1:0]PUPDR11[1:0]PUPDR10[1:0]PUPDR9[1:0]PUPDR8[1:0]PUPDR7[1:0]PUPDR6[1:0]PUPDR5[1:0]PUPDR4[1:0]PUPDR3[1:0]PUPDR2[1:0]PUPDR1[1:0]PUPDR0[1:0]
Reset value0000000000000000000000000000000
0x10GPIOx_IDR
(where x = A to K, Z)
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.IDR15IDR14IDR13IDR12IDR11IDR10IDR9IDR8IDR7IDR6IDR5IDR4IDR3IDR2IDR1IDR0
Reset valuexxxxxxxxxxxxxxx
0x14GPIOx_ODR
(where x = A to K, Z)
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ODR15ODR14ODR13ODR12ODR11ODR10ODR9ODR8ODR7ODR6ODR5ODR4ODR3ODR2ODR1ODR0
Reset value000000000000000
0x18GPIOx_BSRR
(where x = A to K, Z)
BR15BR14BR13BR12BR11BR10BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0BS15BS14BS13BS12BS11BS10BS9BS8BS7BS6BS5BS4BS3BS2BS1BS0
Reset value0000000000000000000000000000000
0x1CGPIOx_LCKR
(where x = A to K, Z)
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.LCK15LCK14LCK13LCK12LCK11LCK10LCK9LCK8LCK7LCK6LCK5LCK4LCK3LCK2LCK1LCK0
Reset value000000000000000
0x20GPIOx_AFRL
(where x = A to K, Z)
AFR7[3:0]AFR6[3:0]AFR5[3:0]AFR4[3:0]AFR3[3:0]AFR2[3:0]AFR1[3:0]AFR0[3:0]
Reset value0000000000000000000000000000000
0x24GPIOx_AFRH
(where x = A to K, Z)
AFR15[3:0]AFR14[3:0]AFR13[3:0]AFR12[3:0]AFR11[3:0]AFR10[3:0]AFR9[3:0]AFR8[3:0]
Reset value0000000000000000000000000000000
0x28GPIOx_BRR
(where x = A to K, Z)
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BR15BR14BR13BR12BR11BR10BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0
Reset value000000000000000
0x30GPIOZ_SECCFGRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SEC7SEC6SEC5SEC4SEC3SEC2SEC1SEC0
Reset value11111111
Table 84. GPIO register map and reset values (continued)
OffsetRegister name313029282726252423222120191817161514131211109876543210
0x03C8GPIOx_HWCFGR10
(where x = A to K, Z)
Res.Res.Res.Res.Res.Res.Res.Res.OR_CFG[3:0]SEC_CFG[3:0]LOCK_CFG[3:0]SPEED_CFG[3:0]AF_SIZE[3:0]AHB_IOP[3:0]
Reset value
(for GPIOA,B,C,D,
E,F,G,H,I,J,K)
000000000001001001000000
Reset value
(for GPIOZ)
000000010001001001000000
0x03CCGPIOx_HWCFGR9
(where x = A to K, Z)
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.EN_IO[15:0]
Reset value
(for GPIOA,B,C,D,
E,F,G,H,I,J)
1111111111111111
Reset value
(for GPIOK,Z)
0000000011111111
0x03D0GPIOx_HWCFGR8
(where x = A to K, Z)
AF_PRIO15[3:0]AF_PRIO14[3:0]AF_PRIO13[3:0]AF_PRIO12[3:0]AF_PRIO11[3:0]AF_PRIO10[3:0]AF_PRIO9[3:0]AF_PRIO8[3:0]
Reset value
(for GPIOA,B,C,D,
E,F,G,H,I,J)
11111111111111111111111111111111
Reset value
(for GPIOK,Z)
00000000000000000000000000000000
0x03D4GPIOx_HWCFGR7
(where x = A to K, Z)
AF_PRIO7[3:0]AF_PRIO6[3:0]AF_PRIO5[3:0]AF_PRIO4[3:0]AF_PRIO3[3:0]AF_PRIO2[3:0]AF_PRIO1[3:0]AF_PRIO0[3:0]
Reset value11111111111111111111111111111111
0x03D8GPIOx_HWCFGR6
(where x = A to K, Z)
MODER_RES[31:16]MODER_RES[15:0]
Reset value11111111111111111111111111111111
0x03DCGPIOx_HWCFGR5
(where x = A to K, Z)
PUPDR_RES[31:16]PUPDR_RES[15:0]
Reset value00000000000000000000000000000000
0x03E0GPIOx_HWCFGR4
(where x = A to K, Z)
OSPEED_RES[31:16]OSPEED_RES[15:0]
Reset value00000000000000000000000000000000
0x03E4GPIOx_HWCFGR3
(where x = A to K, Z)
OTYPER_RES[31:16]ODR_RES[15:0]
Reset value00000000000000000000000000000000
0x03E8GPIOx_HWCFGR2
(where x = A to K, Z)
AFRL_RES[31:16]AFRL_RES[15:0]
Reset value00000000000000000000000000000000
0x03ECGPIOx_HWCFGR1
(where x = A to K, Z)
AFRH_RES[31:16]AFRH_RES[15:0]
Reset value00000000000000000000000000000000
0x03F0GPIOx_HWCFGR0
(where x = A to K, Z)
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OR_RES[15:0]
Reset value0000000000000000
0x03F4GPIO_VERRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MAJREV[3:0]MINREV[3:0]
Reset value01000000
0x03F8GPIO_IPIDRID[31:16]ID[15:0]
Reset value00000000000011110000000000000011
0x03FCGPIO_SIDRSID[31:16]SID[15:0]
Reset value10100011110001011101110100000001
Refer to Section 2.5 on page 149 for the register boundary addresses.