7. General-purpose I/Os (GPIO)

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

7.2 GPIO main features

7.3 GPIO functional description

Subject to the specific hardware characteristics of each I/O port listed in the Section 4: I/O operating modes, 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.

Note: Open-drain and analog features are not available on all the I/Os of the STM32WL3Rxx. Refer to Table 8: GPIO alternate options AF0 - AF3 and Table 9: GPIO alternate options AF4 - AF6 footnotes.

Figure 16 and Figure 17 show the basic structures of a mixed analog/digital 5V tolerant I/O port bit and a digital only 5V tolerant, respectively. Table 18 gives the possible port bit configurations.

Figure 16. Basic structure of a mixed analog/digital five-volt tolerant I/O port bit

Block diagram of Figure 16: Basic structure of a mixed analog/digital five-volt tolerant I/O port bit. It depicts input and output paths connected to the I/O pin, including input driver (with TTL Schmitt trigger, on/off control, Input data register), output driver (with Bit set/reset registers, Output data register, Output control, P-MOS and N-MOS transistors for Push-pull, open-drain or disabled control), internal pull-up and pull-down resistors, protection diodes connected to VDD_FT and VSS, and direct analog input/output paths.
Block diagram of Figure 16: Basic structure of a mixed analog/digital five-volt tolerant I/O port bit. It depicts input and output paths connected to the I/O pin, including input driver (with TTL Schmitt trigger, on/off control, Input data register), output driver (with Bit set/reset registers, Output data register, Output control, P-MOS and N-MOS transistors for Push-pull, open-drain or disabled control), internal pull-up and pull-down resistors, protection diodes connected to VDD_FT and VSS, and direct analog input/output paths.

1. VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.

Figure 17. Basic structure of a digital only five-volt tolerant I/O port bit

Basic structure of a digital only five-volt tolerant I/O port bit
Basic structure of a digital only five-volt tolerant I/O port bit

1. VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.

Table 18. 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
Table 18. Port bit configuration table(1) (continued)
MODE(i)
[1:0]
OTYPER(i)OSPEED(i)
[1:0]
PUPD(i)
[1:0]
I/O configuration
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.

Note: Open-drain and analog features are not available on all the I/Os of the STM32WL3Rxx. Refer to Table 8: GPIO alternate options AF0 - AF3 and Table 9: GPIO alternate options AF4 - AF6 footnotes.

7.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 GPIO input pull-up mode except the SWD debug pins.

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

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.

7.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 seven alternate function inputs (AF0 to AF6) 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:

Note: The user has to disable the pulls by software on I/Os he configures in analog mode.

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

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

7.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 GPIOA port input data register (GPIOA_IDR) and GPIOA port output data register (GPIOA_ODR) for the register descriptions.

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

7.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 GPIOB port bit reset register (GPIOB_BSRR)) 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 GPIOB port bit reset register (GPIOB_BSRR).

7.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, you can connect an alternate function to some other pin as required by your 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 Section 4: I/O operating modes.

General-purpose I/Os (GPIO)

RM0551


7.3.8 External interrupt/wakeup lines

All ports have external interrupt capability. To use external interrupt lines, the IO port must be configured in input mode. The interruption configuration (level/edge, polarity, mask)has to be done in the system controller (SYSCFG). See Section 8: System controller (SYSCFG).

7.3.9 Input configuration

When the I/O port is programmed as input:

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

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

Schematic diagram of input floating/pull up/pull down configurations showing internal registers, drivers, and external pin protection.

The diagram illustrates the internal and external components of an I/O pin configuration. On the left, control signals include 'Read' (output), 'Write' (input), and 'Read/write' (bidirectional). The 'Write' signal controls a 'Bit set/reset registers' block, which in turn controls an 'Output data register'. The 'Read/write' signal also controls the 'Output data register'. The 'Output data register' connects to an 'output driver' (represented by a switch) and an 'Input data register'. The 'Input data register' connects to a 'TTL Schmitt trigger' (represented by a triangle with a hysteresis symbol and an 'on' control input). The 'TTL Schmitt trigger' output connects to the 'input driver' (represented by a dashed box). The 'input driver' and 'output driver' are enclosed in a dashed box. The external 'I/O pin' is connected to a node that branches into two paths: one through an 'on/off' switch to a 'pull up' resistor connected to \(V_{DDIOx}\), and another through an 'on/off' switch to a 'pull down' resistor connected to \(V_{SS}\). Each path includes a 'protection diode' connected to \(V_{DDIOx}\) and \(V_{SS}\) respectively.

Schematic diagram of input floating/pull up/pull down configurations showing internal registers, drivers, and external pin protection.

MS31477V1

158/989

RM0551 Rev 3

ST logo

The ST logo, consisting of the letters 'S' and 'T' in a stylized, italicized font, is positioned in the bottom right corner of the page.

ST logo

7.3.10 Output configuration

When the I/O port is programmed as output:

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

Figure 19. Output configuration

Figure 19. Output configuration

Block diagram showing the Output configuration for an I/O pin. Key components include Read/Write paths, Input data register, Output data register, Bit set/reset registers, Input driver (TTL Schmitt trigger), Output driver (Output control, P-MOS, N-MOS configured as Push-pull or Open-drain), on/off controlled pull up and pull down resistors, protection diodes connected to VDDIOx and VSS, and the I/O pin.

Figure 19. Output configuration

7.3.11 Alternate function configuration

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

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

Figure 20. Alternate function configuration

Block diagram of alternate function configuration showing input and output drivers, registers, and protection diodes.

This block diagram illustrates the alternate function configuration of a GPIO pin. It is divided into an input driver and an output driver. The input driver includes an input data register connected to a TTL Schmitt trigger, which is enabled ('on'). The output driver includes an output data register connected to an output control block that drives P-MOS and N-MOS transistors in a push-pull or open-drain configuration. Both drivers are connected to an I/O pin that features pull-up and pull-down resistors (controlled by 'on/off' signals) and protection diodes connected to VDDIOx and VSS. Data flows between on-chip peripherals and the registers via 'Read' and 'Write' signals.

Block diagram of alternate function configuration showing input and output drivers, registers, and protection diodes.

7.3.12 Analog configuration

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

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

Figure 21. High impedance-analog configuration

Block diagram of high impedance-analog configuration showing disabled input driver and protection diodes.

This block diagram shows the high-impedance analog configuration. The input driver's TTL Schmitt trigger is disabled ('off') and forced to a constant value of '0'. The output driver's P-MOS and N-MOS transistors are shown as open switches, disabling the output buffer. The I/O pin remains connected to protection diodes and pull-up/pull-down resistors. The input data register still receives a 'Read' signal from the peripheral, but the analog signal is not processed by the Schmitt trigger.

Block diagram of high impedance-analog configuration showing disabled input driver and protection diodes.

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

Caution: There is no hardware mechanism to isolate software configuration automatically for the I/Os shared with OSC32_IN (PB13) and OSC32_OUT (PB12) when the external low speed oscillator (LSE) is used. The user has to take care to program the concerned I/O as input floating.

Note: The high speed oscillator (HSE) OSC_IN and OSC_OUT pins are dedicated oscillator pins and can not be used as GPIO.

7.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 Section 7.5: GPIO register map.

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

7.4.1 GPIOA port mode register (GPIOA_MODER)

Address offset:0x00

Reset values:0x0000 00A0

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.MODE11[1:0]MODE10[1:0]MODE9[1:0]MODE8[1:0]
rwrwrwrwrwrwrwrw
1514131211109876543210
MODE7[1:0]Res.Res.Res.Res.Res.Res.MODE3[1:0]MODE2[1:0]MODE1[1:0]MODE0[1:0]
rwrwrwrwrwrwrwrwrwrw

Bits 2y+1:2y MODEy[1:0]: Port A configuration bits (y = 0..15)

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

Note: when configuring a pad in Analog mode, the user must take care to disable the associated pull-up/down to avoid pollution on the analog signal.

ST logo
ST logo

7.4.2 GPIOB port mode register (GPIOB_MODER)

Address offset:0x00

Reset values:0x0000 0000

31302928272625242322212019181716
MODE15[1:0]MODE14[1:0]MODE13[1:0]MODE12[1:0]Res.Res.Res.Res.Res.Res.Res.Res.
rwrwrwrwrwrwrwrw
1514131211109876543210
MODE7[1:0]MODE6[1:0]Res.Res.Res.Res.Res.Res.MODE2[1:0]MODE1[1:0]MODE0[1:0]
rwrwrwrwrwrwrwrwrwrw

Bits 2y+1:2y MODEy[1:0]: Port B configuration bits (y = 0..15)

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

00: Input mode

01: output mode

10: Alternate function mode

11: Analog mode

Note: when configuring a pad in Analog mode, the user must take care to disable the associated pull-up/down to avoid pollution on the analog signal.

7.4.3 GPIOA port output type register (GPIOA_OTYPER)

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
Res.Res.Res.Res.OT11OT10OT9OT8OT7Res.Res.Res.OT3OT2OT1OT0
rwrwrwrwrwrwrwrwrw

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

Bits 11:7 OTy: Port A configuration bits (y = 7..11)

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

0: Output push-pull (reset state)

1: Output open-drain

Bits 6:4 Reserved, must be kept at reset value.

Bits 3:0 OTy: Port A configuration bits (y = 0..3)

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

0: Output push-pull (reset state)

1: Output open-drain

7.4.4 GPIOB port output type register (GPIOB_OTYPER)

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
OT15OT14OT13OT12Res.Res.Res.Res.OT7OT6Res.Res.Res.OT2OT1OT0
rwrwrwrwrwrwrwrwrw
ST logo
ST logo

7.4.5 GPIOA port output speed register (GPIOA_OSPEEDR)

Address offset: 0x08

Reset value: 0x0000 0030

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.OSPEED11
[1:0]
OSPEED10
[1:0]
OSPEED9
[1:0]
OSPEED8
[1:0]
rwrwrwrwrwrwrwrw
1514131211109876543210
OSPEED7
[1:0]
Res.Res.Res.Res.Res.Res.OSPEED3
[1:0]
OSPEED2
[1:0]
OSPEED1
[1:0]
OSPEED0
[1:0]
rwrwrwrwrwrwrwrwrwrw

Bits 2y+1:2y OSPEEDy[1:0]: Port A configuration bits (y = 0..15)

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

7.4.6 GPIOB port output speed register (GPIOB_OSPEEDR)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
OSPEED15
[1:0]
OSPEED14
[1:0]
OSPEED13
[1:0]
OSPEED12
[1:0]
Res.Res.Res.Res.Res.Res.Res.Res.
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
OSPEED7
[1:0]
OSPEED6
[1:0]
Res.Res.Res.Res.Res.Res.OSPEED2
[1:0]
OSPEED1
[1:0]
OSPEED0
[1:0]
rwrwrwrwrwrwrwrwrwrw

Bits 2y+1:2y OSPEEDy[1:0]: Port B configuration bits (y = 0..15)

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

7.4.7 GPIOA port pull-up/pull-down register (GPIOA_PUPDR)

Address offset: 0x0C

Reset values: 0x5555 5595

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.PUPD11[1:0]PUPD10[1:0]PUPD9[1:0]PUPD8[1:0]
rwrwrwrwrwrwrwrw
1514131211109876543210
PUPD7[1:0]Res.Res.Res.Res.Res.Res.Res.PUPD3[1:0]PUPD2[1:0]PUPD1[1:0]PUPD0[1:0]
rwrwrwrwrwrwrwrwrwrw

Bits 2y+1:2y PUPDy[1:0]: Port A configuration bits (y = 0..15)

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

7.4.8 GPIOB port pull-up/pull-down register (GPIOB_PUPDR)

Address offset: 0x0C

Reset values: 0x5555 5555

31302928272625242322212019181716
PUPD15[1:0]PUPD14[1:0]PUPD13[1:0]PUPD12[1:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
rwrwrwrw
1514131211109876543210
PUPD7[1:0]PUPD6[1:0]Res.Res.Res.Res.Res.Res.Res.PUPD2[1:0]PUPD1[1:0]PUPD0[1:0]
rwrwrwrwrwrwrwrwrwrwrw

Bits 2y+1:2y PUPDy[1:0]: Port B configuration bits (y = 0..15)

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

7.4.9 GPIOA port input data register (GPIOA_IDR)

Address offset: 0x10

Reset value: 0x0000 XXXX (where X means undefined)

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.ID11ID10ID9ID8ID7Res.Res.Res.ID3ID2ID1ID0
rrrrrrrrr

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

Bits 11:7 IDy: Port Ainput data bit (y = 7..11)

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

Bits 6:4 Reserved, must be kept at reset value.

Bits 3:0 IDy: Port Ainput data bit (y = 0..3)

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

7.4.10 GPIOB port input data register (GPIOB_IDR)

Address offset: 0x10

Reset value: 0x0000 XXXX (where X means undefined)

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.ID11ID10ID9ID8ID7Res.Res.Res.Res.ID2ID1ID0
rrrrrrrr

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

Bits 15:12 IDy: Port B input data bit (y = 7..11)

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

Bits 6:3 Reserved, must be kept at reset value.

Bits 2:0 IDy: Port B input data bit (y = 0..2)

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

7.4.11 GPIOA port output data register (GPIOA_ODR)

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
Res.Res.Res.Res.OD11OD10OD9OD8OD7Res.Res.Res.OD3OD2OD1OD0
rwrwrwrwrwrwrwrwrw

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

Bits 11:7 ODy: Port A output data bit (y = 7..11)

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_BSRR or GPIOx_BRR registers (x = A, B)

Bits 6:4 Reserved, must be kept at reset value.

Bits 3:0 ODy: Port A output data bit (y = 0..3)

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_BSRR or GPIOx_BRR registers (x = A, B)

7.4.12 GPIOB port output data register (GPIOB_ODR)

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
Res.Res.Res.Res.OD11OD10OD9OD8OD7OD6Res.Res.Res.OD2OD1OD0
rwrwrwrwrwrwrwrwrw

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

Bits 11:6 ODy: Port B output data bit (y = 6..11)

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_BSRR or GPIOx_BRR registers (x = A, B)

Bits 5:3 Reserved, must be kept at reset value.

Bits 2:0 ODy: Port B output data bit (y = 0..2)

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_BSRR or GPIOx_BRR registers (x = A, B)

7.4.13 GPIOA port bit set/reset register (GPIOA_BSRR)

Address offset: 0x18

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.BR11BR10BR9BR8BR7Res.Res.Res.BR3BR2BR1BR0
wwwwwwwww
1514131211109876543210
Res.Res.Res.Res.BS11BS10BS9BS8BS7Res.Res.Res.BS3BS2BS1BS0
wwwwwwwww

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

Bits 27:23 BRy: Port A reset bit y (y = 7..11)

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 22:20 Reserved, must be kept at reset value.

Bits 19:6 BRy: Port A reset bit y (y= 0..3)

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

Bits 15:12 Reserved, must be kept at reset value.

Bits 11:7 BSy: Port A set bit y (y = 7..11)

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

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

Bits 6:4 Reserved, must be kept at reset value.

Bits 3:0 BSy: Port A set bit y (y= 0..3)

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

7.4.14 GPIOB port bit reset register (GPIOB_BSRR)

Address offset: 0x18

Reset value: 0x0000 0000

31302928272625242322212019181716
BR15BR14BR13BR12Res.Res.Res.Res.BR7BR6Res.Res.Res.BR2BR1BR0
wwwwwwwww
1514131211109876543210
BS15BS14BS13BS12Res.Res.Res.Res.BS7BS6Res.Res.Res.BS2BS1BS0
wwwwwwwww

Bits 31:28 BRy: Port B reset bit y (y = 12..15)

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 27:24 Reserved, must be kept at reset value.

Bits 23:22 BRy: Port B reset bit y (y = 6..7)

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 21:19 Reserved, must be kept at reset value.

Bits 18:16 BRy: Port B reset bit y (y = 12..15)

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:12 BSy: Port B set bit y (y= 12..15)

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

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

Bits 7:6 BSy: Port B set bit y (y= 0..1)

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

Bits 5:3 Reserved, must be kept at reset value.

Bits 2:0 BSy: Port B set bit y (y= 0..2)

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

7.4.15 GPIOA port configuration lock register (GPIOA_LCKR)

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
Res.Res.Res.Res.LCK11LCK10LCK9LCK8LCK7Res.Res.Res.LCK3LCK2LCK1LCK0
rwrwrwrwrwrwrwrwrw

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:12 Reserved, must be kept at reset value.

Bits 11:7 LCKy: Port A lock bit y (y= 7..11)

These bits are read/write but can only be written when the LCKK bit is '0, using the specific sequence described in LCKK bit description.

Bits 6:4 Reserved, must be kept at reset value.

Bits 3:0 LCKy: Port A lock bit y (y= 0..3)

These bits are read/write but can only be written when the LCKK bit is '0, using the specific sequence described in LCKK bit description.

7.4.16 GPIOB port configuration lock register (GPIOB_LCKR)

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
LCK15LCK14LCK13LCK12Res.Res.Res.Res.LCK7LCK6Res.Res.Res.LCK2LCK1LCK0
rwrwrwrwrwrwrwrwrw

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:12 LCKy: Port B lock bit y (y= 12..15)

These bits are read/write but can only be written when the LCKK bit is '0, using the specific sequence described in LCKK bit description.

0: Port configuration not locked

1: Port configuration locked

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

Bits 7:6 LCKy: Port B lock bit y (y= 6..7)

These bits are read/write but can only be written when the LCKK bit is '0, using the specific sequence described in LCKK bit description.

Bits 5:3 Reserved, must be kept at reset value.

Bits 2:0 LCKy: Port B lock bit y (y= 0..2)

These bits are read/write but can only be written when the LCKK bit is '0, using the specific sequence described in LCKK bit description.

7.4.17 GPIOA alternate function low register (GPIOA_AFRL)

Address offset: 0x20

Reset value: 0x0000 0000

31302928272625242322212019181716
AFSEL7[3:0]Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
rwrwrwrw
1514131211109876543210
AFSEL3[3:0]AFSEL2[3:0]AFSEL1[3:0]AFSEL0[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:28 y[3:0]: Alternate function selection for port A pin y (y = 7)
These bits are written by software to configure alternate function I/Os AFSELy selection:
0000: AF0
0001: AF1
0010: AF2
0011: AF3
0100: AF4
Other: Reserved

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

Bits 15:0 y[3:0]: Alternate function selection for port A pin y (y = 0..3)
These bits are written by software to configure alternate function I/Os AFSELy selection:
0000: AF0
0001: AF1
0010: AF2
0011: AF3
0100: AF4
Other: Reserved

ST logo
ST logo

7.4.18 GPIOB alternate function low register (GPIOB_AFRL)

Address offset: 0x20

Reset value: 0x0000 0000

31302928272625242322212019181716
AFSEL7[3:0]AFSEL6[3:0]Res.Res.Res.Res.Res.Res.Res.Res.
rwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.AFSEL2[3:0]AFSEL1[3:0]AFSEL0[3:0]
rwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:24 y[3:0]: Alternate function selection for port B pin y (y = 6..7)

These bits are written by software to configure alternate function I/Os AFSELy selection:

0000: AF0

0001: AF1

0010: AF2

0011: AF3

0100: AF4

Other: Reserved

Bits 23:12 Reserved, must be kept at reset value.

Bits 11:0 y[3:0]: Alternate function selection for port B pin y (y = 0..2)

These bits are written by software to configure alternate function I/Os AFSELy selection:

0000: AF0

0001: AF1

0010: AF2

0011: AF3

0100: AF4

Other: Reserved

7.4.19 GPIOA alternate function high register (GPIOA_AFRH)

Address offset: 0x24

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
AFSEL11[3:0]AFSEL10[3:0]AFSEL9[3:0]AFSEL8[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

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

Bits 15:0 y[3:0]: Alternate function selection for port A pin y (y = 8..11)

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

AFSELy selection:

0000: AF0

0001: AF1

0010: AF2

0011: AF3

0100: AF4

Other: Reserved

7.4.20 GPIOB alternate function high register (GPIOB_AFRH)

Address offset: 0x24

Reset value: 0x0000 0000

31302928272625242322212019181716
AFSEL15[3:0]AFSEL14[3:0]AFSEL13[3:0]AFSEL12[3:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.

Bits 31:16 y[3:0]: Alternate function selection for port B pin y (y = 12..15)

These bits are written by software to configure alternate function I/Os AFSELy selection:

0000: AF0

0001: AF1

0010: AF2

0011: AF3

0100: AF4

Other: Reserved

Bits 15:0 Reserved, must be kept at reset value.

7.4.21 GPIOA port bit reset register (GPIOA_BRR)

Address offset: 0x28

Reset value: 0x0000 0000

RM0551 7.4.21column_2column_3column_4column_5column_6column_7column_8column_9column_10column_11column_12column_13column_14column_15column_16
31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.BR11BR10BR9BR8BR7Res.Res.Res.BR3BR2BR1BR0
wwwwwwwww
Bits 11:7BRy:Port A reset bit y (y = 7..11)
Bits 3:0BRy:Port A reset bit y (y = 0..3)
RM0551 Rev 3179/ 989

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

Bits 11:7 BRy: Port A reset bit y (y = 7..11)

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

Bits 6:4 Reserved, must be kept at reset value.

Bits 3:0 BRy: Port A reset bit y (y = 0..3)

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

7.4.22 GPIOB port bit reset register (GPIOB_BRR)

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
BR15BR14BR13BR12Res.Res.Res.Res.BR7BR6Res.Res.Res.BR2BR1BR0
wwwwwwwwwwwwwwww
ST logo
ST logo

7.5 GPIO register map

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

Table 19. GPIO register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00GPIOA_MODERRes.Res.Res.Res.Res.Res.Res.Res.MODE1[1:0]MODE10[1:0]MODE9[1:0]MODE8[1:0]MODE7[1:0]Res.Res.Res.Res.Res.Res.Res.MODE3[1:0]MODE2[1:0]MODE1[1:0]MODE0[1:0]
Reset value000000000010100000
0x00GPIOB_MODERMODE15[1:0]MODE14[1:0]MODE13[1:0]MODE12[1:0]Res.Res.Res.Res.Res.Res.Res.Res.MODE7[1:0]MODE6[1:0]Res.Res.Res.Res.Res.Res.Res.MODE2[1:0]MODE1[1:0]MODE0[1:0]
Reset value000000000000000000
0x04GPIOA_OTYPERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OT11OT10OT9OT8OT7Res.Res.Res.OT3OT2OT1OT0
Reset value000000000
0x04GPIOB_OTYPERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OT15OT14OT13OT12Res.Res.Res.Res.OT7OT6Res.Res.Res.OT2OT1OT0
Reset value000000000
0x08GPIOA_OSPEEDRRes.Res.Res.Res.Res.Res.Res.Res.OSPEED11[1:0]OSPEED10[1:0]OSPEED9[1:0]OSPEED8[1:0]OSPEED7[1:0]Res.Res.Res.Res.Res.Res.OSPEED3[1:0]OSPEED2[1:0]OSPEED1[1:0]OSPEED0[1:0]
Reset value000000000000110000
0x08GPIOB_OSPEEDROSPEED15[1:0]OSPEED14[1:0]OSPEED13[1:0]OSPEED12[1:0]Res.Res.Res.Res.Res.Res.Res.Res.OSPEED7[1:0]OSPEED6[1:0]OSPEED5[1:0]OSPEED4[1:0]Res.Res.OSPEED2[1:0]OSPEED1[1:0]OSPEED0[1:0]
Reset value000000000000000000000
0x0CGPIOA_PUPDRRes.Res.Res.Res.Res.Res.Res.Res.PUPDR11[1:0]PUPDR10[1:0]PUPDR9[1:0]PUPDR8[1:0]PUPDR7[1:0]Res.Res.Res.Res.Res.Res.PUPDR3[1:0]PUPDR2[1:0]PUPDR1[1:0]PUPDR0[1:0]
Reset value010101010110010101
0x0CGPIOB_PUPDRPUPDR15[1:0]PUPDR14[1:0]PUPDR13[1:0]PUPDR12[1:0]Res.Res.Res.Res.Res.Res.Res.Res.PUPDR7[1:0]PUPDR6[1:0]Res.Res.Res.Res.Res.Res.PUPDR2[1:0]PUPDR1[1:0]PUPDR0[1:0]
Reset value010101010101010101
0x10GPIOA_IDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ID15ID14ID13ID12ID11ID10ID9ID8ID7Res.Res.Res.ID3ID2ID1ID0
Reset valuexxxxxxxxxxxx
0x10GPIOB_IDRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ID15ID14ID13ID12Res.Res.ID7ID6Res.Res.Res.ID2ID1ID0
Reset valuexxxxx
0x14GPIOA_ODRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.OD15OD14OD13OD12OD11OD10OD9OD8OD7Res.Res.Res.OD2OD1OD0
Reset value0000000000000

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

OffsetRegister313029282726252423222120191817161514131211109876543210
0x14GPIOB_ODRResResResResResResResResResResResResResResResResOD15OD14OD13OD12ResResResResOD7OD6ResResResResOD2OD1OD0
Reset value000000000
0x18GPIOA_BSRRResResResResBR11BR10BR9BR8BR7ResResResBR3BR2BR1BR0ResResResResBS11BS10BS9BS8BS7ResResResBS3BS2BS1BS0
Reset value000000000000000000
0x18GPIOB_BSRRBR15BR14BR13BR12ResResResResBR7BR6ResResBR3BR2BR1BR0BS15BS14BS13BS12ResResResResBS7BS6ResResResResBS2BS1BS0
Reset value0000000000000000000
0x1CGPIOA_LCKRResResResResResResResResResResResResResResResLCKKResResResResLCK11LCK10LCK9LCK8LCK7ResResResLCK3LCK2LCK1LCK0
Reset value0000000000
0x1CGPIOB_LCKRResResResResResResResResResResResResResResResLCKKLCK15LCK14LCK13LCK12ResResResResLCK7LCK6ResResResResLCK2LCK1LCK0
Reset value0000000000
0x20GPIOA_AFRLAFSEL7[3:0]ResResResResResResResResResResResResAFSEL3[3:0]AFSEL2[3:0]AFSEL1[3:0]AFSEL0[3:0]
Reset value00000000000000000000
0x20GPIOB_AFRLAFSEL7[3:0]AFSEL6[3:0]ResResResResResResResResResResResAFSEL2[3:0]AFSEL1[3:0]AFSEL0[3:0]
Reset value00000000000000000000
0x24GPIOA_AFRH
(where x = A, B)
ResResResResResResResResResResResResResResResResAFSEL11[3:0]AFSEL10[3:0]AFSEL9[3:0]AFSEL8[3:0]
Reset value0000000000000000
0x24GPIOB_AFRH
(where x = A, B)
AFSEL15[3:0]AFSEL14[3:0]AFSEL13[3:0]AFSEL12[3:0]ResResResResResResResResResResResResResResResResRes
Reset value0000000000000000
0x28GPIOA_BRRResResResResResResResResResResResResResResResResResResResBR11BR10BR9BR8BR7ResResResResBR3BR2BR1BR0
Reset value000000000
0x28GPIOB_BRRResResResResResResResResResResResResResResResResBR15BR14BR13BR12ResResResResBR7BR6ResResResResBR2BR1BR0
Reset value000000000

Refer to Section 2.2.2: Memory map and register boundary addresses for the register boundary addresses.