On-Chip Peripherals, Address Decoding, and Pin Multiplexing

The MangoPi's D1-H is a system on a chip (SoC). Besides the CPU, the chip integrates dozens of separate hardware modules called on-chip peripheral controllers, such as the PIO controller for GPIO ports and UART controllers for serial communication. Each controller contains its own digital logic and registers.

Peripheral registers are the “control and status panel” that each controller exposes to the CPU bus. The LEDs and current-limiting resistors plugged into our breadboard, by contrast, are outside the chip: they are off-chip components.

The number of physical pins around a chip package is limited. To make better use of them, the hardware allows functions from multiple controllers to share the same physical pin. Each on-chip controller has its own dedicated register block in a different memory-mapped address range. A single general-purpose register is not responsible for implementing all these functions or connecting all the peripherals.

How can multiple controllers share one physical pin?

This requires a multiplexer (MUX). As a first mental model, think of it as function-selection logic between the controller signals and the pin: a selection code determines which control path the physical pin uses. The available functions for each pin and their codes are specified by the chip design.

There are two different kinds of “selection” to distinguish:

Address decoding locates PB_CFG0; pin multiplexing uses the PB0 function field to select the GPIO output path.

First selection: address decoding — which register receives the write?

The CPU issues a write, for example writing 0x00000001 to address 0x02000030. Address decoding and the access path locate PB_CFG0 and complete the write; PB_CFG0 holds the value.

Second selection: pin multiplexing — which function controls the pin?

The PB0 function field in PB_CFG0 is 0001. These field bits determine the function selection. The MUX / function-selection logic selects the GPIO output path, so PB0 uses GPIO output rather than another available function such as UART.

Address decoding determines which register receives the data; the MUX uses the selection code stored in a register to determine which function the physical pin uses.

Thinking of the MUX as an automatic switch

A multiplexer can be pictured as an automatic switch with several inputs and one output. It takes two kinds of input:

- Candidate signals, such as GPIO output data and a UART controller's transmit signal. - A selection code that tells it which function path to choose.

When a pin is configured for GPIO output, the corresponding data-register bit in the PIO controller drives it. Once the pin is switched to the UART transmit function, its output path is taken over by the UART controller's transmit circuitry.

At that point, continuing to write 0 or 1 to the corresponding GPIO data-register bit no longer changes the pin's level through the GPIO output path.

The complete chain I connected today

CPU executes `sw` → address decoding locates CFG → CFG stores the function-selection code → the MUX selects the pin's control path → in GPIO output mode, DAT data drives the pin.

Original note

Original November 18 Chinese note on on-chip peripheral controllers, address decoding, and pin multiplexing.