【iCore4 雙核心板_FPGA】例程十:FSMC匯流排通訊實驗——複用地址模式

XiaomaGee發表於2017-09-01

實驗原理:

  STM32F767上自帶FMC控制器,本實驗將通過FMC匯流排的地址複用模式實現STM32與FPGA

之間通訊,FPGA內部建立RAM塊,FPGA橋接STM32和RAM塊,本實驗通過FSMC匯流排從STM32向

RAM塊中寫入資料,然後讀取RAM出來的資料進行驗證。

核心程式碼:

int main(void)
{
  int i;
    unsigned int fpga_read_data;

    system_clock.initialize();
    fsmc.initialize();
    led.initialize();
    
    LED_GREEN_ON;
    
    while(1){        
        for(i = 0;i < 256; i++){
            fpga_write(i,i);                                 
        }
        for(i = 0;i < 100000; i++);
        for(i = 0;i < 256;i++){
            fpga_read_data = fpga_read(i);           
            if(fpga_read_data != i){
                LED_GREEN_OFF;
                LED_RED_ON;
            }
        }    
    }
}
module fsmc_ctrl(
    input clk_25m,
    input pll_100m,
   input rst_n,
    
    input FSMC_CLK,
    input NADV,
    input WRn,
    input RDn,
    input CSn,
    input [23:16]AB,
    inout [15:0]DB
);
    
//--------------------wire---------------------------------//
    wire rd = (CSn | RDn);
    wire wr = (CSn | WRn);

//--------------------ab-----------------------------------//
    reg [23:0]address;

    always @ (posedge NADV or negedge rst_n)
        begin
            if(!rst_n)
                begin
                    address <= 24'd0;
                end
            else 
                begin
                    address <= {AB,DB};
                end
            
        end
//--------------------clk----------------------------------//
    reg wr_clk1,wr_clk2;    
    
    always @(posedge pll_100m or negedge rst_n)
        begin
            if(!rst_n)
                begin
                    wr_clk1 <= 1'd1;
                    wr_clk2 <= 1'd1;
                end
            else
                {wr_clk2,wr_clk1} <= {wr_clk1,wr};    //提取寫時鐘
        end
        
    wire clk = (!wr_clk2 | !rd);
    
//--------------------db_out-------------------------------//
    wire [15:0]db_out;
    assign DB = !rd ? db_out : 16'hzzzz;

//--------------------my_ram-------------------------------//
    my_ram u1(
        .address(address),
        .clock(clk),
        .data(DB),
        .wren(!wr),
        .rden(!rd),
        .q(db_out)    
    );//例化ram模組
    
//--------------------endmodule----------------------------//
endmodule

原始碼下載連結:

連結:http://pan.baidu.com/s/1hrK8c3i 密碼:syfc

iCore4連結:

相關文章