Subsection 1.1.2 GPIO: The Software-Hardware Bridge
The physical pins of a microcontroller serve many roles. Some are dedicated: they carry power or ground, connect to a clock crystal, or provide a reset signal. But most pins are GPIO pins: General-Purpose Input/Output. “General-purpose” means they have no fixed function. Each pin is configured independently: one pin might be a digital output driving an LED, an adjacent pin might be a digital input reading a button, and a third might be in alternate function mode, where the GPIO hardware is bypassed and the pin is handed off to a peripheral such as the UART (Universal Asynchronous Receiver-Transmitter) or I2C (Inter-Integrated Circuit). There is also an analog mode that connects the pin directly to the analog-to-digital converter, bypassing the digital input circuitry entirely.
A GPIO output pin is the simplest possible interface between software and the physical world. Set it HIGH and current flows through an LED; set it LOW and the LED goes dark. Drive it HIGH and LOW in a pattern and you are transmitting serial data. Modulate the ratio of HIGH to LOW time and you are controlling motor speed. Everything in this course starts from that one primitive: a pin whose voltage your code controls.
The STM32C031C6 groups its GPIO pins into ports, named A, B, and C, with up to 16 pins per port. A pin is identified by its port letter and bit number within that port: PA5 means Port A, bit 5. The bit number matters because the hardware registers that control each pin use that number to address the right bit.
