STM32通过FSMC与FPGA通信

2019-07-14 23:30发布

各位朋友好,STM32通过FSMC与FPGA通信,我该怎样测试通信是正常的? FPGA  代码如下
  1. module verilog_prj(
  2.                 clk,
  3.                 ARM_clk,
  4.                 led0,
  5.                 ab,       //address
  6.                 db,        //data
  7.                 wrn,        //wr
  8.                 rdn,        //rd
  9.                 csn        //cs
  10.             );

  11. input clk;            //25MHz

  12. output led0;
  13. output arm_clk;

  14. wire clk_8m;      //输入时钟的4倍频,100MHz   
  15. wire locked;      //PLL输出有效标志位,高有效

  16. input[2:0]    ab;
  17. inout[15:0] db;

  18. input wrn;
  19. input rdn;
  20. input csn;

  21. reg [15:0] outa;
  22. reg [15:0] outb;
  23. reg [15:0] outc;
  24. reg [15:0] outd;
  25. reg [15:0] oute;
  26. reg [15:0] outf;
  27. reg [15:0] outg;
  28. reg [15:0] outh;
  29. reg [15:0] out;

  30. //reg [15:0] ina;
  31. //reg [15:0] inb;
  32. //reg [15:0] inc;
  33. //reg [15:0] ind;
  34. //reg [15:0] ine;
  35. //reg [15:0] inf;
  36. //reg [15:0] ing;
  37. //reg [15:0] inh;

  38. //wire rd;
  39. //wire wr;

  40. reg [15:0] indata;

  41. //assign rd = !(csn & rdn); //get rd pulse  ____|~~~~|______
  42. //assign wr = !(csn & wrn); //get wr pulse  ____|~~~~|______

  43. assign db = !rdn ? indata:16'hzzzz;
  44. //  assign db = indata ;
  45. /*
  46. ****************************************************************
  47. *
  48. *      PLL例化
  49. *
  50. ****************************************************************
  51. */
  52. PLL_ctrl    PLL_ctrl_inst (
  53.                 .inclk0(clk),        //PLL输入时钟
  54.                 .c0(clk_8m),        //8MHz to ARM                    
  55.                 .locked(locked)    //PLL输出有效标志位,高有效
  56.             );

  57.             
  58. /*
  59. ****************************************************************
  60. *
  61. *      LED0闪烁
  62. *
  63. ****************************************************************
  64. */            
  65. reg[24:0] cnt1;
  66. always @ (posedge clk) begin
  67.     if(cnt1 == 25'd25_000_000)
  68.     begin
  69.         cnt1 <= 25'd0;
  70.         out <= out+1'b1;
  71.     end
  72.     else
  73.      begin
  74.          cnt1 <= cnt1+1'b1;
  75.          
  76.      end
  77. end


  78. assign led0 = cnt1[24];
  79. assign arm_clk = clk_8m;

  80. /*
  81. ****************************************************************
  82. *
  83. *                 FSMC读写  
  84. *
  85. ****************************************************************
  86. */
  87. //write data, 根据地址线选择八个空间写入,每个空间16位
  88.     always @(negedge wrn)
  89.      begin
  90.        if(csn == 0)
  91.         begin
  92.             case (ab)            
  93.                 3'b000:outa <= db;
  94.                 3'b001:outb <= db;
  95.                 3'b010:outc <= db;
  96.                 3'b011:outd <= db;
  97.                 3'b100:oute <= db;
  98.                 3'b101:outf <= db;
  99.                 3'b110:outg <= db;
  100.                 3'b111:outh <= db;
  101.                 default:;
  102.             endcase
  103.         end
  104.     end
  105.             
  106.     //red data 根据地址线选择8个空间读取,每个空间 16位
  107.     always @( rdn )
  108.     begin
  109.         if(csn == 0)
  110.         begin
  111.             case (ab)
  112.                 3'b000:indata <= out;
  113.                 3'b001:indata <= outb;
  114.                 3'b010:indata <= outc;
  115.                 3'b011:indata <= outd;
  116.                 3'b100:indata <= oute;
  117.                 3'b101:indata <= outf;
  118.                 3'b110:indata <= outg;
  119.                 3'b111:indata <= outh;
  120.                 default:;
  121.             endcase
  122.         end
  123.     end
  124. endmodule               
复制代码



0条回答

一周热门 更多>