当前位置:   article > 正文

Xilinx FPGA程序升级更新_icap xilinx

icap xilinx

  0.概述    

         Xilixn FPGA提供了一种在线升级的方式,可以通过ICAP指令实现。ICAP(Internal Configuration Access Port) 指的是内部配置访问端口,其主要作用是通过内部配置访问端口(ICAP),用户可以在FPGA逻辑代码中直接读写FPGA内部配置寄存器(类似SelectMAP),从而实现特定的配置功能,例如Multiboot。FPGA实现IPROG通常有两种方式,一种是通过ICAP配置,一种是把相关指令嵌入bit文件中。与通过bit文件实现IPROG相比,通过ICAP更灵活。对Xilinx FPGA的升级其实是Multiboot的操作。如下图所示,基地址存放的是Golden Image(bootloader),而高地址存放的是MultiBoot Image。小编会在本文对Xilinx 7系列的MulTIboot做一些简单介绍。

        程序在启动的过程中,首先会加载MultiBoot Image,然后判断配置是否成功,这一步一般都是由外部电路决定,如果成功,则FPGA芯片上运行的是MultiBoot Image,如果失败,程序会自动返回到Golden Image。

1.STARTUP原语

我们都知道fpga掉电程序会丢失,一般使用外部flash存储代码,flash有spi、bpi、qspi等接口,外部存储器的时钟管脚一般与fpga的CCLK_0连接(BANK0),当使用远程更新时,首先fpga内部有控制flash的驱动(即逻辑控制flash时序)的时钟,当然flash时钟也需要控制了,但这时时钟管脚已经连接到CCLK_0,这时候就需要用STARTUPE2(7系列),SPANTAN系列使用STARTUPE原语,而UltraScale系列使用STARTUPE3原语,小编使用的是xc7k325的器件,所以:

  1. STARTUPE2 #(
  2. .PROG_USR("FALSE"), // Activate program event security feature. Requires encrypted bitstreams.
  3. .SIM_CCLK_FREQ(0.0) // Set the Configuration Clock Frequency(ns) for simulation
  4. )
  5. STARTUPE2_inst
  6. (
  7. .CFGCLK(), // 1-bit output: Configuration main clock output
  8. .CFGMCLK(), // 1-bit output: Configuration internal oscillator clock output
  9. .EOS(), // 1-bit output: Active high output signal indicating the End Of Startup.
  10. .PREQ(), // 1-bit output: PROGRAM request to fabric output
  11. .CLK(0), // 1-bit input: User start-up clock input
  12. .GSR(0), // 1-bit input: Global Set/Reset input (GSR cannot be used for the port name)
  13. .GTS(0), // 1-bit input: Global 3-state input (GTS cannot be used for the port name)
  14. .KEYCLEARB(1), // 1-bit input: Clear AES Decrypter Key input from Battery-Backed RAM (BBRAM)
  15. .PACK(1), // 1-bit input: PROGRAM acknowledge input
  16. .USRCCLKO(flash_clk), // 1-bit input: User CCLK input**将SPI的时钟链接到这里**
  17. .USRCCLKTS(0), // 1-bit input: User CCLK 3-state enable input
  18. .USRDONEO(1), // 1-bit input: User DONE pin output control
  19. .USRDONETS(1) // 1-bit input: User DONE 3-state enable outpu
  20. );

其中flash_clk就是时序控制的flash时钟信号,连接到这就行了,其它的不需要改动,也无需约束此管脚(因为约束会报错,小编已经踩过坑了)。 其实在Xilinx上的Xilinx SPI Controller里面包含STARTUP原语,如下图所示,所以对于Xilinx支持的FLASH芯片厂商如:Micron,Winbond,Spansion等,不需要再例化该原语。

SPI-controller

2.ICAP原语

IRPOG命令序列是实现FPGA重加载的重要环节。IPROG命令的效果与在PROGRAM_B引脚产生一个脉冲的效果类似,但是IPROG命令不对重配置[4]逻辑进行复位。Kintex7内部ICAPE2模块能够执行IPROG命令,IPROG命令触发FPGA从SPI Flash中重新加载比特文件,加载地址是Kintex7中WBSTAR寄存器指定的地址。 IPROG命令发送后,FPGA完成3个动作:

  • 发送同步字节(AA995566);
  • 向Kintex7的WBSTAR寄存器写入下一个加载地址(下表地址为00000000);
  • 发送IPORG命令(0000000F)。

下表是通过ICAPE2向重配置模块发送IPROG命令的顺序。

ICAPE2编程命令程序实现如下所示

  1. ICAPE2 #(
  2. .DEVICE_ID(0'h3651093 ), // Specifies the pre-programmed Device ID value to be used for simulation
  3. .ICAP_WIDTH ("X32" ), // Specifies the input and output data width.
  4. .SIM_CFG_FILE_NAME ("C:\\VivadoPrj\\FPGAUartProgram\\7Serial\\7Serial_A7\\7Serial_A7.runs\\impl_1\\OnlineProgram_top.bit" ) // Specifies the Raw Bitstream (RBT) file to be parsed by the simulation model.
  5. )
  6. ICAPE2_inst (
  7. .O (ICAPE2_O ), // 32-bit output: Configuration data output bus
  8. .CLK (ICAPE2_CLK ), // 1-bit input: Clock Input
  9. .CSIB (ICAPE2_CSIB ), // 1-bit input: Active-Low ICAP Enable
  10. .I (ICAPE2_I ), // 32-bit input: Configuration data input bus
  11. .RDWRB (ICAPE2_RDWRB ) // 1-bit input: Read/Write Select input
  12. );

具体实现程序如下所示:

  1. ICAPE2_I[0] <= icape2_data_r[7];
  2. ICAPE2_I[1] <= icape2_data_r[6];
  3. ICAPE2_I[2] <= icape2_data_r[5];
  4. ICAPE2_I[3] <= icape2_data_r[4];
  5. ICAPE2_I[4] <= icape2_data_r[3];
  6. ICAPE2_I[5] <= icape2_data_r[2];
  7. ICAPE2_I[6] <= icape2_data_r[1];
  8. ICAPE2_I[7] <= icape2_data_r[0];
  9. ICAPE2_I[8] <= icape2_data_r[15];
  10. ICAPE2_I[9] <= icape2_data_r[14];
  11. ICAPE2_I[10] <= icape2_data_r[13];
  12. ICAPE2_I[11] <= icape2_data_r[12];
  13. ICAPE2_I[12] <= icape2_data_r[11];
  14. ICAPE2_I[13] <= icape2_data_r[10];
  15. ICAPE2_I[14] <= icape2_data_r[9];
  16. ICAPE2_I[15] <= icape2_data_r[8];
  17. ICAPE2_I[16] <= icape2_data_r[23];
  18. ICAPE2_I[17] <= icape2_data_r[22];
  19. ICAPE2_I[18] <= icape2_data_r[21];
  20. ICAPE2_I[19] <= icape2_data_r[20];
  21. ICAPE2_I[20] <= icape2_data_r[19];
  22. ICAPE2_I[21] <= icape2_data_r[18];
  23. ICAPE2_I[22] <= icape2_data_r[17];
  24. ICAPE2_I[23] <= icape2_data_r[16];
  25. ICAPE2_I[24] <= icape2_data_r[31];
  26. ICAPE2_I[25] <= icape2_data_r[30];
  27. ICAPE2_I[26] <= icape2_data_r[29];
  28. ICAPE2_I[27] <= icape2_data_r[28];
  29. ICAPE2_I[28] <= icape2_data_r[27];
  30. ICAPE2_I[29] <= icape2_data_r[26];
  31. ICAPE2_I[30] <= icape2_data_r[25];
  32. ICAPE2_I[31] <= icape2_data_r[24];

其实在Xilinx上的Block Design中也有ICAP的IP核,所以在进行设计的时候也可以直接调用该IP进行实现跳转功能。

坑三:需要对外部SPI接口进行约束

约束如下:

  1. set cclk_delay 6.7
  2. # Following are the SPI device parameters
  3. # Max Tco
  4. set tco_max 7
  5. # Min Tco
  6. set tco_min 1
  7. # Setup time requirement
  8. set tsu 2
  9. # Hold time requirement
  10. set th 3
  11. # Following are the board/trace delay numbers
  12. # Assumption is that all Data lines are matched
  13. set tdata_trace_delay_max 0.25
  14. set tdata_trace_delay_min 0.25
  15. set tclk_trace_delay_max 0.2
  16. set tclk_trace_delay_min 0.2
  17. ### End of user provided delay numbers
  18. # This is to ensure min routing delay from SCK generation to STARTUP input
  19. # User should change this value based on the results
  20. # Having more delay on this net reduces the Fmax
  21. # Following constraint should be commented when the STARTUP block is disabled
  22. set_max_delay 1.5 -from [get_pins -hier *SCK_O_reg_reg/C] -to [get_pins -hier *USRCCLKO] -datapath_only
  23. set_min_delay 0.1 -from [get_pins -hier *SCK_O_reg_reg/C] -to [get_pins -hier *USRCCLKO]
  24. # Following command creates a divide by 2 clock
  25. # It also takes into account the delay added by the STARTUP block to route the CCLK
  26. # This constraint is not needed when the STARTUP block is disabled
  27. # The following constraint should be commented when the STARTUP block is disabled
  28. create_generated_clock -name clk_sck -source [get_pins -hierarchical *axi_quad_spi_1/ext_spi_clk] [get_pins -hierarchical *USRCCLKO] -edges {3 5 7} -edge_shift [list $cclk_delay $cclk_delay $cclk_delay]
  29. # Enable the following constraint when STARTUP block is disabled
  30. #create_generated_clock -name clk_virt -source [get_pins -hierarchical *axi_quad_spi_1/ext_spi_clk] [get_ports <SCK_IO>] -edges {3 5 7}
  31. # Data is captured into FPGA on the second rising edge of ext_spi_clk after the SCK falling edge
  32. # Data is driven by the FPGA on every alternate rising_edge of ext_spi_clk
  33. set_input_delay -clock clk_sck -max [expr $tco_max + $tdata_trace_delay_max + $tclk_trace_delay_max] [get_ports IO*_IO] -clock_fall;
  34. set_input_delay -clock clk_sck -min [expr $tco_min + $tdata_trace_delay_min + $tclk_trace_delay_min] [get_ports IO*_IO] -clock_fall;
  35. set_multicycle_path 2 -setup -from clk_sck -to [get_clocks -of_objects [get_pins -hierarchical */ext_spi_clk]]
  36. set_multicycle_path 1 -hold -end -from clk_sck -to [get_clocks -of_objects [get_pins -hierarchical */ext_spi_clk]]
  37. # Data is captured into SPI on the following rising edge of SCK
  38. # Data is driven by the IP on alternate rising_edge of the ext_spi_clk
  39. set_output_delay -clock clk_sck -max [expr $tsu + $tdata_trace_delay_max - $tclk_trace_delay_min] [get_ports IO*_IO];
  40. set_output_delay -clock clk_sck -min [expr $tdata_trace_delay_min -$th - $tclk_trace_delay_max] [get_ports IO*_IO];
  41. set_multicycle_path 2 -setup -start -from [get_clocks -of_objects [get_pins -hierarchical */ext_spi_clk]] -to clk_sck
  42. set_multicycle_path 1 -hold -from [get_clocks -of_objects [get_pins -hierarchical */ext_spi_clk]] -to clk_sck

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/947912
推荐阅读
相关标签
  

闽ICP备14008679号