ARM M7 GPIO



GPIO Modes
GPIO ports can be individually configured by software in several modes:
Input:
• Input floating
• Input pull-up
• Input-pull-down
Output:
• Output open-drain with pull-up or pull-down capability
• Output push-pull with pull-up or pull-down capability
Input/Output:
• Analog
• Alternate function push-pull with pull-up or pull-down capability
• Alternate function open-drain with pull-up or pull-down capability

In addition to standard GPIO modes, the pin mode can be configured as EXTI (Extended interrupt and event controller) with interrupt.
External Interrupt mode:
– GPIO_MODE_IT_RISING : Rising edge trigger detection

– GPIO_MODE_IT_FALLING : Falling edge trigger detection
– GPIO_MODE_IT_RISING_FALLING : Rising/Falling edge trigger detection

Another variable to be consider is the speed (this controls the slew rate (the rise time and fall time) of the output signal). Possible values are:
GPIO_SPEED_FREQ_LOW
GPIO_SPEED_FREQ_MEDIUM
GPIO_SPEED_FREQ_HIGH
GPIO_SPEED_FREQ_VERY_HIGH

                                            Input Configuration

When the I/O port is programmed as input:
• The output buffer is disabled
• The Schmitt trigger input is activated
• The pull-up and pull-down resistors are activated by programming
• The data present on the I/O pin are sampled into the input data register
• A read access to the input data register provides the I/O state

Input Floating: Its state is indeterminate, meaning that it is neither connected to VCC or to ground. It’s used interchangeably to describe a pin which is in the high-impedance state
Input pull-up: Pull-up resistors are used to set a pin to a logical high state (30K <=RPU <=50K)
Input pull-down: Pull-down resistors are used to set a pin to a logical low state (30K <=RPU <=50K)
                                          Output configuration
When the I/O port is programmed as output:
• The output buffer is enabled:
– Open drain mode: A “0” in the Output register activates the N-MOS whereas a “1”
in the Output register leaves the port in Hi-Z (the P-MOS is never activated)
– Push-pull mode: A “0” in the Output register activates the N-MOS whereas a “1” in
the Output register activates the P-MOS
• The Schmitt trigger input is activated
• The pull-up and pull-down resistors are activated by programming
• The data present on the I/O pin are sampled into the input data register
• A read access to the input data register gets the I/O state
• A read access to the output data register gets the last written value

Output Push Pull: In Push-Pull type there will be two switches (transistor/ MOSFET) inside the uC and one switch will be connected to Ground and the other will be connected to Vcc/Vdd. If you make the output HIGH the pin will be connected to Vdd through the NPN switch and if you make the Output pin LOW the pin will be connected to Ground thorough the PNP switch
Output Open Drain: There will be only one switch (transistor/MOSFET) inside the uC and this switch is connected to Ground. If you make the output pin HIGH the pin will be connected to ground through the switch and if you make the Output pin LOW the pin will be left floating since the switch will be turned off. Since in the Open Drain type the pin is left as floating a pull-high or pull-down resistor is usually added to the GPIO pin

                                     Alternate function configuration
On some pins, the user has the possibility to select alternate functions inputs / outputs. Each pin is multiplexed with up to sixteen peripheral functions such as communication interfaces (SPI, UART, I2C, USB, CAN, LCD and others), timers, debug interface, and others
When the I/O port is programmed as alternate function:
• The output buffer can be configured in open-drain or push-pull mode
• The output buffer is driven by the signals coming from the peripheral (transmitter
enable and data)
• The Schmitt trigger input is activated
• The weak pull-up and pull-down resistors are activated or not by programming
• The data present on the I/O pin are sampled into the input data register
• A read access to the input data register gets the I/O state


                                            Analog configuration
Analog mode allows the use of ADC, DAC, OPAMP, and COMP internal peripherals.
When the I/O port is programmed as analog configuration:
• The output buffer is disabled
• The Schmitt trigger input is deactivated, providing zero consumption for every analog
value of the I/O pin. The output of the Schmitt trigger is forced to a constant value (0).
• The weak pull-up and pull-down resistors are disabled by hardware
• Read access to the input data register gets the value “0”



Setting PB12 as output with STM32 CubeMX for code generation

Definition of GPIO modes
File: stm32hxx_hal_gpio.h



Example: Toggle PB12 pin
Set Pin Mode: stm32h7xx_nucleo_144.c
main.c:
Output Signal in PB12 pin
Example 2: External interrupt AN4899: STM32 GPIO configuration for hardware settings and low-power consumption