STM32/PY32 GPIO: 8 Input/Output Modes Explained

Practical explanation of common GPIO modes on STM32/PY32 MCUs.

GPIO 8 Common Modes

GPIO (General Purpose Input/Output) is used to interface with external circuits. On STM32/PY32, common modes include:

  • floating input
  • pull-up input
  • pull-down input
  • analog input
  • push-pull output
  • open-drain output
  • alternate-function push-pull
  • alternate-function open-drain

Input Modes

Floating input (GPIO_Mode_IN_FLOATING)

The pin is high-impedance and not internally pulled up/down. External circuitry determines level.

1
2
3
4
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

Pull-up input (GPIO_Mode_IPU)

Internal pull-up resistor keeps default level high.

Pull-down input (GPIO_Mode_IPD)

Internal pull-down resistor keeps default level low.

Output Modes

Push-pull output

Can actively drive both high and low levels. Good for general digital output.

Open-drain output

Can actively pull low; high level typically provided by pull-up resistor. Useful for shared bus (for example I2C-like signaling).

Analog Mode

Analog mode disconnects digital input/output path and is used for ADC/analog signals.

Practical Selection Tips

  • Button input: pull-up or pull-down.
  • LED/general control pin: push-pull output.
  • Wired-AND/shared line: open-drain + pull-up.
  • ADC pin: analog mode.
记录并分享
Built with Hugo
Theme Stack designed by Jimmy