1. 程式人生 > >vivado----fpga硬體除錯 (一)----mark_debug

vivado----fpga硬體除錯 (一)----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. 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. set_property IOSTANDARD LVCMOS33 [get_ports clk]
  4. set_property IOSTANDARD LVCMOS18 [get_ports rst]
  5. set_property PACKAGE_PIN T22 [get_ports {led[0]}]
  6. set_property PACKAGE_PIN T21 [get_ports {led[1]}]
  7. set_property PACKAGE_PIN U22 [get_ports {led[2]}]
  8. set_property PACKAGE_PIN U21 [get_ports {led[3]}]
  9. set_property PACKAGE_PIN V22 [get_ports {led[4]}]
  10. set_property PACKAGE_PIN W22 [get_ports {led[5]}]
  11. set_property PACKAGE_PIN U19 [get_ports {led[6]}]
  12. set_property PACKAGE_PIN U14 [get_ports {led[7]}]
  13. set_property IOSTANDARD LVCMOS33 [get_ports {led[0]}]
  14. set_property IOSTANDARD LVCMOS33 [get_ports {led[1]}]
  15. set_property IOSTANDARD LVCMOS33 [get_ports {led[2]}]
  16. set_property IOSTANDARD LVCMOS33 [get_ports {led[3]}]
  17. set_property IOSTANDARD LVCMOS33 [get_ports {led[4]}]
  18. set_property IOSTANDARD LVCMOS33 [get_ports {led[5]}]
  19. set_property IOSTANDARD LVCMOS33 [get_ports {led[6]}]
  20. set_property IOSTANDARD LVCMOS33 [get_ports {led[7]}]
之後run synthesis綜合,之後open synthesized design,在左上角選擇debug layout,在debug視窗中netlist看到counter訊號前面有一個綠色的小蜘蛛,表示counter訊號被標記出來了。

     在訊號前面加入mark debug的好處

      這其實是一種比較繁瑣的方法,更為方便的方法是,直接綜合工程,在之後開啟綜合設計,在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.htmhttp://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程式即可。