Open this Example

Random Access of External Memory

The example shows how to model external memory accesses from FPGA for rotating an ASCII art image. Many applications require FPGA to access memory in random fashion as per the requirements of algorithm. You will learn how to design memory address generation along with other AXI4 master signals to read and write specific regions of memory using SoC Blockset. You will simulate, implement and verify your design on hardware.

Contents

Supported hardware platforms:

Design Task

The ASCII art image is encoded as 24-by-64 matrix of uint8 characters. The design task is to rotate the image by modeling AXI4 Master interfaces in FPGA logic for external memory access. By simulating the design with external memory model and the AXI4 protocol, you verify the behavior at application design time. This saves time otherwise spent in debugging the design on hardware during the implementation phase.

The overall dataflow is as described in figure below. The image is stored in the external memory at the memory region from address 0x00000000 to 0x000017FF. FPGA algorithm reads the image from this region and rotates it by writing it in the reverse order into the memory region from 0x00001800. Finally, the data is read back from the memory.

Model Structure

The models are structured using Model references. Top model 'soc_image_rotation' includes the FPGA model 'soc_image_rotation_fpga' using Model block as model reference.

The top model covers the following areas:

FPGA model implements the algorithm in three subsystems, AXI4MasterRead, ReverseDataOrder and AXI4MasterWrite. Open FPGA subsystem for image rotation:

As the positive edge of start signal is detected, AXIMasterRead reads one line of image data and deliver it to ReverseDataOrder for reverses the order of data. The reversed data is then written to external memory by AXIMasterWrite subsystem. Once the data for one line is written, it sends a signal request_next_line to trigger reading of next line by AXIMasterRead. This cycle continues until all lines of the image are processed.

Open AXI4MasterReadController and AXI4MasterWriteController blocks to inspect the MATLAB® code for AXI4 Master interfaces. These blocks design the addressing logic for read and write operations as per AXI4 protocol. SoC Blockset supports AXI4 Master protocol and for timing diagrams of AXI4 signals, please refer to Model Design for AXI4 Master Interface Generation.

Simulation

Run the model and open the Logic analyzer from the FPGA model. Notice the following key points:

The input and output images are plotted at the end of simulation:

Implementation

Following products are required for this section:

To implement the model on a supported FPGA board, use the SoC Builder application. Make sure you have installed required products and FPGA vendor software before implementation.

Open
<docid:soc_ref#mw_c7ffe7b7-da90-4248-9010-19b4413be7ab SoC Builder> from
the Tools menu and follow these steps:

The FPGA synthesis may take more than 30 minutes to complete. To save time, you may want to use the provided pre-generated bitstream by following these steps:

>> copyfile(fullfile(matlabroot,'toolbox','soc','socexamples','bitstreams','soc_image_rotation-zc706.bit'), './soc_prj');

To run this example, copy the example test bench to your project folder.

>> copyfile(fullfile(matlabroot,'toolbox','soc','socexamples','soc_image_rotation_aximaster.m'), './soc_prj','f');

Enter the following command to run the test bench:

>> soc_image_rotation_aximaster

The test bench performs the following operations:

If your FPGA board is not Xilinx Zynq ZC706 evaluation kit you need to do the following settings in the configuration parameters of the top model before launching the SoC Builder.

Available pre-generated bitstreams are:

Modify the copyfile command and example test bench to match your board and selected project folder as appropriate. Note that pre-generated bitstream may not work if you customized the memory map.

Enter the following command to close the top model and FPGA model:

Conclusion

This example shows modeling of AXI4 Master interfaces for accessing external memory in random fashion using SoC Blockset by rotating an ASCII art image. You can use this as a guide to design your own algorithm to access memory directly using AXI4 Master protocol.