RM0444
Each I/O pin has a multiplexer with up to eight alternate function inputs (AF0 to AF7) that
can be configured through the GPIOx_AFRL (for pin 0 to 7) and GPIOx_AFRH (for pin 8 to
15) registers:
•
After reset the multiplexer selection is alternate function 0 (AF0). The I/Os are
configured in alternate function mode through GPIOx_MODER register.
•
The specific alternate function assignments for each pin are detailed in the device
datasheet.
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:
•
Debug function: after each device reset these pins are assigned as alternate function
pins immediately usable by the debugger host
•
GPIO: configure the desired I/O as output, input or analog in the GPIOx_MODER
register.
•
Peripheral alternate function:
–
–
–
•
Additional functions:
–
–
Refer to the "Alternate function mapping" table in the device datasheet 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.
Connect the I/O to the desired AFx in one of the GPIOx_AFRL or GPIOx_AFRH
register.
Select the type, pull-up/pull-down and output speed via the GPIOx_OTYPER,
GPIOx_PUPDR and GPIOx_OSPEEDER registers, respectively.
Configure the desired I/O as an alternate function in the GPIOx_MODER register.
ADC, DAC and COMP connection can be enabled in ADC, DAC or COMP
registers regardless the configured GPIO mode. When ADC, DAC or COMP uses
a GPIO, it is recommended to configure the GPIO in analog mode, through the
GPIOx_MODER register.
For the additional functions like RTC, TAMP, WKUPx and oscillators, configure the
required function in the related RTC, TAMP, PWR and RCC registers. These
functions have priority over the configuration in the standard GPIO registers.
RM0444 Rev 5
General-purpose I/Os (GPIO)
235/1390
247
Need help?
Do you have a question about the STM32G0 1 Series and is the answer not in the manual?
Questions and answers