ST AN2710 Application note

AN2710
Application note
Safe GPIO port configuration
in STR7xx devices
Introduction
The general purpose I/O (GPIO) ports of STR7xx devices are programmable by firmware in several modes: input, output, alternate function, output open drain, output push-pull, bidirectional weak push-pull and high impedance. It is possible to manage the analog input mode as well.
This application note describes the best way of configuring the GPIO ports.
February 2008 Rev 1 1/30
www.st.com
Contents AN2710
Contents
1 STR71x & STR73x I/O ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1 Functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 General-purpose I/O (GPIO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.1 Alternate function I/O (AF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.2 Input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.3 Input pull-up/pull-down configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.4 Output configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.5 Alternate function configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2.6 High impedance-analog input configuration . . . . . . . . . . . . . . . . . . . . . 11
2 STR75x general-purpose I/O ports (GPIO) . . . . . . . . . . . . . . . . . . . . . . 12
2.1 Functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.1 General purpose I/O (GPIO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.2 Alternate functions (AF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.3 Input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.1.4 Output configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.1.5 Alternate function configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.6 Analog input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3 STR7x atomic bit set or bit reset (bit-wise write operations) . . . . . . . 19
4 Recommended configuration sequence . . . . . . . . . . . . . . . . . . . . . . . . 20
4.1 From alternate push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.2 From alternate function open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.3 From output push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.4 From output open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.5 From input/output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.6 From input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.7 From analog input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2/30
AN2710 List of tables
List of tables
Table 1. STR71x port bit configuration table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 2. STR73x port bit configuration table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 3. STR75x Port bit configuration table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Table 4. Alternate push-pull to analog input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 5. Alternate push-pull to input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 6. Alternate push-pull to Input pull-up/pull-down. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 7. Alternate push-pull to output open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 8. Alternate push-pull to output push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 9. Alternate push-pull to alternate function open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 10. Alternate function open drain to analog input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 11. Alternate function open drain to input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 12. Alternate function open drain to Input pull-up/pull-down. . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 13. Alternate function open drain to output open drain. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 14. Alternate function open drain to output push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 15. Alternate function open drain to alternate function push-pull . . . . . . . . . . . . . . . . . . . . . . . 22
Table 16. Output push-pull to analog Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Table 17. Output push-pull to input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Table 18. Output push pull to Input pull-up/pull-down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Table 19. Output push-pull to output open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Table 20. Output push-pull to alternate function open drain. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Table 21. Output push-pull to alternate function push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Table 22. Output open drain to analog input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 23. Output open drain to input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 24. Output open drain to Input pull-up/pull-down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 25. Output open drain to output push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 26. Output open drain to alternate function open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 27. Output open drain to alternate function push-pull. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 28. Input pull-up/pull-down to analog input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 29. Input pull-up/pull-down to Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Table 30. Input pull-up/pull-down to output open drain. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Table 31. Alternate Input pull-up/pull-down to output open drain sequence. . . . . . . . . . . . . . . . . . . . 24
Table 32. Input pull-up/pull-down to output push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Table 33. Alternate sequence: Input pull-up/pull-down to output push-pull . . . . . . . . . . . . . . . . . . . . 24
Table 34. Input pull-up/pull-down to alternate function open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Table 35. Alternate sequence: Input pull-up/pull-down to alternate function open drain . . . . . . . . . . 24
Table 36. Input pull-up/pull-down to alternate function push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 37. Input to analog input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 38. Input to Input pull-up/pull-down. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 39. Input to output open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 40. Alternate Input to output open drain sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 41. Input to output push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 42. Input to alternate function open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Table 43. Alternate sequence: Input to alternate function open drain . . . . . . . . . . . . . . . . . . . . . . . . 26
Table 44. Input to alternate function push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Table 45. Analog input to input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Table 46. Analog input to Input pull-up/pull-down. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Table 47. Analog input to output push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Table 48. Analog input to output open drain. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3/30
List of tables AN2710
Table 49. Analog input to alternate function open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Table 50. Analog Input to alternate function push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Table 51. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4/30
AN2710 List of figures
List of figures
Figure 1. Basic structure of an I/O port bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 2. Input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 3. Input pull-up/pull-down configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 4. Output configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 5. Alternate function configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 6. High impedance-analog input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 7. Basic structure of an I/O port bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 8. Input floating/pull-up/pull-down configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 9. Output configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 10. Alternate function configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 11. High impedance-analog input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5/30
STR71x & STR73x I/O ports AN2710

1 STR71x & STR73x I/O ports

1.1 Functional description

Each of the general purpose I/O ports has three 16-bit Configuration registers (PC0, PC1, PC2) and one 16-bit Data register (PD).
Subject to the specific hardware characteristics of each I/O port listed in the “Pin description” table provided in the relevant STR7x datasheet, each port bit can be individually configured as an input, output, alternate function, etc.
Each I/O port bit is freely programmable, however the I/O port registers have to be accessed as 16-bit words. 32-bit or byte access is not allowed.
Figure 1 shows the basic structure of an I/O port bit.

Figure 1. Basic structure of an I/O port bit

To on-chip peripheral
Read/Write
I/O Data register
From on-chip peripheral
Alternate function (IN)
Input latch
Output latch
Alternate function (OUT)
TTL CMOS
Analog input
Push-pull Tristate Open drain Weak push-p ull
I/O pin
ai14915
6/30
AN2710 STR71x & STR73x I/O ports

Table 1. STR71x port bit configuration table

Port Configuration Registers (bit)
(1)
Val ues
PC0(n) 01010101
PC1(n) 00110011
PC2(n) 00001111
Configuration HiZ/AIN IN IN IPUPD OUT OUT AF AF
Output TRI TRI TRI WP OD PP OD PP
Input AIN TTL CMOS CMOS NA NA CMOS CMOS
1. AF = alternate function, AIN = analog input, HiZ = high impedance, IN = input, IPUPD = input pull-up/pull­down, OD = open drain, OUT = output, PP = push-pull, TRI = tristate, TTL = TTL input levels, WP = weak push-pull. NA = not applicable. In Output mode, a read access the port will get the output latch value). See Figure 4.

Table 2. STR73x port bit configuration table

(1)
Port Configuration
Val ues
Registers (bit)
PC0(n) 01 0 10101
PC1(n) 00 1 10011
PC2(n) 00 0 01111
Configuration HiZ/AIN IN
Output TRI TRI WP
reserved
Input - TTL TTL TTL TTL TTL TTL
1. AF = alternate function, AIN = analog input, HiZ = high impedance, IN = input, IPUPD = input pull-up/pull­down, OD = open drain, OUT = output, PP = push-pull, TRI = tristate, TTL = TTL input levels, WP = weak push-pull.
2. Depending on the PD(n) value, it behaves as weak pull-up (PD=1) or weak pull-down (PD=0)

1.2 General-purpose I/O (GPIO)

At reset the I/O ports are configured as general-purpose (memory mapped I/O).
When the user writes to the I/O Data register, the data are always loaded into the output latch. The output latch holds the data to be output while the input latch captures the data present on the I/O pin.
A read access to the I/O Data register reads the input latch or the output latch depending on whether the port bit is configured as an input or an output.
IPUPD OUT OUT AF AF
(2)
OD PP OD PP
7/30
STR71x & STR73x I/O ports AN2710

1.2.1 Alternate function I/O (AF)

The alternate functions for each pin are listed in the datasheet. Configuring a port bit as alternate function will disconnect the output latch and connect the pin to the output signal of an on-chip peripheral.
For alternate function inputs, the port must be configured in Input mode and the input
pin must be driven externally.
Note: It is also possible to emulate the AFI input pin by firmware by programming the GPIO
controller. In this case, the port should be configured in Alternate Function Output mode. And obviously, the corresponding port should not be driven externally as it will be driven by the firmware using the GPIO controller.
For AF output or input-output, the port bit must be in AF configuration.
External interrupts/wakeup lines
Some ports have external interrupt capability (see datasheet). To use external interrupts, the port must be configured in input mode. For more information on interrupts and wakeup lines, refer to the reference manual.

1.2.2 Input configuration

When the I/O port is programmed as Input:
The output buffer is forced tristate
The data present on the I/O pin are sampled into the input latch with every clock cycle
A read access to the Data register gets the value in the input latch.
Figure 2 shows the input configuration of the I/O port bit.
Figure 2. Input configuration
Alternate function (IN)
Input latch
I/O Data register
Output latch
Alternate function (OUT)
1. For STR73x only.
TTL CMOS
Analog input
(1)
Tristate
I/O pin
ai14916
8/30
AN2710 STR71x & STR73x I/O ports

1.2.3 Input pull-up/pull-down configuration

When the I/O port is programmed as input pull-up/pull-down:
The output buffer is turned on in weak push-pull configuration and the firmware can
write the appropriate level into the output latch to activate the weak pull-up or pull-down as required.
The data in the output latch drive the I/O pin (a logic zero activates a weak pull-down, a
logic one activates a weak pull-up).
A read access to the I/O Data register gets the input latch value.
Figure 3 shows the Input pull-up/pull-down configuration of the I/O port.
Figure 3. Input pull-up/pull-down configuration
I/O port Data register

1.2.4 Output configuration

When the I/O port is programmed as output:
The output buffer is turned on in open drain or push-pull configuration
The data in the output latch drive the I/O pin
A read access to the I/O Data register gets the output latch value.
Figure 4 shows the output configuration of the I/O port bit.
Input latch
Output latch
Alternate function (IN)
Alternate function (OUT)
PU
PD
Analog input
When AIEN = 1
I/O pin
Weak push-pull
ai14917
9/30
Loading...
+ 21 hidden pages