General Purpose Output

  • The output buffer is enabled (open drain or push-pull).
  • The Schmitt trigger input is active.
  • The pull-up and -down resistors are active, according to PUPDR.
  • Input data is sampled every AHB clock.
  • Input data register holds I/O state.
  • Output data register holds last written value.




Make sure the peripheral is enabled:

  • Enable GPIOx in RCC→AHBENR[0].

Configure the MODE and PUPDR as well as the output type and speed register,
for every pin that should act as digital output:

  • Write 0x01 to the corresponding fields in GPIOx→MODE.
  • Configure pull-up / -down in GPIOx→PUPDR.
  • Configure output type in GPIOx→OTYPER.
    (in conjunction with GPIOx→PUPDR)
  • Configure output speed in GPIOx→OSPEEDR.





Pin x01Output mode




Pin x00No pull-up, pull-down (reset state)
01Pull-up
10Pull-down
11Reserved




Pin x0Output type: push-pull (reset state)
1Output type: open-drain




Pin x00Speed: 2 MHz (reset state)
01Speed: 10 MHz
10Speed: 50 MHz
11Speed: 100 MHz




ODx0Clear/reset pin x
1Set pin x




BSx0No effect
1Set pin x
BRx0No effext
1Clear/reset pin x
  • stm32/peripherals/gpio_output.txt
  • Last modified: 2022/12/28 08:17
  • by ruan