This repository contains a modular, fully synthesizable, and simulation-verified Write HDL Code for SPI(master) to AXI4-Lite bridge design in Verilog HDL. This project translates serial SPI transactions into parallel AXI4-Lite register reads and writes, allowing an external master to communicate with internal FPGA registers.
The bridge operates as an SPI Slave on its external pins and an AXI4-Lite Master on its internal bus interface.
- SPI Protocol: Compatible with SPI Mode 0 (CPOL=0, CPHA=0) using active-low Chip Select (
cs_n). - Synchronization: Input lines are double-synchronized to the fast system clock (
clk) immediately at the input boundaries to prevent metastability. - 24-bit Packet Framing: Transactions are structured in 3 bytes:
[8-bit Command] -> [8-bit Address] -> [8-bit Data]. - Standard AXI4-Lite Handshakes: Drives compliant address, data, and response valid-ready signals.
To satisfy the "SPI(master) to AXI4-Lite" objective, the bridge is designed under the following system architecture choice:
- External SPI Master: The project assumes that an external host controller (such as a microcontroller) acts as the SPI Master, generating all SPI bus transactions and driving
sclk,cs_n, andmosi. - Bridge SPI Slave (
spi_slave.v): The bridge physically implements an SPI Slave interface to receive and synchronize those incoming asynchronous transactions. - Bridge AXI4-Lite Master: The bridge internally converts the received SPI commands into parallel AXI4-Lite register write and read accesses on the internal FPGA bus fabric. This architecture complies exactly with the protocol roles, ensuring that transactions originating from an SPI Master are successfully translated into standard-compliant register operations inside the chip.
The design is split into five submodules under the top-level wrapper spi2axilite:
spi_slave(spi_slave.v): Synchronizes external inputs and shifts serial bits into 8-bit parallel bytes.spi_cmd_decoder(spi_cmd_decoder.v): Parses the command byte to identify write (8'h01), read (8'h02), or invalid instructions.spi_fsm(spi_fsm.v): Sequencer FSM that coordinates byte boundaries, schedules bus requests, and handles reset aborts.axi_lite_master(axi_lite_master.v): Coordinates standard AMBA AXI4-Lite channel handshakes.axi_register_bank(axi_register_bank.v): Target AXI4-Lite slave register memory map.
The bridge controller uses a robust 7-state FSM:
IDLE GET_CMD GET_ADDR GET_DATA (Write path) AXI_WRITE / AXI_READ SEND_RESP (Read path).
- Abort Protection: If Chip Select (
cs_n) goes high at any point during a transaction, the FSM instantly aborts and resets toIDLEin exactly one clock cycle, protecting internal registers from corrupted or incomplete packets.
The internal register bank manages four 32-bit registers, spaced by 4 bytes for address alignment:
| Address | Register Name | Access Type | Default Value | Description |
|---|---|---|---|---|
32'h0000_0000 |
CONTROL | Read/Write | 32'h0000_0000 |
Configures system behavior. |
32'h0000_0004 |
STATUS | Read-Only | 32'h0000_0001 |
Returns 1 to show the core is active. |
32'h0000_0008 |
DATA0 | Read/Write | 32'h0000_0000 |
User data register 0. |
32'h0000_000C |
DATA1 | Read/Write | 32'h0000_0000 |
User data register 1. |
The self-checking testbench (spi2axilite_tb.v) has fully verified the design inside ModelSim with 0 Errors and 0 Warnings:
- System Reset: Checked that registers reset to defaults and STATUS is preloaded with
1. - SPI WRITE: Value
0xAAsuccessfully written to the registerDATA0(offset 0x08). - SPI READ: Value
0xAAsuccessfully read back and shifted onto themisoline in real-time. - CS_N Abort: Confirmed that deasserting
cs_nmid-transaction immediately resets the FSM toIDLE. - Invalid Command Rejection: Rejects unsupported opcodes like
0xFF, leaving register configurations unchanged.
A dedicated presentation script sim/run_presentation.do is included to format the ModelSim waveform window:
- Dividers: Groups waveforms into SPI, FSM, AXI, Register Bank, and CDC Debug signals.
- Hexadecimal Radix: Forces clear hex layout on address and register buses for easy verification.
- State Decoders: Decodes raw binary FSM state variables into clear ASCII labels (
IDLE,AXI_WRITE) inside the wave viewer.
- Navigate to the simulation folder:
cd "D:\program files\spi2axilite\spi2axilite\sim"
- Launch ModelSim and run the presentation script:
vsim -do "do compile.do; do run_presentation.do"
Paste the following command directly into the ModelSim command console:
cd {D:/program files/spi2axilite/spi2axilite/sim}; do compile.do; do run_presentation.do- Parity Checking: Add parity bits to incoming serial transactions to detect transmission errors before AXI writes occur.
- Interrupt Support: Add a hardware interrupt pin to alert the external master as soon as internal registers change value.
- Full AXI Support: Extend AXI4-Lite master logic to support standard AXI4 burst modes for high-speed block data transfers.
