Table of contents
STM32 GPIOs are available in various configurations. Each GPIO pin can be individually configured by software in any of the following modes:
• Input floating
• Input pull-up
• Input drop down
• Simulation
• Open-drain output with pull-up or pull-down
• Push-pull output with pull-up or pull-down
• Alternate function push-pull with pull-up or pull-down
• Alternate function open drain with pull-up or pull-down
GPIO Equivalent Schematic
STM32 products integrate three main GPIO basic structures:
• Three-volt compatible (abbreviated as TC).
Figure 1 shows the equivalent GPIO graph structure.
• Three Volt Tolerant (abbreviated as TT).
• Five Volt Tolerant (abbreviated as FT)
Figure 2 shows the equivalent GPIO graph structure of TT or FT.
Input Mode Configuration
When an STM32 device I/O pin is configured as an input, one of the following three options must be selected:
• Output with internal pullup. Pull-up resistors are used in STM32 devices to ensure well-defined logic levels in case of floating input signals. Depending on application requirements, an external pull-up resistor can be used.
• Input with internal pull-down. Pull-down resistors are used in STM32 devices to ensure well-defined logic levels in case of floating input signals. Depending on application requirements, an external pull-down can be used.
• Floating input. The signal level follows the external signal. When there is no external signal, the Schmitt trigger switches randomly between logic levels caused by external noise. This increases overall consumption.
When programmed as an input, an I/O port has the following characteristics:
• The output buffer is turned off;
• Schmitt trigger input is turned on;
• Determine whether to activate pull-up or pull-down resistors according to the value in the GPIOx_PUPDR register;
• The input data register samples the data on the I/O pin every 1 AHB clock cycle;
• I/O status can be obtained by reading the GPIOx_IDR input data register;
Output Mode Configuration
When an STM32 device I/O pin is configured as an output, one of the following two options must be selected:
• Push-pull output mode:
The push-pull output actually uses two transistors: a PMOS and an NMOS. Each transistor turns on to drive the output to the appropriate level:
– When the output must be driven to a high state, the top transistor (PMOS) is turned on
– Bottom transistor (NMOS) conducts when output must be driven to low state
The control of the two transistors is done through the GPIO port output type register (GPIOx_OTYPER).
Writing a 0 to the relevant bit of the output register (GPIOx_ODR) activates the NMOS transistor, forcing the I/O pin to ground.
Writing a 1 to the relevant bit in the output register (GPIOx_ODR) activates the PMOS transistor, forcing the I/O pin to VDD.
• Open-drain output mode:
Open-drain output mode does not use a PMOS transistor, but requires a pull-up resistor.
When the output has to go high, the NMOS transistor has to be turned off and the level is pulled high only by the pull-up resistor. This pull-up resistor can be internal, typically 40kOhm, and is activated via the GPIO port pull-up/pull-down register (GPIOx_PUPDR).
When programmed as an output, an I/O port has the following characteristics:
• Output buffers can be configured as open-drain or push-pull;
• Schmitt trigger input is turned on;
• Determine whether to activate pull-up or pull-down resistors according to the value in the GPIOx_PUPDR register;
• The value written to the output data register GPIOx_ODR sets the state of the I/O pin;
• The data written in GPIOx_ODR can be read from GPIOx_IDR, which is updated every AHB clock cycle;
multiplexing function
On some STM32 GPIO pins, the user can choose alternate function input/output. Each pin can be multiplexed with up to 16 peripheral functions, such as communication interfaces (SPI, UART, I2C, USB, CAN, LCD, etc.), timers, debug interfaces, etc.
The alternate function of the selected pin is configured through two registers:
• GPIOx_AFRL (pins 0 to 7)
• GPIOx_AFRH (pins 8 to 15)
When programming an I/O port as an alternate function:
• Output buffers can be configured as open-drain or push-pull
• Output buffers driven by signals from peripherals (transmitter enable and data)
• Schmitt trigger input is turned on
• Depending on the value in the GPIOx_PUPDR register whether to activate pull-up or pull-down resistors
The input data register samples the data on the I/O pin every 1 AHB clock cycle.
Read access to the input data registers obtains the I/O status.
Simulation configuration
There are some STM32 GPIO pins that can be configured in analog mode, allowing the use of ADC, DAC, OPAMP and COMP internal peripherals. To use GPIO pins in analog mode, consider the following registers:
• - GPIOx_MODER, select mode (input, output, multiplexed, analog)
• - GPIOx_ASCR, select the desired function, ADC, DAC, OPAMP or COMP
When programming an I/O port as an analog configuration:
• Output buffer is turned off
• The Schmitt trigger input is disabled, so there is zero consumption per analog value on the I/O pin. The output of the Schmitt trigger is forced to a constant value (0).
• Pull-up and pull-down resistors are disabled by hardware
A read access to the input data register has the value "0".
GPIO Configuration Guide