文章目录
本文使用工程源码已上传 https://download.csdn.net/download/botao_li/10891304
从本文档开始将介绍PS和PL之间通过AXI总线互联。
三种AXI总线协议为
- AXI_LITE:性能较低的地址映射传输,一次只能传输4字节
- AXI_STREAM:高速流数据传输,无地址映射,不能直接与PS连接
- AXI(又称AXI_FULL):性能较高的地址映射传输
AXI_LITE一般用于小规模的数据交互,比如参数、指令或者状态信息
本文档用AXI_LITE总线实现2项功能:
- PS读写PL的寄存器读取板上按钮状态控制LED灯开关
- PL读写PS的DDR内存
axi lite时序
下文中生成的AXI_LITE接口的IP模块自带的示例代码可以修改后使用,AXI_LITE的接口时序来源于示例代码的参考
写操作时序
- master:同时设置awvalid和wvalid有效
- slave:等待awvalid和wvalid同时有效,同时将awready和wready设置1
- slave:在awvalid awready wvalid wready同时为1的情况下,bvalid设1,同时取出awaddr和wdata
- master:收到awready将awvalid设0,收到wready将wvalid设0
- master:收到bvalid将bready设1,下个时钟周期设0
- slave:收到bready将bvalid设0
读操作时序
- master:设置arvalidy为1
- slave:收到arvalid将arready设1,下个时钟周期设0
- slave:在arready arvalid同时为1的情况下,rvalid设1,axi_rresp设0有效
- master:收到arready将arvalid设0
- master:收到rvalid将rready设1,下个时钟周期设0
- slave:收到rready将rvalid设1
- master:在rready rvalid同时为1的情况下,检查rdata数值
建立工程
与之前相同的方法建立zcu102的Vivado工程
配置Zynq模块
建立Block Design,并添加Zynq模块
选择Run Block Automation
在弹出窗口中按照默认配置选择OK
双击打开Zynq模块配置,在PS-PL Configuration页进行如下配置
使用pl_clk0作为PL端工作时钟,并且连接2个AXI接口的aclk
自定义Slave AXI_LITE接口的IP模块
在Tools菜单选择Create and Package New IP
在弹出窗口中选中Create AXI4 Peripheral
选择Edit IP后点击Finish
之后弹出当前IP的Vivado工程
在Sources窗口双击打开接口模块
在代码注释中指示的位置**(非必须)**添加自定义的模块端口
注意:端口定义必须加上wire
根据代码所示,前述步骤配置的4个32位寄存器分别为slv_reg0~3
若当前IP在PS端的基地址为base_addr,则slv_reg0读写地址为base_addr,slv_reg1读写地址为base_addr+4,svl_reg2和3以此类推
将slv_reg0用于写入PL端LED,slv_reg1用于读取PL端按钮
根据注释位置(位置非必须)添加以下代码
并修改读操作赋值
打开IP的顶层模块,进行如下修改
在当前IP的Vivado工程界面,在Tools菜单选择Create and Package IP
选择Package your current project
在弹出窗口选择Overwrite
最后点击Finish
完成后关闭当前IP的Vivado工程
自定义Master AXI_LITE接口的IP模块
参考[Slave AXI_LITE的模块的生成](#自定义Slave AXI_LITE接口的IP模块),进行如下配置
最后选择Edit IP打开IP的Vivado工程
由于默认生成的示例代码过于复杂,因此根据AXI_LITE接口时序全部重写,并添加读写接口
进入Vivado工程后,使用与[自定义Slave接口IP相同的方式](#自定义Slave AXI_LITE接口的IP模块)修改接口模块和顶层模块如下
接口模块代码
`timescale 1 ns / 1 ps
module master_axi_lite_v1_0_M00_AXI #
(
// Users to add parameters here
// User parameters ends
// Do not modify the parameters beyond this line
// The master will start generating data from the C_M_START_DATA_VALUE value
parameter C_M_START_DATA_VALUE = 32'hAA000000,
// The master requires a target slave base address.
// The master will initiate read and write transactions on the slave with base address specified here as a parameter.
parameter C_M_TARGET_SLAVE_BASE_ADDR = 32'h40000000,
// Width of M_AXI address bus.
// The master generates the read and write addresses of width specified as C_M_AXI_ADDR_WIDTH.
parameter integer C_M_AXI_ADDR_WIDTH = 32,
// Width of M_AXI data bus.
// The master issues write data and accept read data where the width of the data bus is C_M_AXI_DATA_WIDTH
parameter integer C_M_AXI_DATA_WIDTH = 32,
// Transaction number is the number of write
// and read transactions the master will perform as a part of this example memory test.
parameter integer C_M_TRANSACTIONS_NUM = 4
)
(
// Users to add ports here
//写接口
input wire wr_en,//写使能
input wire [31:0] wr_addr,//相对写地址,与写使能对齐
input wire [31:0] wr_data,//写数据,与写使能对齐
output wire wr_done,//写结束,单个时钟周期有效
//读接口
input wire rd_en,//读使能,单个时钟周期有效
input wire [31:0] rd_addr,//相对读地址,与读使能对齐
output wire rd_valid,//读出数据有效,单个时钟周期有效
output wire [31:0] rd_data,//读出数据
output wire rd_done,//读结束,单个时钟周期有效
// User ports ends
// Do not modify the ports beyond this line
// // Initiate AXI transactions
// input wire INIT_AXI_TXN,
// // Asserts when ERROR is detected
// output reg ERROR,
// // Asserts when AXI transactions is complete
// output wire TXN_DONE,
// AXI clock signal
input wire M_AXI_ACLK,
// AXI active low reset signal
input wire M_AXI_ARESETN,
// Master Interface Write Address Channel ports. Write address (issued by master)
output wire [C_M_AXI_ADDR_WIDTH-1 : 0] M_AXI_AWADDR,
// Write channel Protection type.
// This signal indicates the privilege and security level of the transaction,
// and whether the transaction is a data access or an instruction access.
output wire [2 : 0] M_AXI_AWPROT,
// Write address valid.
// This signal indicates that the master signaling valid write address and control information.
output wire M_AXI_AWVALID,
// Write address ready.
// This signal indicates that the slave is ready to accept an address and associated control signals.
input wire M_AXI_AWREADY,
// Master Interface Write Data Channel ports. Write data (issued by master)
output wire [C_M_AXI_DA