What you practice
GPIO register block (2.1). Implement GPIO direction, output, and set/clear registers in a student module and verify with a testbench. It is in GPIO CSR Block — Part 2 · Peripheral Islands of the SoC Masterclass. Build GPIO, timer, UART, and IRQ islands, then wrap them as a peripheral subsystem.
SoC lessons simulate the fabric and the peripheral together in the IDE. Verilator is the simulator; the waveform is where address and response show up.
What you will learn
You will implement a GPIO register block that handles direction, output, and set/clear operations via an AXI-Lite interface. This module is a fundamental building block for peripheral islands in SoC designs.
Learning objectives
- Define register addresses for direction, output, input, set, and clear operations.
- Implement a finite state machine to handle AXI-Lite read and write transactions.
- Update GPIO output and direction registers based on write data.
- Verify the design using a testbench that writes to direction and output registers.
Theory
The GPIO register block exposes several registers to the CPU via the AXI-Lite bus. These registers control the direction (input vs output) and the output value of the GPIO pins. The direction register (REG_DIR) sets the pin mode. The output register (REG_OUT) sets the static output value. The set register (REG_SET) performs a bitwise OR to drive pins high. The clear register (REG_CLR) performs a bitwise AND NOT to drive pins low. The input register (REG_IN) allows the CPU to read the current pin state.
| Register | Address | Access | Description |
|---|---|---|---|
| DIR | 0x00 | RW | Direction control (1=Out, 0=In) |
| OUT | 0x04 | RW | Output value latch |
| IN | 0x08 | RO | Current pin input value |
| SET | 0x0C | WO | Bitwise OR to output |
| CLR | 0x10 | WO | Bitwise AND NOT to output |
The AXI-Lite interface uses a simple state machine to manage transactions. The IDLE state waits for valid address and write/read requests. The WRITE state captures data when wvalid is asserted. The READ state latches data and asserts rvalid. The RESP state acknowledges the write with a response.
Practice
Open this chapter in RtlStudio to load the workspace. Navigate to Explore and open student/rtl/ip/soc/gpio_csr.sv. Define the register addresses as 32-bit constants. Set REG_DIR to 32'h00. Set REG_OUT to 32'h04. Set REG_SET to 32'h0C. Set REG_CLR to 32'h10. Ensure the state machine logic correctly decodes these addresses in the WRITE and READ cases. Open student/tb/tb_top.sv to verify the implementation. Run Simulation from the sidebar. Check the Log panel for the result.
Summary
You implemented a GPIO register block that maps memory addresses to internal direction, output, and control registers. The design handles AXI-Lite transactions to support read operations and atomic set/clear updates for output bits. This exercise reinforced the use of finite state machines for protocol handling and bitwise logic for register manipulation.
© 2026 RtlStudio. Licensed under CC BY-NC-ND 4.0. Commercial use and modifications by third parties are not permitted.
Run it in the Verilog IDE
- Open the lesson workspace in the IDE. The fabric and the peripheral are one simulation.
- Run Verilator and follow the address, write data, and read response on the waveform.
- A passing log is not enough when decode or an IRQ line is the point of the lesson — those show up on the VCD.
- Run Yosys on the RTL island you just integrated when you want the mapped cells.
The lesson is done when the simulation matches GPIO register block. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.