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.
Programming Example
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. */
Configuration Registers
MODER
PUPDR
Push-up / pull-down register
Pin x | 00 | No pull-up, pull-down (reset state) |
01 | Pull-up | |
10 | Pull-down | |
11 | Reserved |
OTYPER
OSPEEDR
Output speed register
Pin x | 00 | Speed: 2 MHz (reset state) |
01 | Speed: 10 MHz | |
10 | Speed: 50 MHz | |
11 | Speed: 100 MHz |