GPIO, MCU input/output core
GPIO, STM32·STM8 MCU I/O ports
Used for various applications and purposes
[Editor's Note] Generally, when we think of semiconductors, we tend to think of semiconductors that are familiar to the general public, such as the CPU and memory of computers. On the other hand, MCUs (Micro Controller Units), which are used as core semiconductors for operating electronic products, are semiconductors that are still unfamiliar to the general public, even though they are commonly used in all electronic products that we easily come across. These MCUs have recently been in the media due to the semiconductor shortage, and have begun to attract the attention of the general public. Accordingly, our magazine has prepared a place to learn about MCUs through a series of articles by Yuji Kawano, Manager of ST Microelectronics, a company specializing in MCU semiconductors.
■ MCU that inputs and outputs binary signals The simplest task that an MCU can perform is to output binary (0/1) signals through a port and read binary signals from the port. Although very simple, these functions are essential and are implemented in all high-performance MCUs. This paper describes the devices and input/output ports that perform these functions.
■ IO, binary signal reading component Input/output ports are generally defined as components that output binary signals through the port and read binary signals input from the port. Such ports are also called IO (or I/O) ports. The I/O ports of STM32 and STM8 MCUs produced by STMicroelectronics (hereinafter referred to as ST) are called GPIO (general-purpose input/output pins) because they are used for various applications and purposes. The word 'port' can certainly be thought of as a port where cargo is loaded and released. This is an apt metaphor for the role performed by the MCU, except that the 'cargo' handled by the MCU is a piece of data consisting of 0 and 1.

▲Figure 1: Role of GPIO
Figure 1 is one of the simplest applications for GPIO. When the push-button switch is off, a '0' (ground level) is input to port 2. When the button is pressed, the input changes to a '1' (power supply voltage level). However, if port 1 normally outputs '1', the LED will remain turned off, and if it outputs '0', the LED will turn on.
These functions are linked to the MCU program, turning the LED on when the button is pressed, and off when the button is not pressed.
Examples of how this port could be used in practice include replacing a push-button switch with a control circuit input signal, or replacing an LED with a motor-driver IC.

▲Figure 2: GPIO structure
Next, let's look at the internal structure of GPIO. Since the MCU structure varies depending on the manufacturer, you need to read the relevant user manual for a detailed description of the structure of a specific MCU. For example, let's look at the GPIO structure of STM32.
Figure 2 shows the structure diagram of GPIO. The upper part is the input circuit, and the lower part is the output circuit. On the right is the GPIO pin where data enters and exits. Right after this pin is a protection diode that prevents noise and surge voltage from the power or ground. Since GPIO has pull-up/pull-down resistors, the number of external resistors required can be reduced. Software can connect or disconnect these pull-up/pull-down resistors to the circuit. The CMOS circuit accepts the input data and passes it to the internal circuit. This CMOS circuit is called the input buffer. In this diagram, a CMOS inverter is used as a buffer.
Data output from the MCU is transmitted through the output buffer. This buffer consists of a CMOS inverter and uses high-performance CMOS to drive circuits outside the MCU.
One type of GPIO structure is the NMOS open-drain structure, where the NMOS drain remains open, i.e., the PMOS is not connected to the NMOS.
An output buffer consisting of only NMOS (i.e., without PMOS) is called an NMOS open-drain. For reference, this type of drain is shown on the right side of Figure 2. This buffer requires an external pull-up resistor because it cannot output '1' (high) by itself. For example, an NMOS open-drain structure is used for I2C communication ports.
In fact, since electrical signals are the inputs of the GPIO circuit, when you want to make a push-button circuit, you need to know which voltage represents '0' and which voltage represents '1'. In the case of digital logic circuits such as MCUs, the boundary level between the two voltage ranges representing "0" and '1' is called the threshold level. Since CMOS circuits receive signals from the internal circuits of the MCU, the threshold level is the voltage that turns on or off the PMOS/NMOS circuits that make up the CMOS.

▲Figure 3: Threshold value
Now, let's look at Figure 3(a). Let's assume that the input voltage to the GPIO is gradually increased from GND (0 V) until it reaches the power supply level, and then gradually decreased again. Initially, GPIO recognizes the input voltage as '0', but once it exceeds a certain voltage, GPIO recognizes it as '1'. As mentioned earlier, this boundary voltage is called the threshold voltage. When the output voltage drops below the threshold voltage, GPIO recognizes it as '0' again.
To ensure stable operation even with noisy input signals, there is another type of GPIO that has two threshold levels. One threshold is for '0' to '1' transitions, and the other is for '1' to '0' transitions. A GPIO that uses two thresholds is said to have Schmitt-trigger characteristics.
Next, let's look at Figure 3(b). This figure is different from Figure 3(a). The threshold for the transition from '0' to '1' is not the same as the threshold for the transition from '1' to '0'. The voltage difference between these two threshold levels is called the hysteresis voltage range.
Once a GPIO recognizes a voltage level as a '1' or '0', it will not recognize any fluctuations in the input level, even if there is noise, as long as the voltage level fluctuates within the hysteresis voltage range. In other words, it is noise-resistant.
This type of GPIO is used for clock input ports for communication, reset ports, interrupt request ports, etc., and prevents noise-induced errors (including voltage fluctuations and chattering).
Different MCUs use different conditions for the input characteristics, but VIH is generally used to indicate the H-threshold, and VIL is used to indicate the L-threshold.
■ Be careful that there are environments where the output is neither '1' nor '0'. .jpg)
▲Figure 4: Output characteristics
In general, VOH represents the output voltage of '1', and VOL represents the output voltage of '0'. The characteristics of the output buffer MOS affect these voltages. Let's look at Figure 4. When '1' is the output (Figure 4(a)), the PMOS is turned on, and when '0' is the output (Figure 4(b), the NMOS is turned on. In the former case, the output voltage differs slightly from the power supply voltage (Vdd) due to the voltage drop appearing in the PMOS (Vpmos in Figure 4). In the latter case, the output voltage differs slightly from the GND level (Vss) due to the voltage drop appearing in the NMOS (Vnmos in Figure 4). As a result, the output voltage is as follows. VOH = Vdd - Vpmos and VOL = Vss + Vnmos. For specific values, please refer to the manual that specifies the electrical characteristics of the relevant MCU.
It should be noted that there are circumstances where the output is neither '1' nor '0'. This condition, which occurs when both the PMOS and NMOS are off, is called the 'high impedance state', 'open state' or 'tri-state', and is denoted as 'HZ' or 'High-Z'. High impedance means that the output state has high impedance with respect to the power supply or GND. Since this output characteristic is the third state other than the two states of H and L, it is called the 'tri-state'. The 'open state' means that the output circuit is not connected to anything.