实验原理:
STM32F767上自带FMC控制器,本实验将通过FMC总线的地址独立模式实现STM32与FPGA
之间通信,FPGA内部建立RAM块,FPGA桥接STM32和RAM块,本实验通过FSMC总线从STM32向
RAM块中写入数据,然后读取RAM出来的数据进行验证。
核心代码:
int main(void)
{
long int i;
unsigned int fpga_read_data; system_clock.initialize();
fsmc.initialize();
led.initialize(); LED_GREEN_ON; /*FSMC²âÊÔ*/
while(){
/*fmc²âÊÔ*/
for(i = ;i < ; i++){
fpga_write(i,i); //ÏòFPGAдÊý¾Ý
} for(i = ;i < ; i++);
for(i = ;i < ;i++){
fpga_read_data = fpga_read(i); //´ÓFPGAÖжÁÈ¡Êý¾Ý
if(fpga_read_data != i){
LED_GREEN_OFF;
LED_RED_ON;
while();
}
}
}
}
module fsmc_ctrl(
input clk_25m,
input pll_100m,
input rst_n, input FSMC_CLK,
input NADV,
input WRn,
input RDn,
input CSn,
input [:]AB,
inout [:]DB
); //--------------------wire---------------------------------//
wire rd = (CSn | RDn);
wire wr = (CSn | WRn); //--------------------clk----------------------------------//
reg wr_clk1,wr_clk2,wr_clk3; always @(posedge pll_100m or negedge rst_n)
begin
if(!rst_n)
begin
wr_clk1 <= 'd1;
wr_clk2 <= 'd1;
end
else
{wr_clk3,wr_clk2,wr_clk1} <= {wr_clk2,wr_clk1,wr}; //提取写时钟
end wire clk = (!wr_clk1 | !rd); //--------------------db_out-------------------------------//
wire [:]db_out;
assign DB = !rd ? db_out : 'hzzzz; //--------------------my_ram-------------------------------//
my_ram u1(
.address(AB),
.clock(clk),
.data(DB),
.wren(!wr),
.rden(!rd),
.q(db_out)
);//例化ram模块 //--------------------endmodule----------------------------//
endmodule
源代码下载链接:
链接:http://pan.baidu.com/s/1misqyko 密码:eg83
iCore4链接: