This is an old revision of the document!


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.




The code snippet bellow shows how to configure and use a GPIO pin as output.

#include "reg_stm32f4xx.h"
 
/* Configure GPIO pin A.5 as output. */
GPIOA->MODER &= ~(0x3 << 10u);    /* Clear existing mode bits 10 and 11. */
GPIOA->MODER |= (0x1 << 10u);     /* Set pin 10 to pull-up mode. */
 
GPIOA->PUPDR &= ~(0x3 << 10u);    /* Clear existing pull-up/-down bits 10 and 11. */
GPIOA->PUPDR |= (0x2 << 10u);     /* Set pin 5 to pull-down mode. */
 
GPIOA->OTYPER &= ~(0x1 << 5u);    /* Clear existing output type bit 5. */
 
GPIOA->OSPEEDR &= ~(0x3 << 10u);  /* Clear existing output speed bits 10 and 11. */
GPIOA->OSPEEDR |= (0x1 << 10u);   /* Set pin 5 to medium speed (10 MHz) mode. */
 
/* Write to GPIO pin A.5. */
GPIOA->IDR |= (0x1 << 5u);        /* Write to data register. */
 
GPIOA->BSRR[0] = (0x1 << 5u);     /* Directly set GPIO pin A.5. */
GPIOA->BSRR[1] = (0x1 << 5u);     /* Directly clear GPIO pin A.5. */


Mode register




Pinx01Output mode (reset state)

Push-up / pull-down register




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

Output type register




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

Output speed register




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

Output data register




Bit set / reset register




BSx1Set pin x
BRx1Clear/reset pin x




  • stm32/peripherals/gpio_output.1456389215.txt.gz
  • Last modified: 2016/02/25 08:33
  • by feur