8. General-purpose I/Os (GPIO)

8.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).

8.2 GPIO main features

8.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 19 shows the basic structure of a Three-volt tolerant (TT) and Five-volt tolerant (FT) I/O port bit.

Figure 19. Three-volt or Five-volt tolerant GPIO structure (TT or FT)

Figure 19: Three-volt or Five-volt tolerant GPIO structure (TT or FT). The diagram shows the internal architecture of a GPIO pin, divided into Analog and Digital domains. The Analog domain includes an Analog IP, a parasitic diode and resistor connected to V_DDA, and an analog switch controlled by an 'Analog option'. The Digital domain includes an 'Alternate function input', an 'Input data register', an 'Output data register', an 'Alternate function output', an 'Input buffer', and an 'Output buffer'. The Output buffer contains an 'Output control' block connected to PMOS and NMOS transistors, which are connected to V_DD and V_SS respectively. The I/O pin is connected to the output buffer and an 'ESD protection' block. The ESD protection block is connected to V_SS and V_DD. The diagram also shows resistors R_PU and R_PU on the V_DD and V_SS lines, and an 'on/off' control for the ESD protection.
Figure 19: Three-volt or Five-volt tolerant GPIO structure (TT or FT). The diagram shows the internal architecture of a GPIO pin, divided into Analog and Digital domains. The Analog domain includes an Analog IP, a parasitic diode and resistor connected to V_DDA, and an analog switch controlled by an 'Analog option'. The Digital domain includes an 'Alternate function input', an 'Input data register', an 'Output data register', an 'Alternate function output', an 'Input buffer', and an 'Output buffer'. The Output buffer contains an 'Output control' block connected to PMOS and NMOS transistors, which are connected to V_DD and V_SS respectively. The I/O pin is connected to the output buffer and an 'ESD protection' block. The ESD protection block is connected to V_SS and V_DD. The diagram also shows resistors R_PU and R_PU on the V_DD and V_SS lines, and an 'on/off' control for the ESD protection.

MSV46873V1

Note: The parasitic diode in the analog domain is connected to \( V_{DDA} \) and cannot be used as a protection diode.

The voltage level called \( V_{DD\_FT} \) in some datasheets and reference manuals is within the ESD protection block.

When the analog option is selected, the FT I/O is not five-volt tolerant anymore since the pin is supplied with \( V_{DDA} \) .

A TT or FT GPIO pin has no internal protection diode connected to supply ( \( V_{DD} \) ). There is no physical limitation against over-voltage. Therefore, for applications requiring a limited voltage threshold, it is recommended to connect an external diode to \( V_{DD} \) .

Table 38 gives the possible port bit configurations.

Table 38. Port bit configuration table (1)
MODE(i)
[1:0]
OTYPER(i)OSPEED(i)
[1:0]
PUPD(i)I/O configuration
[1:0][1:0]
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
xxx10
xxx11
  1. 1. GP = general-purpose, PP = push-pull, PU = pull-up, PD = pull-down, OD = open-drain, AF = alternate function.

8.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 analog mode.

The debug pins are in AF pull-up/pull-down after reset:

PH3/BOOT0 is in input mode during the reset until at least the end of the option byte loading phase. See Section 8.3.15: Using PH3 as GPIO .

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.

8.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.

8.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.

8.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 8.4.5: GPIO port input data register (GPIOx_IDR) (x = A to C and E and H) and Section 8.4.6: GPIO port output data register (GPIOx_ODR) (x = A to C and E and H) for the register descriptions.

8.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.

8.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 8.4.8: GPIO port configuration lock register (GPIOx_LCKR) ( x = A to C and E and H )) 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 8.4.8: GPIO port configuration lock register (GPIOx_LCKR) ( x = A to C and E and H ).

8.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.

8.3.8 External interrupt/wake-up lines

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

Refer to Section 14: Extended interrupt and event controller (EXTI) and to Section 14.3: EXTI functional description .

8.3.9 Input configuration

When the I/O port is programmed as input:

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

Figure 20: Input floating / pull up / pull down configurations. This block diagram shows the internal architecture of an I/O port bit for input configurations. On the left, a 'Read' signal connects to an 'Input data register'. A 'Write' signal connects to 'Bit set/reset registers', which in turn connect to an 'Output data register'. A 'Read/write' signal also connects to the 'Output data register'. The 'Input data register' is connected to a 'TTL Schmitt trigger' (labeled 'on'). The 'Output data register' is connected to an 'Output driver' (labeled 'on/off'). The 'TTL Schmitt trigger' and 'Output driver' are both connected to the 'I/O pin'. The 'I/O pin' is also connected to a 'Pull up' resistor (connected to VDDIOX) and a 'Pull down' resistor (connected to VSS). A 'Protection diode' is connected between the 'I/O pin' and VSS. The 'Pull up' and 'Pull down' resistors are controlled by 'on/off' signals. The diagram is labeled MSv63602V1.

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

Figure 20: Input floating / pull up / pull down configurations. This block diagram shows the internal architecture of an I/O port bit for input configurations. On the left, a 'Read' signal connects to an 'Input data register'. A 'Write' signal connects to 'Bit set/reset registers', which in turn connect to an 'Output data register'. A 'Read/write' signal also connects to the 'Output data register'. The 'Input data register' is connected to a 'TTL Schmitt trigger' (labeled 'on'). The 'Output data register' is connected to an 'Output driver' (labeled 'on/off'). The 'TTL Schmitt trigger' and 'Output driver' are both connected to the 'I/O pin'. The 'I/O pin' is also connected to a 'Pull up' resistor (connected to VDDIOX) and a 'Pull down' resistor (connected to VSS). A 'Protection diode' is connected between the 'I/O pin' and VSS. The 'Pull up' and 'Pull down' resistors are controlled by 'on/off' signals. The diagram is labeled MSv63602V1.

8.3.10 Output configuration

When the I/O port is programmed as output:

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

Figure 21: Output configuration. This block diagram shows the internal architecture of an I/O port bit for output configurations. On the left, a 'Read' signal connects to an 'Input data register'. A 'Write' signal connects to 'Bit set/reset registers', which in turn connect to an 'Output data register'. A 'Read/write' signal also connects to the 'Output data register'. The 'Input data register' is connected to a 'TTL Schmitt trigger' (labeled 'on'). The 'Output data register' is connected to an 'Output control' block, which is connected to a 'P-MOS' and an 'N-MOS' (labeled 'Push-pull or open-drain'). The 'TTL Schmitt trigger' and the 'Output control' are both connected to the 'I/O pin'. The 'I/O pin' is also connected to a 'Pull up' resistor (connected to VDDIOX) and a 'Pull down' resistor (connected to VSS). A 'Protection diode' is connected between the 'I/O pin' and VSS. The 'Pull up' and 'Pull down' resistors are controlled by 'on/off' signals. The diagram is labeled MSv63641V1.

Figure 21. Output configuration

Figure 21: Output configuration. This block diagram shows the internal architecture of an I/O port bit for output configurations. On the left, a 'Read' signal connects to an 'Input data register'. A 'Write' signal connects to 'Bit set/reset registers', which in turn connect to an 'Output data register'. A 'Read/write' signal also connects to the 'Output data register'. The 'Input data register' is connected to a 'TTL Schmitt trigger' (labeled 'on'). The 'Output data register' is connected to an 'Output control' block, which is connected to a 'P-MOS' and an 'N-MOS' (labeled 'Push-pull or open-drain'). The 'TTL Schmitt trigger' and the 'Output control' are both connected to the 'I/O pin'. The 'I/O pin' is also connected to a 'Pull up' resistor (connected to VDDIOX) and a 'Pull down' resistor (connected to VSS). A 'Protection diode' is connected between the 'I/O pin' and VSS. The 'Pull up' and 'Pull down' resistors are controlled by 'on/off' signals. The diagram is labeled MSv63641V1.

8.3.11 Alternate function configuration

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

Figure 22 shows the alternate function configuration of the I/O port bit.

Figure 22. Alternate function configuration

Figure 22: Alternate function configuration diagram. This block diagram illustrates the internal architecture of a GPIO pin in alternate function mode. On the left, an 'Alternate function input' from an 'on-chip peripheral' is connected to an 'Input data register'. This register is 'Read' by the CPU. A 'Write' to 'Bit set/reset registers' controls the 'Output data register'. The 'Output data register' is 'Read/write' by the CPU and provides an 'Alternate function output' to the 'on-chip peripheral'. The 'Input data register' is connected to a 'TTL Schmitt trigger' (labeled 'on'). The 'Output data register' is connected to an 'Output control' block, which drives a 'P-MOS' and an 'N-MOS' transistor configured as a 'Push-pull or open-drain' driver. Both the Schmitt trigger and the output driver are part of an 'Input driver' and 'Output driver' block, respectively, which can be turned 'on/off'. The I/O pin is connected to the Schmitt trigger, the output driver, a 'Pull up' resistor (connected to VDDIOX), a 'Pull down' resistor (connected to VSS), an 'ESD protection' circuit (connected to VSS), and a 'Protection diode' (connected to VSS). The diagram is labeled MSV63642V1.
Figure 22: Alternate function configuration diagram. This block diagram illustrates the internal architecture of a GPIO pin in alternate function mode. On the left, an 'Alternate function input' from an 'on-chip peripheral' is connected to an 'Input data register'. This register is 'Read' by the CPU. A 'Write' to 'Bit set/reset registers' controls the 'Output data register'. The 'Output data register' is 'Read/write' by the CPU and provides an 'Alternate function output' to the 'on-chip peripheral'. The 'Input data register' is connected to a 'TTL Schmitt trigger' (labeled 'on'). The 'Output data register' is connected to an 'Output control' block, which drives a 'P-MOS' and an 'N-MOS' transistor configured as a 'Push-pull or open-drain' driver. Both the Schmitt trigger and the output driver are part of an 'Input driver' and 'Output driver' block, respectively, which can be turned 'on/off'. The I/O pin is connected to the Schmitt trigger, the output driver, a 'Pull up' resistor (connected to VDDIOX), a 'Pull down' resistor (connected to VSS), an 'ESD protection' circuit (connected to VSS), and a 'Protection diode' (connected to VSS). The diagram is labeled MSV63642V1.

8.3.12 Analog configuration

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

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

Figure 23. High impedance-analog configuration. This block diagram illustrates the internal architecture of an I/O pin in high-impedance analog mode. On the left, an 'On-chip peripheral' is connected to 'Bit set/reset registers' (Write) and an 'Output data register' (Read/write). The 'Input data register' is connected to a 'TTL Schmitt trigger' (labeled 'off') and provides a 'Read' signal. The 'Output data register' connects to an 'Input driver' and an 'Output driver' (both in dashed boxes). The 'I/O pin' is connected to the drivers, an 'ESD protection' circuit (connected to Vss), and a 'Protection diode' (connected to Vss). The pin is also connected to an 'Analog' input. The diagram is labeled MSv63643V1.

Figure 23. High impedance-analog configuration

Figure 23. High impedance-analog configuration. This block diagram illustrates the internal architecture of an I/O pin in high-impedance analog mode. On the left, an 'On-chip peripheral' is connected to 'Bit set/reset registers' (Write) and an 'Output data register' (Read/write). The 'Input data register' is connected to a 'TTL Schmitt trigger' (labeled 'off') and provides a 'Read' signal. The 'Output data register' connects to an 'Input driver' and an 'Output driver' (both in dashed boxes). The 'I/O pin' is connected to the drivers, an 'ESD protection' circuit (connected to Vss), and a 'Protection diode' (connected to Vss). The pin is also connected to an 'Analog' input. The diagram is labeled MSv63643V1.

8.3.13 Using the LSE oscillator pins as GPIOs

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

When the LSE oscillator is switched ON (by setting the 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.

When the oscillator is configured in a user external clock mode, only the OSC32_IN pin is reserved for clock input and the OSC32_OUT pin can still be used as normal GPIO.

Note: The HSE OSC_IN and OSC_OUT pins are dedicated oscillator pins and cannot be used as GPIO.

8.3.14 Using the GPIO pins in the RTC supply domain

The PC14/PC15 GPIO functionality is lost when the core supply domain is powered off (when the device enters Standby mode). In this case, if their GPIO configuration is not bypassed by the RTC configuration, these pins are set in an analog input mode.

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

8.3.15 Using PH3 as GPIO

PH3 may be used as boot pin (BOOT0) or as a GPIO. Depending on the nSWBOOT0 bit in the user option byte, it switches from the input mode to the analog input mode:

8.4 GPIO registers

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

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

8.4.1 GPIO port mode register (GPIOx_MODER)
(x = A to C and E and H)

Address offset: 0x00

Reset value: 0xABFF FFFF (for port A)

Reset value: 0xFFFF FEBF (for port B)

Reset value: 0xFFFF FFFF for port C, D

Reset value: 0x0000 03FF for port E

Reset value: 0x0000 00CF for port H

Port B[31:20] are reserved

Port C[27:0] are reserved

Port E[31:10, 7:0] are reserved

Port H[31:8, 5:0] are reserved

31 3029 2827 2625 2423 2221 2019 1817 16
MODE15[1:0]MODE14[1:0]MODE13[1:0]MODE12[1:0]MODE11[1:0]MODE10[1:0]MODE9[1:0]MODE8[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
15 1413 1211 109 87 65 43 21 0
MODE7[1:0]MODE6[1:0]MODE5[1:0]MODE4[1:0]MODE3[1:0]MODE2[1:0]MODE1[1:0]MODE0[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 MODE[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 (reset state)

8.4.2 GPIO port output type register (GPIOx_OTYPER)
(x = A to C and E and H)

Address offset: 0x04

Reset value: 0x0000 0000

Port B[31:10] are reserved

Port C[31:16, 13:0] are reserved

Port E[31:5, 3:0] are reserved

Port H[31:4, 2:0] are reserved

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
OT15OT14OT13OT12OT11OT10OT9OT8OT7OT6OT5OT4OT3OT2OT1OT0
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.

8.4.3 GPIO port output speed register (GPIOx_OSPEEDR)
(x = A to C and E and H)

Address offset: 0x08

Reset value: 0x0C00 0000 (for port A)

Reset value: 0x0000 00C0 (for port B)

Reset value: 0x0000 0000 (for other ports)

Port B[31:20] are reserved

Port C[27:0] are reserved

Port E[31:10, 7:0] are reserved

Port H[31:8, 5:0] are reserved

31302928272625242322212019181716
OSPEED15 [1:0]OSPEED14 [1:0]OSPEED13 [1:0]OSPEED12 [1:0]OSPEED11 [1:0]OSPEED10 [1:0]OSPEED9 [1:0]OSPEED8 [1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
OSPEED7 [1:0]OSPEED6 [1:0]OSPEED5 [1:0]OSPEED4 [1:0]OSPEED3 [1:0]OSPEED2 [1:0]OSPEED1 [1:0]OSPEED0 [1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 OSPEED[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: Fast speed

11: High speed

Note: Refer to the device datasheet for the frequency specifications and the power supply and load conditions for each speed..

8.4.4 GPIO port pull-up/pull-down register (GPIOx_PUPDR)
(x = A to C and E and H)

Address offset: 0x0C

Reset value: 0x6400 0000 (for port A)

Reset value: 0x0000 0100 (for port B)

Reset value: 0x0000 0000 (for other ports)

Port B[31:20] are reserved

Port C[27:0] are reserved

Port E[31:10, 7:0] are reserved

Port H[31:8, 5:0] are reserved

31302928272625242322212019181716
PUPD15[1:0]PUPD14[1:0]PUPD13[1:0]PUPD12[1:0]PUPD11[1:0]PUPD10[1:0]PUPD9[1:0]PUPD8[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
PUPD7[1:0]PUPD6[1:0]PUPD5[1:0]PUPD4[1:0]PUPD3[1:0]PUPD2[1:0]PUPD1[1:0]PUPD0[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 PUPD[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

8.4.5 GPIO port input data register (GPIOx_IDR)
(x = A to C and E and H)

Address offset: 0x10

Reset value: 0x0000 XXXX

Port B[31:10] are reserved

Port C[31:16, 13:0] are reserved

Port E[31:5, 3:0] are reserved

Port H[31:4, 2:0] are reserved

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
ID15ID14ID13ID12ID11ID10ID9ID8ID7ID6ID5ID4ID3ID2ID1ID0
rrrrrrrrrrrrrrrr

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

Bits 15:0 ID[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.

8.4.6 GPIO port output data register (GPIOx_ODR)
(x = A to C and E and H)

Address offset: 0x14

Reset value: 0x0000 0000

Port B[31:10] are reserved

Port C[31:16, 13:0] are reserved

Port E[31:5, 3:0] are reserved

Port H[31:4, 2:0] are reserved

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
OD15OD14OD13OD12OD11OD10OD9OD8OD7OD6OD5OD4OD3OD2OD1OD0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

Bits 15:0 OD[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 OD bits can be individually set and/or reset by writing to the GPIOx_BSR register (x = A..F).

8.4.7 GPIO port bit set/reset register (GPIOx_BSR)
(x = A to C and E and H)

Address offset: 0x18

Reset value: 0x0000 0000

Port B[31:26, 15:10] are reserved

Port C[29:16, 13:0] are reserved

Port E[31:21, 19:5, 3:0] are reserved

Port H[31:20, 18:4, 2:0] are reserved

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 ODx bit

1: Resets the corresponding ODx 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 ODx bit

1: Sets the corresponding ODx bit

8.4.8 GPIO port configuration lock register (GPIOx_LCKR)
(x = A to C and E and H)

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

Port B[31:17, 15:10] are reserved

Port C[31:17, 13:0] are reserved

Port E[31:17, 15:5, 3:0] are reserved

Port H[31:17, 15:4, 2:0] are reserved

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.LCKK
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

8.4.9 GPIO alternate function low register (GPIOx_AFRL)
(x = A to C and E and H)

Address offset: 0x20

Reset value: 0x0000 0000

Port C[31:0] are reserved

Port E[31:20, 15:0] are reserved

Port H[31:16, 11:0] are reserved

31302928272625242322212019181716
AFSEL7[3:0]AFSEL6[3:0]AFSEL5[3:0]AFSEL4[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
AFSEL3[3:0]AFSEL2[3:0]AFSEL1[3:0]AFSEL0[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 AFSEL[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

8.4.10 GPIO alternate function high register (GPIOx_AFRH)
(x = A to C and E and H)

Address offset: 0x24

Reset value: 0x0000 0000

Port B[31:8] are reserved

Port C[23:0] are reserved

Port E[31:0] are reserved

Port H[31:0] are reserved

31302928272625242322212019181716
AFSEL15[3:0]AFSEL14[3:0]AFSEL13[3:0]AFSEL12[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
AFSEL11[3:0]AFSEL10[3:0]AFSEL9[3:0]AFSEL8[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 AFSEL[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

8.4.11 GPIO port bit reset register (GPIOx_BRR) (x = A to C and E and H)

Address offset: 0x28

Reset value: 0x0000 0000

Port B[31:10] are reserved

Port C[31:16, 13:0] are reserved

Port E[31:5, 3:0] are reserved

Port H[31:4, 2:0] are reserved

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

8.4.12 GPIO register map

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

Table 39. GPIO register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00GPIOA_MODERMODE15[1:0]MODE14[1:0]MODE13[1:0]MODE12[1:0]MODE11[1:0]MODE10[1:0]MODE9[1:0]MODE8[1:0]MODE7[1:0]MODE6[1:0]MODE5[1:0]MODE4[1:0]MODE3[1:0]MODE2[1:0]MODE1[1:0]MODE0[1:0]
Reset value10101010111111111111111111111111
0x00GPIOB_MODERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MODE9[1:0]MODE8[1:0]MODE7[1:0]MODE6[1:0]MODE5[1:0]MODE4[1:0]MODE3[1:0]MODE2[1:0]MODE1[1:0]MODE0[1:0]
Reset value------------11111111111010111111
0x00GPIOC_MODERMODE15[1:0]MODE14[1:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value1111----------------------------
0x00GPIOE_MODERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MODE4[1:0]Res.Res.Res.Res.Res.Res.Res.Res.
Reset value----------------------11--------
0x00GPIOH_MODERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MODE3[1:0]Res.Res.Res.Res.Res.Res.
Reset value------------------------11------
0x04GPIOA_OTYPERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OT15OT14OT13OT12OT11OT10OT9OT8OT7OT6OT5OT4OT3OT2OT1OT0
Reset value----------------0000000000000000
0x04GPIOB_OTYPERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OT9OT8OT7OT6OT5OT4OT3OT2OT1OT0
Reset value----------------------0000000000
0x04GPIOC_OTYPERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OT15OT14Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value----------------00--------------
0x04GPIOE_OTYPERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OT4Res.Res.Res.Res.
Reset value---------------------------0----
0x04GPIOH_OTYPERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OT3Res.Res.Res.
Reset value----------------------------0---

Table 39. GPIO register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x08GPIOA_OSPEEDROSPEED15[1:0]OSPEED14[1:0]OSPEED13[1:0]OSPEED12[1:0]OSPEED11[1:0]OSPEED10[1:0]OSPEED9[1:0]OSPEED8[1:0]OSPEED7[1:0]OSPEED6[1:0]OSPEED5[1:0]OSPEED4[1:0]OSPEED3[1:0]OSPEED2[1:0]OSPEED1[1:0]OSPEED0[1:0]
Reset value00001100000000000000000000000000
0x08GPIOB_OSPEEDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OSPEED9[1:0]OSPEED8[1:0]OSPEED7[1:0]OSPEED6[1:0]OSPEED5[1:0]OSPEED4[1:0]OSPEED3[1:0]OSPEED2[1:0]OSPEED1[1:0]OSPEED0[1:0]
Reset value------------00000000000011000000
0x08GPIOC_OSPEEDROSPEED15[1:0]OSPEED14[1:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value0000----------------------------
0x08GPIOE_OSPEEDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OSPEED4[1:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value---------------------00--------
0x08GPIOH_OSPEEDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OSPEED3[1:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value--------------------00----------
0x0CGPIOA_PUPDRPUPD15[1:0]PUPD14[1:0]PUPD13[1:0]PUPD12[1:0]PUPD11[1:0]PUPD10[1:0]PUPD9[1:0]PUPD8[1:0]PUPD7[1:0]PUPD6[1:0]PUPD5[1:0]PUPD4[1:0]PUPD3[1:0]PUPD2[1:0]PUPD1[1:0]PUPD0[1:0]
Reset value01100100000000000000000000000000
0x0CGPIOB_PUPDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PUPD9[1:0]PUPD8[1:0]PUPD7[1:0]PUPD6[1:0]PUPD5[1:0]PUPD4[1:0]PUPD3[1:0]PUPD2[1:0]PUPD1[1:0]PUPD0[1:0]
Reset value------------0000000000010000000
0x0CGPIOx_PUPDR
(where x = C, D)
PUPD15[1:0]PUPD14[1:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value0000----------------------------
0x0CGPIOE_PUPDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PUPD4[1:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value---------------------00--------
0x0CGPIOH_PUPDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PUPD3[1:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value---------------------00--------

Table 39. GPIO register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x10GPIOA_IDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ID15ID14ID13ID12ID11ID10ID9ID8ID7ID6ID5ID4ID3ID2ID1ID0
Reset valuexxxxxxxxxxxxxxxx
0x10GPIOB_IDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ID9ID8ID7ID6ID5ID4ID3ID2ID1ID0
Reset valuexxxxxxxxxx
0x10GPIOC_IDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ID15ID14Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset valuexx
0x10GPIOE_IDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ID4Res.Res.Res.Res.
Reset value---------------------------x----
0x10GPIOH_IDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ID3Res.Res.Res.
Reset value----------------------------x---
0x14GPIOA_ODRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OD15OD14OD13OD12OD11OD10OD9OD8OD7OD6OD5OD4OD3OD2OD1OD0
Reset value0000000000000000
0x14GPIOB_ODRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OD9OD8OD7OD6OD5OD4OD3OD2OD1OD0
Reset value0000000000
0x14GPIOC_ODRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OD15OD14Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value00
0x14GPIOE_ODRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OD4Res.Res.Res.Res.
Reset value---------------------------0----
0x14GPIOH_ODRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OD3Res.Res.
Reset value----------------------------0---
0x18GPIOA_BSRRBR15BR14BR13BR12BR11BR10BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0BS15BS14BS13BS12BS11BS10BS9BS8BS7BS6BS5BS4BS3BS2BS1BS0
Reset value00000000000000000000000000000000
0x18GPIOB_BSRRRes.Res.Res.Res.Res.Res.BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0Res.Res.Res.Res.Res.Res.BS9BS8BS7BS6BS5BS4BS3BS2BS1BS0
Reset value------0000000000------0000000000
0x18GPIOC_BSRRBR15BR14Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BS15BS14Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
Reset value00--------------00--------------
0x18GPIOE_BSRRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BR4Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BS4Res.Res.Res.
Reset value-----------0----------------0---
0x18GPIOH_BSRRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BR3Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.BS3Res.Res.
Reset value------------0----------------0--
0x1CGPIOA_LCKRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.LCKKLCK15LCK14LCK13LCK12LCK11LCK10LCK9LCK8LCK7LCK6LCK5LCK4LCK3LCK2LCK1LCK0
Reset value00000000000000000
0x1CGPIOB_LCKRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.LCKKRes.Res.Res.Res.Res.Res.LCK9LCK8LCK7LCK6LCK5LCK4LCK3LCK2LCK1LCK0
Reset value00000000000

Table 39. GPIO register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x1CGPIOC_LCKRResResResResResResResResResResResResResResResLCKKLCK15LCK14ResResResResResResResResResResResResResRes
Reset value000
0x1CGPIOE_LCKRResResResResResResResResResResResResResResResLCKKResResResResResResResResResResResResLCK4ResResRes
Reset value---------------0------------0---
0x1CGPIOH_LCKRResResResResResResResResResResResResResResResLCKKResResResResResResResResResResResResResLCK3ResRes
Reset value---------------0-------------0--
0x20GPIOx_AFRL
(where x = A,B)
AFSEL7[3:0]AFSEL6[3:0]AFSEL5[3:0]AFSEL4[3:0]AFSEL3[3:0]AFSEL2[3:0]AFSEL1[3:0]AFSEL0[3:0]
Reset value00000000000000000000000000000000
0x20GPIOE_AFRLResResResResResResResResResResResResResResResAFSEL4[3:0]ResResResResResResResResResResResResResResResRes
Reset value---------------0----------------
0x20GPIOH_AFRLResResResResResResResResResResResResResResResResResResResAFSEL3[3:0]ResResResResResResResResResResResRes
Reset value-------------------0000--------
0x24GPIOA_AFRHAFSEL15[3:0]AFSEL14[3:0]AFSEL13[3:0]AFSEL12[3:0]AFSEL11[3:0]AFSEL10[3:0]AFSEL9[3:0]AFSEL8[3:0]
Reset value00000000000000000000000000000000
0x24GPIOB_AFRHResResResResResResResResResResResResResResResResResResResResResResResResResResAFSEL9[3:0]AFSEL8[3:0]ResResResRes
Reset value000000
0x24GPIOC_AFRHAFSEL15[3:0]AFSEL14[3:0]ResResResResResResResResResResResResResResResResResResResResResResResResResResResResResRes
Reset value00000000
0x28GPIOA_BRRResResResResResResResResResResResResResResResResBR15BR14BR13BR12BR11BR10BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0
Reset value000000000000000
0x28GPIOB_BRRResResResResResResResResResResResResResResResResResResResResResResBR9BR8BR7BR6BR5BR4BR3BR2BR1BR0
Reset value0000000000
0x28GPIOC_BRRResResResResResResResResResResResResResResResResBR15BR14ResResResResResResResResResResResResResRes
Reset value00
0x28GPIOE_BRRResResResResResResResResResResResResResResResResResResResResResResResResResResResResBR4ResResRes
Reset value0
0x28GPIOH_BRRResResResResResResResResResResResResResResResResResResResResResResResResResResResResBR3ResResRes
Reset value0
Refer to Section 2.2 on page 56 for the register boundary addresses.