Create a Testbench for Simulating the AXI4-Lite Interface


In part 2, we have built the AXI4-Lite wrapper for GCD core and counters. In this part, we are going to create a testbench file for simulating the AXI4-Lite wrapper. This testbench simulates as if the CPU writes/reads address/data to or from the AXI4-Lite wrapper.

You can get the full source code of this part from here.

Testbench File

The following code shows the testbench file for simulating the axi_gcd_performance.v. First, we instantiate the axi_gcd_performance module as dut, in line 26-47. Then, we define Verilog task for writing (axi_write) and reading (axi_read) to and from the dut.

To simulate the AXI4-Lite write signal, we should set the address (on s_axi_awaddr) of the register that we want to write to, and set the s_axi_awvalid to one. After that, set the data on the s_axi_wdata, and set the s_axi_wvalid to one.

To simulate the AXI4-Lite read signal, we should set the address (on s_axi_araddr) of the register that we want to read from, and set the s_axi_arvalid to one. After that, the data will be available on the s_axi_ardata.

In line 76-88, we can send the input A and B to the GCD core. Then, we should initiate the operation by writing one to the START bit in status register.  After that, we should wait for several clock cycles until the operation is finished. In real implementation, we should not wait for several clock cycles. Instead, we should wait until the READY bit in status register becomes one. We may use polling or interrupt method to wait for this bit becomes one. Finally, read the output R.


The simulation was done using Vivado simulator. The following figure shows the timing diagram of the AXI4-Lite wrapper. Firstly, we write the write address. Secondly, we write the write data. Then, the GCD core starts the operation. Thirdly, we write the read address. Fourthly, we read the read data.

Every address/data transaction in AXI4-Lite occurs if both of the *valid and *ready signal are one. This is called handshake. The AXI4 master (CPU) will stretch the *valid signal if the *ready signal is zero, i.e. it waits until the *read becomes one. You can learn more on this AXI4-Lite protocol from the AXI protocol specification.


In this tutorial, we have built the testbench file for simulating the AXI4-Lite GCD. This testbench file is useful for verifying our AXI4-Lite module before we synthesize the design. Furthermore, by simulating the AXI4-Lite module, we can have a better understanding on how the AXI4-Lite protocol works.

Next: Test the GCD Core with Bare Metal Application