Access FPGA External Memory Using MATLAB as AXI Master

This example shows how to use MATLAB as AXI Master to access external DDR memories connected to an FPGA. The FPGA design instantiates an Intel DDR memory controller for accessing the DDR memories. This memory controller provides a memory-mapped slave interface for read and write operations from the FPGA. The MATLAB as AXI Master feature provides an AXI master IP that allows MATLAB to access any memory-mapped slave IPs in the FPGA. In this example, we demonstrate how to integrate the JTAG MATLAB as AXI Master IP or Ethernet MATLAB as AXI Master IP into a Qsys design, and then read and write the DDR memory from MATLAB.

Requirements

  • Intel® Quartus Prime™ of compatible version

  • Arrow® DECA MAX10 FPGA development kit

  • HDL Verifier™ Support Package for Intel FPGA Boards

  • USB-Blaster II™ Download Cable

  • Ethernet Cable

Set Up for Using JTAG MATLAB as AXI Master

Step 1: Set up FPGA board. Make sure that the DECA board is connected to the host computer via the USB JTAG cable.

Step 2: Prepare example in MATLAB

Set up the Intel Quartus Prime tool path. Use your own Intel Quartus Prime installation path when executing the command. For example:

>> hdlsetuptoolpath('ToolName','Altera Quartus II',  'ToolPath','C:\intelFPGA\18.0\quartus\bin64\quartus.exe');

Create a folder outside the scope of your MATLAB installation folder into which you can copy the example files. The folder must be writable. This example assumes that the folder is located at C:\MyTests.

Start MATLAB and set the current directory in MATLAB to the folder you just created. For example:

>> cd C:\MyTests

Copy the example files into current directory by executing this command in MATLAB.

>> copyAlteraFPGAExampleFiles('aximaster')

Create a Quartus project for this example. This tcl script creates the Quartus project, and adds the design files to the project.

>> system('quartus_sh -t create_project_deca.tcl')

This command takes a few seconds to finish. When it is done, a Quartus project named "aximaster_deca.qpf" is created in your current directory.

Step 3: Configure Quartus Prime Project to use MATLAB as AXI Master. Copy the IP to the project directory using the following command:

>>  setupAXIMasterForQuartus('aximaster_deca.qpf')

Next, open the generated Quartus project in GUI mode. You can double-click the project in a file browser, or execute this command in MATLAB:

>> system('quartus aximaster_deca.qpf &')

Step 4: Inspect JTAG MATLAB as AXI Master IP in Qsys Design (Optional)

In the Quartus GUI, open the Qsys design file system.qsys and inspect how the MATLAB as AXI Master IP is connected to the DDR controller.

Step 5: Generate FPGA programming file and program FPGA. To generate the FPGA programming file , click the "Start Compilation" button in Quartus Prime.

After generating the programming file, program the FPGA in MATLAB using the following command:

>> filProgramFPGA('Altera','output_files/aximaster_deca.sof',1)

Set Up for Using Ethernet MATLAB as AXI Master

Step 1: Set up FPGA board. Make sure that the DECA board is connected to the host computer via both the USB Blaster II Download Cable and the Ethernet cable.

Step 2: Prepare example in MATLAB.

Set up the Intel Quartus Prime tool path. Use your own Intel Quartus Prime installation path when executing the command. For example:

>> hdlsetuptoolpath('ToolName','Altera Quartus II',  'ToolPath','C:\intelFPGA\18.0\quartus\bin64\quartus.exe');

Create a folder outside the scope of your MATLAB installation folder. The folder must be writable. This example assumes that the folder is located at C:\MyTests.

Start MATLAB and set the current directory in MATLAB to the folder you just created. For example:

>> cd C:\MyTests

Copy the example files into current directory by executing this command in MATLAB

>> copyAlteraFPGAExampleFiles('eth_aximaster')

Create a Quartus project for this example. This tcl script would create the Quartus project, and add the design files we created to the project

>> system('quartus_sh -t create_project_eth_deca.tcl')

When it is done, a Quartus project named "eth_aximaster_deca.qpf" is created in your current directory.

Step 3: Configure Quartus Prime Project to use the Ethernet MATLAB as AXI Master. Copy the IP to the project directory using the following command:

>>  setupAXIMasterForQuartus('eth_aximaster_deca.qpf')

Next, open the generated Quartus project in GUI mode. Double-click the project in a file browser, or execute this command in MATLAB:

>> system('quartus eth_aximaster_deca.qpf &')

Step 4: Inspect Ethernet MATLAB as AXI Master IP in Qsys Design (Optional)

In the Quartus GUI, open the Qsys design file aximaster.qsys and inspect how the MATLAB as AXI Master IP is connected to the DDR controller.

The Ethernet based MATLAB as AXI Master IP has been assigned a target IP Address of 192.168.1.2 and UDP Port value of 50101. These values can be changed by double clicking on the ethernet_mac_hub_IP in Qsys.

Step 5: Generate FPGA programming file and program FPGA. To generate the FPGA programming file , click the "Start Compilation" button in Quartus Prime.

After generating the programming file, program the FPGA in MATLAB using the following command:

>> filProgramFPGA('Altera','output_files/eth_aximaster_deca.sof',1)

Read and Write Operations to the FPGA

After programming the FPGA, you can read and write into the AXI slaves connected to the MATLAB as AXI Master IP. In this example, the data will be written to the DDR memory connected to the FPGA, and retrieved back into MATLAB.

First, create the AXI master object in MATLAB

If using JTAG MATLAB as AXI Master:

>> h = aximaster('Intel')

If using Ethernet MATLAB as AXI Master:

>> h = aximaster('Intel','interface','UDP','deviceAddress','192.168.1.2','port','50101');

Then run these two commands to write a single word of value 100 into DDR memory at address 0 and read it back by using the AXI master object:

>> writememory(h, 0,100)
>> readmemory(h, 0,1)

You can also read and write large vectors of data into DDR memory using a single read/write command in MATLAB. These commands automatically break down the large amount of data into smaller bursts so that they can be transferred via AXI4 protocol. The function uses the largest possible burst size for each burst to maximize the throughput performance. The following commands write 10000 words into DDR memory and read them back. It also checks if the read back data are correct and reports the execution time.

>> address = 0;
>> data = 1:100000;
>> writememory(h, address, data);
>> r = readmemory(h, address, 100000);
>> assert(all(r==data));