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 and GPIOx_BRR registers 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 16 shows the basic structures of a standard I/O port bit. Table 38 gives the possible port bit configurations.

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

Figure 16: Basic structure of an I/O port bit. This block diagram illustrates the internal architecture of a GPIO pin. On the left, external connections include 'To/from on-chip peripherals, power control and EXTI' for 'Analog input/output' and 'Digital input'. The 'Digital input' path goes through an 'Input driver' containing a 'TTL Schmitt trigger' with 'On/off' control, connected to an 'Input data register'. The 'Input data register' is linked to 'Bit set/reset registers' (Write) and a 'Read' path. The 'Output driver' consists of 'Output control' logic connected to 'P-MOS' and 'N-MOS' transistors, labeled 'Push-pull, open-drain or disabled'. It is connected to 'Output data register' (Read/write) and 'Alternate function output' from on-chip peripherals. The output stage connects to the 'I/O pin' through 'Pull up' and 'Pull down' resistors with 'on/off' switches, connected to VDDIOx and VSS respectively. The diagram is labeled MSV33182V2.
Figure 16: Basic structure of an I/O port bit. This block diagram illustrates the internal architecture of a GPIO pin. On the left, external connections include 'To/from on-chip peripherals, power control and EXTI' for 'Analog input/output' and 'Digital input'. The 'Digital input' path goes through an 'Input driver' containing a 'TTL Schmitt trigger' with 'On/off' control, connected to an 'Input data register'. The 'Input data register' is linked to 'Bit set/reset registers' (Write) and a 'Read' path. The 'Output driver' consists of 'Output control' logic connected to 'P-MOS' and 'N-MOS' transistors, labeled 'Push-pull, open-drain or disabled'. It is connected to 'Output data register' (Read/write) and 'Alternate function output' from on-chip peripherals. The output stage connects to the 'I/O pin' through 'Pull up' and 'Pull down' resistors with 'on/off' switches, connected to VDDIOx and VSS respectively. The diagram is labeled MSV33182V2.

Table 38. Port bit configuration table (1)

MODE(i)
[1:0]
OTYPE(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
Table 38. Port bit configuration table (1) (continued)
MODE(i)
[1:0]
OTYPE(i)OSPEED(i)
[1:0]
PUPD(i)
[1:0]
I/O configuration
0101
00xxx00InputFloating
xxx01InputPU
xxx10InputPD
xxx11Reserved (input floating)
11xxx00Input/outputAnalog
xxx01Reserved
xxx10
xxx11

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:

Note: PA14 is shared with BOOT0 functionality. Caution is required as the debugging device can manipulate BOOT0 pin value.

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.

The GPIO pins can operate as:

The GPIOs with debug alternate functions are set to Alternate function mode upon reset.

Available for some GPIO pins, the Additional function mode is set through the control registers of the corresponding functional block such as ADC, DAC, RTC, RCC, and PWR, regardless of the GPIOx_MODER register setting.

When an I/O is set in Additional function mode, it is recommended to set its corresponding GPIO multiplexer in the GPIOx_MODER register to Analog mode.

8.3.2 I/O pin alternate function multiplexer and mapping

Each functional block signal to connect on the device pins as alternate function is internally routed towards multiple GPIO pins. Each GPIO pin has a multiplexer with 16 positions (AF0 to AF15) controlled through the GPIOx_AFRH and GPIOx_AFRH registers, to select one of up to 16 alternate functions at a time. The alternate function selected for a GPIO pin is physically connected to the pin through GPIO mode multiplexer controlled by the GPIOx_MODER register.

Upon reset, the alternate function multiplexer on each GPIO is set to AF0 position.

This flexibility eases PCB routing and allows configuring small pin-count devices to match the application requirements.

The mapping of alternate function signals to GPIO alternate function multiplexers is detailed in the device datasheet.

To use an I/O in a given configuration, proceed as detailed in the following subsections.

Debug function

After each device reset, these pins are assigned as alternate function pins.

GPIO

Configure the desired I/O as output, input, or as an analog port, through the GPIOx_MODER register.

Peripheral alternate function

Cortex ® -M0+ alternate function (EVENTOUT)

The Cortex ® -M0+ output EVENTOUT signal can be used by configuring the I/O pin to output at the dedicated AF. An event can be signaled through the configured pin after executing the SEV instruction.

Additional functions

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.5.5: GPIO port input data register (GPIOx_IDR) (x = A, B, C, D, F) and Section 8.5.6: GPIO port output data register (GPIOx_ODR) (x = A, B, C, D, F) 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.5.8: GPIO port configuration lock register (GPIOx_LCKR) ( \( x = A, B, C, D, F \) )) 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.5.8: GPIO port configuration lock register (GPIOx_LCKR) ( \( x = A, B, C, D, F \) ).

8.3.7 I/O alternate function input/output

When an I/O pin operates in Alternate function mode, the alternate function selected determines whether it acts as an input or as an output.

The pull-up/pull-down and output speed settings (via the GPIOx_OTYPER, GPIOx_PUPDR and GPIOx_OSPEEDER registers, respectively) remain effective.

8.3.8 External interrupt/wake-up lines

All ports have external interrupt capability. To use external interrupt lines, the given pin must not be configured in analog mode or being used as oscillator pin, so the input trigger is kept enabled.

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

8.3.9 Input configuration

When the I/O port is programmed as input:

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

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

Figure 17: Input floating/pull up/pull down configurations. This block diagram illustrates the internal architecture of a GPIO input. On the left, a 'To / from on-chip peripherals, power control and EXTI' block is connected to an 'Analog input/output' block. Below this, a 'Read' path goes from the 'Input data register' to the CPU. A 'Write' path goes from the CPU to 'Bit set/reset registers', which in turn write to the 'Output data register'. A 'Read/write' path goes from the CPU 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' (containing an N-MOS) and an 'Input driver' (containing a P-MOS). The 'I/O pin' is connected to the 'TTL Schmitt trigger', the 'Output driver', and a 'Pull up' resistor (connected to VDDIOx) and a 'Pull down' resistor (connected to VSS). The 'Pull up' and 'Pull down' resistors are controlled by 'on/off' switches. The diagram is labeled MSv33183V2.
Figure 17: Input floating/pull up/pull down configurations. This block diagram illustrates the internal architecture of a GPIO input. On the left, a 'To / from on-chip peripherals, power control and EXTI' block is connected to an 'Analog input/output' block. Below this, a 'Read' path goes from the 'Input data register' to the CPU. A 'Write' path goes from the CPU to 'Bit set/reset registers', which in turn write to the 'Output data register'. A 'Read/write' path goes from the CPU 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' (containing an N-MOS) and an 'Input driver' (containing a P-MOS). The 'I/O pin' is connected to the 'TTL Schmitt trigger', the 'Output driver', and a 'Pull up' resistor (connected to VDDIOx) and a 'Pull down' resistor (connected to VSS). The 'Pull up' and 'Pull down' resistors are controlled by 'on/off' switches. The diagram is labeled MSv33183V2.

8.3.10 Output configuration

When the I/O port is programmed as output:

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

Figure 18. Output configuration

Figure 18. Output configuration diagram showing the internal architecture of a GPIO pin in output mode. The diagram includes an input driver with a TTL Schmitt trigger, an output driver with P-MOS and N-MOS transistors, and pull-up/pull-down resistors. It shows connections to registers (Input data register, Bit set/reset registers, Output data register) and external components like on-chip peripherals and an I/O pin.

The diagram illustrates the internal circuitry of a GPIO pin configured for output. On the left, external connections include 'To / from on-chip peripherals, power control and EXTI' and 'Analog input/output'. The 'Input data register' is connected to the input driver, which contains a 'TTL Schmitt trigger' labeled 'On'. The 'Bit set/reset registers' and 'Output data register' are shown with 'Write' and 'Read/write' access paths. The 'Output data register' feeds into the 'Output control' block within the 'Output driver' section. This block drives a pair of transistors: a 'P-MOS' connected to \( V_{DDIOx} \) and an 'N-MOS' connected to \( V_{SS} \) . These transistors are labeled 'Push-pull or open-drain'. The output of the transistors is connected to the 'I/O pin'. Additionally, there are 'Pull up' and 'Pull down' resistors connected to the I/O pin, with 'on/off' switches, connected to \( V_{DDIOx} \) and \( V_{SS} \) respectively. The diagram is labeled 'MSv33184V3' in the bottom right corner.

Figure 18. Output configuration diagram showing the internal architecture of a GPIO pin in output mode. The diagram includes an input driver with a TTL Schmitt trigger, an output driver with P-MOS and N-MOS transistors, and pull-up/pull-down resistors. It shows connections to registers (Input data register, Bit set/reset registers, Output data register) and external components like on-chip peripherals and an I/O pin.

8.3.11 Alternate function configuration

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

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

Figure 19. Alternate function configuration-

Figure 19: Alternate function configuration diagram. This schematic shows the internal architecture of a GPIO pin in alternate function mode. On the left, an 'On-chip peripheral' is connected to 'Analog input/output' and 'Alternate function input' lines. The 'Alternate function input' connects to an 'Input data register', which is read by the CPU. The 'Analog input/output' line connects to the 'I/O pin'. The 'I/O pin' is connected to an 'Input driver' containing a 'TTL Schmitt trigger' (labeled 'On'). The 'I/O pin' also connects to an 'Output driver' containing an 'Output control' block, a 'P-MOS' transistor connected to VDDIOX, and an 'N-MOS' transistor connected to VSS. This output driver is configured for 'Push-pull or open-drain' operation. The 'Output control' block is connected to an 'Output data register', which is read/written by the CPU. The 'Output data register' is also connected to 'Bit set/reset registers', which are written by the CPU. The 'I/O pin' is also connected to 'Pull up' (connected to VDDIOX) and 'Pull down' (connected to VSS) resistors, both of which are 'on/off'. The diagram is labeled MSv31479V2.
Figure 19: Alternate function configuration diagram. This schematic shows the internal architecture of a GPIO pin in alternate function mode. On the left, an 'On-chip peripheral' is connected to 'Analog input/output' and 'Alternate function input' lines. The 'Alternate function input' connects to an 'Input data register', which is read by the CPU. The 'Analog input/output' line connects to the 'I/O pin'. The 'I/O pin' is connected to an 'Input driver' containing a 'TTL Schmitt trigger' (labeled 'On'). The 'I/O pin' also connects to an 'Output driver' containing an 'Output control' block, a 'P-MOS' transistor connected to VDDIOX, and an 'N-MOS' transistor connected to VSS. This output driver is configured for 'Push-pull or open-drain' operation. The 'Output control' block is connected to an 'Output data register', which is read/written by the CPU. The 'Output data register' is also connected to 'Bit set/reset registers', which are written by the CPU. The 'I/O pin' is also connected to 'Pull up' (connected to VDDIOX) and 'Pull down' (connected to VSS) resistors, both of which are 'on/off'. The diagram is labeled MSv31479V2.

8.3.12 Analog configuration

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

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

Figure 20. High impedance-analog configuration

Figure 20: High impedance-analog configuration diagram. This schematic shows the internal architecture of a GPIO pin in high-impedance analog mode. On the left, an 'On-chip peripheral' is connected to 'Analog input/output'. The 'Analog input/output' line connects to the 'I/O pin'. The 'I/O pin' is connected to an 'Input driver' containing a 'TTL Schmitt trigger' (labeled 'Off' and '0'). The 'I/O pin' also connects to an 'Output driver' containing an 'Output control' block and a switch that is open in this configuration. The 'Output control' block is connected to an 'Output data register', which is read/written by the CPU. The 'Output data register' is also connected to 'Bit set/reset registers', which are written by the CPU. The 'I/O pin' is also connected to 'Pull up' (connected to VDDIOX) and 'Pull down' (connected to VSS) resistors, both of which are 'on/off'. The diagram is labeled MSv33185V2.
Figure 20: High impedance-analog configuration diagram. This schematic shows the internal architecture of a GPIO pin in high-impedance analog mode. On the left, an 'On-chip peripheral' is connected to 'Analog input/output'. The 'Analog input/output' line connects to the 'I/O pin'. The 'I/O pin' is connected to an 'Input driver' containing a 'TTL Schmitt trigger' (labeled 'Off' and '0'). The 'I/O pin' also connects to an 'Output driver' containing an 'Output control' block and a switch that is open in this configuration. The 'Output control' block is connected to an 'Output data register', which is read/written by the CPU. The 'Output data register' is also connected to 'Bit set/reset registers', which are written by the CPU. The 'I/O pin' is also connected to 'Pull up' (connected to VDDIOX) and 'Pull down' (connected to VSS) resistors, both of which are 'on/off'. The diagram is labeled MSv33185V2.

8.3.13 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 GPIOs.

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

When HSE or LSE oscillator is bypassed, its input pin is used as external clock input and its output pin is free for use as GPIO.

For the devices housed in 48-pin packages, the HSE and LSE oscillators have separate input and output pins (see HSE_NOT_REMAPPED bit of the FLASH option bytes). On packages with less than 48 pins, HSE and LSE oscillators have one common input pin OSCX_IN and one common output pin OSCX_OUT, which restricts their use to one at a time (the other must be disabled).

8.3.14 Low pin count package adjustment

Due to the restriction of some low pin count packages, multiple GPIOs are connected to the same I/O pins. The SYSCFG_CFGR3 register allows selecting which of them is active, to prevent conflicts.

8.3.15 Reset pin (PF2-NRST) in GPIO mode

The PF2-NRST pin can be configured as reset I/O or as a GPIO.

To configure PF2-NRST as a GPIO (input, output, AF, or analog I/O), set the NRST_MODE bitfield to GPIO mode in the FLASH option bytes. The new setting only takes effect upon the option byte loading (OBL) event following a reset. Until the reset release, PF2-NRST keeps acting as reset I/O.

The user must ensure that, upon power-on, the level on the NRST pin can exceed the minimum \( V_{IH(NRST)} \) level specified in the device datasheet. Otherwise, the device does not exit the power-on reset. This applies to any NRST configuration set through the NRST_MODE[1:0] bitfield, the GPIO mode inclusive.

When PF2-NRST acts as a GPIO, reset can only be triggered from one of the device internal reset sources and the reset signal cannot be output.

For further information on reset function, refer to the RCC section.

8.4 GPIO in low-power modes

Table 39. Effect of low-power modes on the GPIO

ModeDescription
SleepNo effect. GPIO (EXTI) interrupts cause the device to exit Sleep mode.
StopNo effect. GPIO (EXTI) interrupts cause the device to exit Stop mode.

Table 39. Effect of low-power modes on the GPIO (continued)

ModeDescription
Standby

The GPIO digital interface is powered down and must be reinitialized after exiting Standby mode. Wake-up pins can be configured to cause the device to exit Standby mode.

GPIO's are set to analog mode by hardware. Pull-up or pull-down device can individually be enabled through the PWR_PUCRx and PWR_PDCRx registers, respectively, to keep the I/Os at defined levels.

Shutdown

The GPIO digital interface is powered down and must be reinitialized after exiting Shutdown mode. Wake-up pins can be configured to cause the device to exit Shutdown mode.

The GPIO's are set to analog mode by hardware. Pull-up or pull-down device can individually be enabled through the PWR_PUCRx and PWR_PDCRx registers, respectively, to keep the I/Os at defined levels.

8.5 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 40 .

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

Port D is only available on STM32C03xx products.

8.5.1 GPIO port mode register (GPIOx_MODER)
(x =A, B, C, D, F)

Address offset:0x00

Reset value: 0xEBFF FFFF (port A)

Reset value: 0xFFFF FFFF (ports other than A)

31302928272625242322212019181716
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
1514131211109876543210
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 MODEy[1:0] : Port x configuration for I/O y (y = 15 to 0)

These bits are written by software to set the I/O to one of four operating modes.

00: Input

01: Output

10: Alternate function

11: Analog

8.5.2 GPIO port output type register (GPIOx_OTYPER)
(x = A, B, C, D, F)

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
OT15OT14OT13OT12OT11OT10OT9OT8OT7OT6OT5OT4OT3OT2OT1OT0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

Bits 15:0 OTy : Port x configuration for I/O 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

8.5.3 GPIO port output speed register (GPIOx_OSPEEDR)
(x = A, B, C, D, F)

Address offset: 0x08

Reset value: 0x0C00 0000 (for port A)

Reset value: 0x0000 0000 (ports other than A)

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 OSPEEDy[1:0] : Port x configuration for I/O y (y = 15 to 0)

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

00: Very low speed

01: Low speed

10: High speed

11: Very high speed

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

The FT_c GPIOs cannot be set to high speed.

8.5.4 GPIO port pull-up/pull-down register (GPIOx_PUPDR)
(x = A, B, C, D, F)

Address offset: 0x0C

Reset value: 0x2400 0000 (for port A)

Reset value: 0x0000 0000 (ports other than A)

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 PUPDy[1:0] : Port x configuration I/O 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

Note: On the same pin, this pull up/down must not be activated when a pull down/up is set through the PWR_PDCRx/PWR_PUCRx registers.

8.5.5 GPIO port input data register (GPIOx_IDR)
(x = A, B, C, D, F)

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
ID15ID14ID13ID12ID11ID10ID9ID8ID7ID6ID5ID4ID3ID2ID1ID0
rrrrrrrrrrrrrrrr

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

Bits 15:0 IDy : Port x input data I/O y (y = 15 to 0)

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

8.5.6 GPIO port output data register (GPIOx_ODR)
(x = A, B, C, D, F)

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
OD15OD14OD13OD12OD11OD10OD9OD8OD7OD6OD5OD4OD3OD2OD1OD0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

Bits 15:0 ODy : Port output data I/O 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, B, C, D, F).

8.5.7 GPIO port bit set/reset register (GPIOx_BSR)
(x = A, B, C, D, F)

Address offset: 0x18

Reset value: 0x0000 0000

31302928272625242322212019181716
BR15BR14BR13BR12BR11BR10BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0
wwwwwwwwwwwwwwww
1514131211109876543210
BS15BS14BS13BS12BS11BS10BS9BS8BS7BS6BS5BS4BS3BS2BS1BS0
wwwwwwwwwwwwwwww

Bits 31:16 BRy : Port x reset I/O y (y = 15 to 0)

These bits are write-only. A read operation always returns 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 BSy : Port x set I/O y (y = 15 to 0)

These bits are write-only. A read operation always returns 0x0000.

0: No action on the corresponding ODRx bit

1: Sets the corresponding ODRx bit

8.5.8 GPIO port configuration lock register (GPIOx_LCKR)
(x = A, B, C, D, F)

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

8.5.9 GPIO alternate function low register (GPIOx_AFRL)
(x = A, B, C, D, F)

Address offset: 0x20

Reset value: 0x0000 0000

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 y [3:0] : Alternate function selection for port x 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.5.10 GPIO alternate function high register (GPIOx_AFRH)
(x = A, B, C, D, F)

Address offset: 0x24

Reset value: 0x0000 0000

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 y [3:0] : Alternate function selection for port x, I/O 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.5.11 GPIO port bit reset register (GPIOx_BRR) (x = A, B, C, D, F)

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 BRy : Port x reset I/O y (y = 15 to 0)

These bits are write-only. A read operation always returns 0x0000.

0: No action on the corresponding ODx bit

1: Reset the corresponding ODx bit

8.5.12 GPIO register map

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

Table 40. GPIO register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00GPIOx_MODER
(x = A, B, C, D, F)
MODE15[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 value (port A)11101011111111111111111111111111
Reset value (ports other than A)11111111111111111111111111111111
0x04GPIOx_OTYPER
(x = A, B, C, D, F)
ResResResResResResResResResResResResResResResResOT15OT14OT13OT12OT11OT10OT9OT8OT7OT6OT5OT4OT3OT2OT1OT0
Reset value0000000000000000
0x08GPIOx_OSPEEDR
(x = A, B, C, D, F)
OSPEED15[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 value (port A)00001100000000000000000000000000
Reset value (ports other than A)00000000000000000000000000000000
0x0CGPIOx_PUPDR
(x = A, B, C, D, F)
PUPD15[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 value (port A)00100100000000000000000000000000
Reset value (ports other than A)00000000000000000000000000000000
0x10GPIOx_IDR
(x = A, B, C, D, F)
ResResResResResResResResResResResResResResResResID15ID14ID13ID12ID11ID10ID9ID8ID7ID6ID5ID4ID3ID2ID1ID0
Reset valuexxxxxxxxxxxxxxxx
0x14GPIOx_ODR
(x = A, B, C, D, F)
ResResResResResResResResResResResResResResResResOD15OD14OD13OD12OD11OD10OD9OD8OD7OD6OD5OD4OD3OD2OD1OD0
Reset value0000000000000000
0x18GPIOx_BSRR
(x = A, B, C, D, F)
BR15BR14BR13BR12BR11BR10BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0BS15BS14BS13BS12BS11BS10BS9BS8BS7BS6BS5BS4BS3BS2BS1BS0
Reset value00000000000000000000000000000000
0x1CGPIOx_LCKR
(x = A, B, C, D, F)
ResResResResResResResResResResResResResResResResLCKKLCK15LCK14LCK13LCK12LCK11LCK10LCK9LCK8LCK7LCK6LCK5LCK4LCK3LCK2LCK1LCK0
Reset value0000000000000000
0x20GPIOx_AFRL
(x = A, B, C, D, F)
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
0x24GPIOx_AFRH
(x = A, B, C, D, F)
AFSEL15 [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
0x28GPIOx_BRR
(x = A, B, C, D, F)
ResResResResResResResResResResResResResResResResBR15BR14BR13BR12BR11BR10BR9BR8BR7BR6BR5BR4BR3BR2BR1BR0
Reset value0000000000000000

Refer to Section 2.2 on page 45 for the register boundary addresses.