6 - STM32 Gpio
6 - STM32 Gpio
STM32 GPIO
CONTENTS
• Objectives
• GPIO Features
2
★Objectives:
3
GPIO Features
• Bi-directional I/O ports available
• Standard I/Os 5V tolerant
• The GPIOs can sink 25mA
• 18 MHz Toggling
• Configurable Output Speed up to 50 MHz
• Up to 16 Analog Inputs
• Alternate Functions pins (like USARTx, TIMx, I2Cx,
SPIx,…)
4
GPIO Features
• Bi-directional I/O ports available
• Can be set-up as external interrupt
• One I/O can be used as Wake-Up from STANDBY (PA.00)
• One I/O can be set-up as Tamper Pin (PC.13)
• All Standard I/Os are shared in 5 ports (GPIOA..GPIOE)
• Locking mechanism to avoid spurious write in the IO
registers:
When the LOCK sequence has been applied on a port
bit, it is no longer possible to modify the configuration
of the port bit until the next reset (no write access to
the CRL and CRH registers corresponding bit).
5
STM32 GPIO and pins
STM32F103VET6 has five 16-bit ports: PA, PB, PC, PD, PE.
6
•STM32F103VET6 pins
7
GPIO Configuration Modes
Subject to the specific hardware characteristics of each I/O port listed in the
datasheet, each port bit of the General Purpose IO (GPIO) Ports, can be
individually configured by software in several modes:
● Input floating
● Input pull-up
● Input-pull-down
● Analog
● Output open-drain
● Output push-pull
● Alternate function push-pull
● Alternate function open-drain
Each I/O port bit is freely programmable, however the I/O port registers have to
be accessed as 32-bit words (half-word or byte accesses are not allowed). The
purpose of the GPIOx_BSRR and GPIOx_BRR registers is to allow atomic
read/modify accesses to any of the GPIO registers. This way, there is no risk that
an IRQ occurs between the read and the modify access.
8
GPIO Configuration Modes
9
GPIO Configuration Modes
10
10
GPIO Configuration Modes
11
11
AFIO Features/ GPIO Remapping(1/3)
• To optimize the number of peripherals available for the 64-pin or the 100-
pin or the 144-pin package, it is possible to remap some alternate
functions to some other pins. This is achieved by software, In this case, the
alternate functions are no longer mapped to their original assignations.
13
AFIO Features/ GPIO Remapping(3/3)
▪ Using Debug pins:
14
Circuit structure of STM32 GPIO
1. Input configuration Pull-up, pull-down or
Floating, pull-up or pull-down input floating can be set
according to the
Schmitt trigger is on requirement.
15
Output buffer is disabled
15
When the I/O Port is programmed as Input:
16
16
2. Output configuration Schmitt trigger is on
In open-drain mode, P-MOS is not activated, and only N-MOS works. ‘0’
on the output register will activate N-MOS, and output LOW, and ‘1’ on the
output register will set the port to high impedance status.
In push-pull mode, ‘0’ on the output register will activate N-MOS, and ‘1’
on the output register will activate P-MOS. 17
17
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
while 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
while a “1” in the Output register activates the P-MOS.
● The Schmitt Trigger Input is activated.
● The weak pull-up and pull-down resistors are disabled.
● The data present on the I/O pin is sampled into the Input Data
Register every APB2 clock cycle
● A read access to the Input Data Register gets the I/O state in open
drain mode
● A read access to the Output Data register gets the last written value
in Push-Pull mode
18
18
3. Alternate function configuration
Pull-up and pull-down are
Alternate function input Schmitt trigger is on
disabled.
19
19
When the I/O Port is programmed as Alternate Function:
20
20
STM32 GPIO Configuration