[转]vivado硬件调试——mark_debug

最近两个月开始用Vivado做项目,之前一直用ISE开发,个人觉得ISE方便好用,而Vivado编译又慢,还占内存,打开一个工程就需要好半天,可视化界面感觉也没什么用处,不如模块化的代码来的简单,而且还有一些bug。无奈xilinx公司不再开发ISE,到14.7就结束了,以后的芯片只能用Vivado做设计了,只能用它了,现在已经更新到了2014.4版本,我现在用的是2013.4版本,开发板是zedboard。

用Vivado进行硬件调试,就是要插入ila核,即“集成逻辑分析仪”,然后将想要引出来观察的信号连到这个核的probe上。

首先第一步,需要把想要观测的信号标记出来,即mark_debug,有两种mark_debug的方法,我用verilog写了一个简单的流水灯程序,只有几行代码,如下:

  1. module main(
  2. input            clk,
  3. input            rst,
  4. output reg [7:0] led
  5.     );
  6. (*mark_debug = "true"*)reg [23:0] counter;
  7. always @(posedge clk) begin
  8. if(rst) begin
  9. counter <= 0;
  10. led <= 8'b00000001;
  11. end
  12. else counter <= counter + 1;
  13. if (counter == 24'hffffff)
  14. led <= {led[6:0],led[7]};
  15. end
  16.  
  17. endmodule
例如,要观察counter信号的波形,那么在第7行定义reg型信号counter时,前面加上(*mark_debug=“true”*),这样就把counter信号标记了出来。如果用vhdl语言实现的话,这句话用该这样写:
  1. signal counter : std_logic_vector (23 downto 0);
  2. attribute mark_debug: string;
  3. attribute mark_debug of counter : signal is "true";
另外添加xdc约束文件,内容如下:
  1. set_property PACKAGE_PIN Y9 [get_ports clk]
  2. set_property PACKAGE_PIN T18 [get_ports rst]
  3.  
  4. set_property IOSTANDARD LVCMOS33 [get_ports clk]
  5. set_property IOSTANDARD LVCMOS18 [get_ports rst]
  6.  
  7. set_property PACKAGE_PIN T22 [get_ports {led[0]}]
  8. set_property PACKAGE_PIN T21 [get_ports {led[1]}]
  9. set_property PACKAGE_PIN U22 [get_ports {led[2]}]
  10. set_property PACKAGE_PIN U21 [get_ports {led[3]}]
  11. set_property PACKAGE_PIN V22 [get_ports {led[4]}]
  12. set_property PACKAGE_PIN W22 [get_ports {led[5]}]
  13. set_property PACKAGE_PIN U19 [get_ports {led[6]}]
  14. set_property PACKAGE_PIN U14 [get_ports {led[7]}]
  15.  
  16. set_property IOSTANDARD LVCMOS33 [get_ports {led[0]}]
  17. set_property IOSTANDARD LVCMOS33 [get_ports {led[1]}]
  18. set_property IOSTANDARD LVCMOS33 [get_ports {led[2]}]
  19. set_property IOSTANDARD LVCMOS33 [get_ports {led[3]}]
  20. set_property IOSTANDARD LVCMOS33 [get_ports {led[4]}]
  21. set_property IOSTANDARD LVCMOS33 [get_ports {led[5]}]
  22. set_property IOSTANDARD LVCMOS33 [get_ports {led[6]}]
  23. set_property IOSTANDARD LVCMOS33 [get_ports {led[7]}]
之后run synthesis综合,之后open synthesized design,在左上角选择debug layout,在debug窗口中netlist看到counter信号前面有一个绿色的小蜘蛛,表示counter信号被标记出来了。
这其实是一种比较繁琐的方法,更为方便的方法是,直接综合工程,在之后打开综合设计,在netlist中直接选中想要查看的信号,右键选择mark debug,即可将信号标记出来。
但是采用第一种方式的好处是,如果工程比较复杂的话,一些信号可能会被综合优化掉,加上模块层层实例化,在netlist中可能找不到要观测的信号,这时在代码里面mark_debug,依旧可以将该信号引出来。
 
接着第二步就是插入调试内核了,在Vivado界面下方,找到Unassigned Debug Nets,右键选择 set up debug,在接下来的对话框中列出了counter信号的lk domain是CLK_IBUG_BUFG,其trig和data项都打了对勾,表示counter信号既作为触发信号也作为数据信号。
 
选择next,在接下来的对话框中将enable advanced trigger mode 和enable basic capture mode勾选上,继续next,最后finish,在界面下方的debug窗口显示如下:
 
 
右键dbg_hub,选择implement debug cores,接着在打开的schematic中,可以看见插入的ila核,其probe端口与counter相连,打开xdc文件,在最后几行多出来这几行代码:
  1. create_debug_core u_ila_0 labtools_ila_v3
  2. set_property ALL_PROBE_SAME_MU true [get_debug_cores u_ila_0]
  3. set_property ALL_PROBE_SAME_MU_CNT 4 [get_debug_cores u_ila_0]
  4. set_property C_ADV_TRIGGER true [get_debug_cores u_ila_0]
  5. set_property C_DATA_DEPTH 1024 [get_debug_cores u_ila_0]
  6. set_property C_EN_STRG_QUAL true [get_debug_cores u_ila_0]
  7. set_property C_INPUT_PIPE_STAGES 0 [get_debug_cores u_ila_0]
  8. set_property C_TRIGIN_EN false [get_debug_cores u_ila_0]
  9. set_property C_TRIGOUT_EN false [get_debug_cores u_ila_0]
  10. set_property port_width 1 [get_debug_ports u_ila_0/clk]
  11. connect_debug_port u_ila_0/clk [get_nets [list clk_IBUF_BUFG]]
  12. set_property port_width 24 [get_debug_ports u_ila_0/probe0]
  13. connect_debug_port u_ila_0/probe0 [get_nets [list {counter[0]} {counter[1]} {counter[2]} {counter[3]} {counter[4]} {counter[5]} {counter[6]} {counter[7]} {counter[8]} {counter[9]} {counter[10]} {counter[11]} {counter[12]} {counter[13]} {counter[14]} {counter[15]} {counter[16]} {counter[17]} {counter[18]} {counter[19]} {counter[20]} {counter[21]} {counter[22]} {counter[23]}]]
  14. set_property C_USER_SCAN_CHAIN 1 [get_debug_cores dbg_hub]

到此为止,成功将要观察的信号引出来,完成了插入调试内核,接着直接运行generate bitstream,即可生成bit文件。

最后一步,连上zedboard开始调试,用impact将bit文件下载到板卡上,或者在后面hardware manager中选择program device也可以。打开hardware manager,然后open new target,一直next直到结束,即可打开Vivado硬件逻辑分析仪,如下图所示:

要查看波形,必须要有信号触发,将counter信号拖入右方的basic trigger setup窗口,可以设置,想要counter等于何值时触发,右键counter,选择run trigger,并将counter信号添加到波形窗口中,接着便可以在打开的波形窗口中观察counter信号的变化。

硬件调试的流程大致如上述所示,这只是非常简单的一个例子,作为对官网视频教程的一个翻译加补充吧,如果工程较大的话,debug时还会遇到各种问题,就需要一步步慢慢摸索解决啦。

参考官网视频教程,另外在xilinx官网上也可以搜到debug的文档:

http://china.xilinx.com/training/vivado/inserting-debug-cores-into-the-design.htm
http://china.xilinx.com/training/vivado/programming-and-debugging-design-in-hardware.htm

附加两点我曾遇到的小问题:

(1)在进行综合之前,需要将先将xdc约束文件添加到工程中,否则最后write bitstream时出错。Vivado的一个问题就是,有好多ise中综合时就能检测出的错误,而Vivado要等到生成bitstream时才报错。

(2)在打开hardware manager之后,提示vcseserver没有开启,在vivado/2013.4/bin下面运行vcseserver的bat程序即可。

猜你喜欢

转载自www.cnblogs.com/tubujia/p/9242895.html