在之前的“Xilinx 7系列FPGA部分重配置【1】”中已經較為詳細地記錄了分別在工程模式(Project Mode)和非工程模式(Non-Project Mode)下、使用7系列的Xilinx FPGA芯片創建部分重配置(Partial Reconfiguration,PR)項目、並生成相應的bit配置文件的流程。
前述流程是一個較為基本的PR項目操作流程、在UG947和UG909文檔的示范例中都有說明,自己也按照前述的流程、參考UG文檔、在Xilinx Arty評估板上(xc7a35ticsg324-1L)創建了兩個簡單的PR項目、對PR功能成功進行了實現和驗證。評估板上的下載和調試接口是USB JTAG,對FPGA的下載和配置使用的是JTAG模式。根據UG470,FPGA的配置模式主要包含以下幾種:
在粗略地整體瀏覽完UG470之后意識到,JTAG模式是一種健壯性相對比較好的配置模式。
而前段時間工作項目上、板上FPGA的型號為xc7a35tftg256-1、配置模式為從串模式、FPGA的配置文件由另外一個stm32芯片進行加載,並且整個PR項目的復雜度遠非UG文檔上的示例所可比擬(由於實際應用的需求,接手的FPGA工程的復雜度主要體現在user IO的使用率極高、幾乎用完了全部可分配的管腳),所以按照前述PR項目的創建和配置文件生成流程進行操作之后、一直無法通過PR驗證。
后來在仔細參考了當前項目之前的降級版本的項目片上FPGA的工程文件包之后、在VIVADO的批處理模式下(batch mode)、運行編寫的TCL腳本、使用和之前一樣的代碼包作為源文件、重新生成了FPGA配置文件,在測試板上實驗之后、PR功能驗證通過。所以在這里將TCL腳本中、相對前述的操作流程作出更改的幾個點進行記錄,以便日后參考。
1、設計思路改變
自己在之前的PR操作中一直采取的思路是:
begin
分別生成頂層的邏輯綜合dcp(末尾有RP(Reconfigurable Partition)黑盒子定義)、以及N種RM的綜合dcp-
使用頂層+RM1拼接生成第一種全局配置-
挖空RP(updata_design -black_box)得到static.dcp-
打開static.dcp-
填入第二種RM-
實現第二個全局配置-
……
填入第N種RM-
實現第N個全局配置
end
而參考了前人的TCL腳本之后、現在采取的創建思路是:
begin
直接利用全部的.v文件生成第一種完整的配置(TOP.v文件末尾不包含對RP的黑盒子定義)-
將RP挖空(updata_design -black_box)、得到static.dcp-
綜合第二中RM、執行reset_timing命令、保存為RM_2nd.dcp
填入第二種RM-
實現第二個全局配置-
……
填入第N種RM-
實現第N個全局配置
end
需要注意的是,在保存生成的第二個RM的綜合dcp之前進行了一個reset_timing的命令,這在之前做的時候都是沒注意過、也沒采用過的。
2、綜合命令選項
執行synth_design時需要指定的屬性變量
如果對A模塊做綜合時、B模塊中的參數需要通過A模塊傳遞過去,那么在綜合時可以使用-generic屬性,格式如下:
-generic <name>=<value> - (Optional)
The value of a VHDL generic entity, or of a Verilog parameter. The -generic option can be used to override the assigned values of parameters in the RTL design sources. However it can only override parameters at the top level of the design. Repeat the -generic option multiple times in the synth_design command for each generic or parameter value to be defined.
在進行PR項目中還進行設置了的屬性包括
-flatten_hierarchy <arg> - (Optional)
Flatten the hierarchy of the design during LUT mapping. The valid values are:
* rebuilt - This will attempt to rebuild the original hierarchy of the
RTL design after synthesis has completed. This is the default setting.
* full - Flatten the hierarchy of the design.
* none - Do not flatten the hierarchy of the design. This will preserve
the hierarchy of the design, but will also limit the design optimization that can be performed by the synthesis tool.
設計中指定的是none。
-no_lc - (Optional)
Disable the default LUT combining feature of Vivado synthesis.
設計中使用了-no_lc。
-fsm_extraction <arg> - (Optional)
Finite state machine (FSM) encoding is automatic (auto) in Vivado synthesis by default. This option enables state machine identification and specifies the type of encoding that should be applied. Valid values are: off, one_hot, sequential, johnson, gray, auto.
設計中指定的是off
綜合后續RM時還指定了OOT模式。
-mode [ default | out_of_context ] - (Optional)
Out of Context mode specifies the synthesis of an IP module, or block module, for use in an out-of-context design flow. This mode turns off I/O buffer insertion for the module, and marks the module as OOC, to facilitate its use in the tool flow. The block can also be implemented for analysis purposes. Refer to the Vivado Design Suite User Guide: Designing with IP (UG896) or the Vivado Design Suite User Guide: Hierarchical Design (UG905) for more information.
3、布局布線、實現命令選項
執行place_design命令時需要指定的屬性變量:
-directive <arg> - (Optional)
Direct placement to achieve specific design objectives. Only one directive can be specified for a single place_design command, and values are case-sensitive.
* SSI_SpreadLogic_high - Distribute logic across SLRs. SSI_SpreadLogic_high achieves the highest level of distribution.
* SSI_SpreadLogic_low - Distribute logic across SLRs. SSI_SpreadLogic_low achieves a minimum level of logic distribution, while reducing placement runtime.
還可以為該-directive屬性指定其它很多種值、這里沒有一一列舉,設計中指定的是SSI_SpreadLogic_high
在執行最后一步的write_bitstream命令之前需要進行的設定包括:
set_property CONFIG_MODE S_SERIAL [current_design]
set_property BITSTREAM.CONFIG.PERSIST Yes [current_design]
set_property BITSTREAM.SEU.ESSENTIALBITS YES [current_design]
set_property BITSTREAM.GENERAL.COMPRESS TRUE [current_design]
其中第三條根據字面意思是增強FPGA的SEU方面性能的設定、未在UG文檔中找到相應說明,其余語句的含義依次如下:
set_property CONFIG_MODE S_SERIAL [current_design]
設定FPGA的配置模式為從串
set_property BITSTREAM.CONFIG.PERSIST Yes [current_design]
為FPGA的配置添加全局PERSIST屬性
set_property BITSTREAM.GENERAL.COMPRESS TRUE [current_design]
選擇在生成bit配置文件時進行壓縮處理、提高生成速度
其中的第二條語句,查閱UG908可以看到:
根據其大意,該參數默認值為no,在進行PR項目、配置模式為串行等情況下需要將該參數設置為yes。
在UG470中對persist option的說明如下(P128):
The persist bitstream option maintains the configuration logic access to the multi-function configuration pins after configuration. The persist option is primarily used to maintain the SelectMAP port after configuration for readback access. Persist is not needed for JTAG configuration since the JTAG port is dedicated and always available. Persist and ICAP cannot be used at the same time. PERSIST is also not recommended for standard Master SPI/BPI configuration mode setups. For advanced tandem Master SPI/BPI configuration mode setups refer to XAPP1179, for the PERSIST option usage.
The persist option can also be used to reconfigure the device from an external controller without pulsing the PROGRAM_B pin or using the JTAG port. The multi-function pins that persist depend on the configuration mode pin settings, and are the same as those shown for each configuration mode in Table 2-2, page 22 and Table 2-3, page 23, except that PUDC_B and DOUT_CSO_B never persist. Any I/O pins that persist cannot be used as I/O in the user design. Use the CONFIG_MODE constraint to reserve the correct pins during implementation of the design. Persisted I/O use the general-purpose I/O standard default of LVCMOS, 12 mA drive, Slow slew rate.
4、意外錯誤記錄
(1)BITSTREAM.CONFIG.PERSIST設置和7系列FPGA芯片的RS[1:0]管腳相關
在執行上述第三點最后的“set_property BITSTREAM.CONFIG.PERSIST Yes [current_design]”語句之后、執行write_bitstream命令之后報錯,顯示不能為項目中的某一個引腳添加該PERSIST屬性、當把項目中使用到該引腳的代碼、以及該引腳對應的約束文件行刪掉之后,write_bitstream命令順利執行。具體到當前項目,使用的FPGA型號為xc7a35tftg256-1、出現錯誤提示的引腳號為H14(以及G15)。
查閱對應的芯片管腳封裝手冊UG475可以看到,這兩個腳在封裝圖里面的小方塊中標記為r,如下圖:
UG475文檔結合UG470對r的注釋為:
Pin Name |
Type |
Direction |
Description |
RS0 or RS1 |
Multi-function |
Output |
The RS0 and RS1 pins are revision selection output pins,intended to drive upper address lines on a parallel flashmemory. Normally, RS0 and RS1 are high-Z duringconfiguration. However, the FPGA can drive the RS0 and RS1 pins under two possible conditions. When theConfigFallback option is enabled, the FPGA drives RS0and RS1 Low during the fallback configuration processthat follows a detected configuration error. When auser-invoked MultiBoot configuration is initiated, the FPGA can drive the RS0 and RS1 pins to a user-defined state during the MultiBoot configuration process. If fallback is disabled (default) and if MultiBoot is notused, or if SPI mode is used, then RS0 and RS1 are high-Z and can be left unconnected. |
在UG470中對這兩個腳的說明是:
RS0 and RS1 are only driven when a MultiBoot event is initiated or when the ConfigFallback option is enabled and a Fallback event occurs.
Otherwise, RS0 and RS1 are high-Z. When using the RS[1:0] pins for configuration it is recommended not to use them in User mode.
P62:
RS[1:0] are typically high impedance. However, a MultiBoot (or Fallback event in BPI mode) can cause RS[1:0] to drive High or Low.
P145:
RS Pins
The dual-purpose RS pins are disabled by default. The RS pins drive Low during a fallback for BPI or Master SelectMAP mode, but do not drive Low during SPI mode. For initial MultiBoot systems, the RS pins are wired to upper address bits of the flash and strapped High or Low with a pull-up or pull-down resistor, respectively. At power up, the system boots to the upper address space defined by the pull-up resistors on the RS and address line connections. During a fallback, the RS pins drive Low and the device boots from address space 0. The RS pins should be tied to upper addresses defined by the system to allow for full bit files to be stored in each memory segment.
P146:
In all configuration modes except SPI mode, RS[1:0] is controllable by WBSTAR.
在P119中講到了WBSTAR相關的內容,也涉及到了RS[1:0],具體如下所示:
The warm boot start address register (WBSTAR) specifies the MultiBoot address location to be used when the IPROG command is applied. The name of each bit position in the warm boot start address register is given in Table 5-34 and described in Table 5-35.
講解PR的UG908(v2018.2)的P118中提到:
To use external configuration modes (other than JTAG) for loading a partial BIT file, these pins must be reserved for use after the initial device configuration. This is achieved by using the BITSTREAM.CONFIG.PERSIST property to keep the dual-purpose I/O for configuration usage and to set the configuration width. Refer to this link in the Vivado Design Suite User Guide: Programming and Debugging (UG908) [Ref 25]. The Tcl command syntax to set this property is:
set_property BITSTREAM.CONFIG.PERSIST <value> [current_design]
where <value> is either No or Yes.
按照個人理解、這段話中所指的'these pins'指的是在UG470的Table2-2和Table2-3中列出的全部Configuration Pins、其中就包含RS0 和RS1 pins(屬於Multi-function pins也就是dual-purpose pins)。
而在一般的用於成熟的商用產品的設計中、顯然也會經常用到除了JTAG之外的、對FPGA進行配置的配置模式。
根據上述信息、為確保安全起見、在設計PR項目的FPGA硬件電路時、應當避免將具體芯片的RS0 和RS1管腳作為普通IO引腳使用(前提當然是選用的具體型號的FPGA芯片上包含這兩個引腳)。
(2)TCL腳本相關-VIVADO的shell模式和batch模式
之前在VIVADO的非工程模式下進行PR項目的工作時、不管是直接在windows的命令提示符窗口還是VIVADO GUI下的TCL Console,使用的都是shell模式的vivado,而后來仿照前人項目進行工作時、都是在windows的命令提示符窗口進入vivado的batch模式、使用source語句(vivado -mode batch -source <your_Tcl_script>)運行編寫好的tcl腳本。
在進行工作期間發現、當綜合同樣一個頂層模塊時,
方式一:
在vivado的batch模式下運行編寫好的tcl腳本,tcl的腳本內容依次大致為:
read_verilog <file_name1.v> read_verilog <file_name2.v> ... read_xdc <xdc_file.xdc> synth_design -no_lc ... ...
方式二:
使用和方式一相同的.v和.xdc源文件、在vivado的shell模式下(不管是命令提示符窗口還是VIVADO GUI Tcl Console),一行一行的敲進去方式一中腳本文件內的命令,然后一條一條地執行。
這兩種方式運行完了之后,VIVADO給出的提示不盡相同;並且如果都只是warnings還好,問題就出在,在某些時候,方式一的結果會報出error、但同時synth_design是顯示成功執行了的(error在Tcl Console中也找不到、但是就是顯示有1 error),而方式二卻不會報出error。
這個問題可能是由於vivado shell mode和batch mode工作時的細微差別所致,具體原因尚不明,僅記錄在此,供日后參考。
5、額外注意點
(1)在做Floorplan步驟中、繪制Pblock的注意點
根據UG947和UG909,在綜合之后、為每個RP的instance繪制相應的Pblock時,需要注意的基本點包括:
一般需要將RESET_AFTER_RECONFIG設置為TRUE(默認為FALSE);
一般需要將SNAPPING_MODE設置為ROUTING(或者設置為ON,默認為OFF);
當使用RESET_AFTER_RECONFIG的情況下,需要讓繪制的Pblock的垂直方向上的兩個邊界與clock region的垂直邊界對齊;
確保繪制的Pblock中所包含的邏輯資源是足夠的(為當下的布局布線和后續RM可能的升級修改留出足夠空間)。
除了上述注意點之外,目前找不到更多的明確提出了的注意點。
如下圖所示是xc7a35tftg256-1型號FPGA的VIVADO下的Device頁面:
可以看到其中包含6個clock region。之前在做PR工程期間,只敢讓一個RP的Pblock占據一個clock region,而在查閱UG文檔、以及借鑒了前人的PR項目案例之后,發現可以讓一個RP的Pblock占據多個clock region,比如可以是下圖這樣:
也似乎可以是下圖這樣(來自UG909-P87-Fig.6-1):
所以根據目前的有限了解,不需要將一個RP的Pblock局限在一個clock region之中。
(2)PR項目的工程和非工程模式
由於在開始接手PR項目任務時、在開始階段一直在工程模式下操作,所以在使用Tcl腳本(非工程模式)生成了可以通過PR測試的配置文件、交差之后,(抱着Project Mode不死心的態度)又在工程模式下新建了項目、按照Tcl腳本中對一些關鍵命令的屬性參數設置修改了工程模式下的一些屬性設置,分別如下所示。
綜合設置:
Implementation設置:
在打開open implementation之后、write bitstream之前進行的設置:
這里上面打鈎的“Prohibit usage of……”設置其實就是設置了BITSTREAM.CONFIG.PERSIST Yes的屬性,在UG702中也找到了對該點的說明(雖然UG702是針對ISE的):
-g Persist:Yes
Prohibits the use of the dual-purpose configuration pins as user I/O, which is required if Slave SelectMAP or Slave Serial modes are to be used for Partial Reconfiguration. This option should be used in conjunction with the CONFIG_MODE constraint to select the proper set of configuration pins to be reserved for post-configuration use. Consult the Constraints Guide (UG625) for the complete set of values for CONFIG_MODE (examples: S_SELECTMAP, S_SERIAL).
為了提高速度也設置了bit壓縮:
工程模式的project下、RM等的添加和之前操作流程沒有變化,都是通過partial configuration wizard下管理和添加(見上一篇PR)。
按照這樣的設置、繼續使用了tcl腳本模式下的pblock區塊規划。
使用這樣在Project Mode下生成的bit配置文件、打包下載到電路板上,也成功通過了PR測試!
總結來看:在vivado batch mode的非工程模式下使用TCL腳本和在VIVADO GUI下全程通過工程模式,都可以創建出滿足PR需求的bit配置文件,關鍵主要在於synth_design、place_design和write_bitstream等關鍵步驟中重要屬性參數的設置。