Cyclone2 FPGA读写FLASH SST39VF1601 实验Verilog逻辑源码Quartus工程文件
module FLASH_TEST (
//input
input sys_clk , //system clock;
input sys_rst_n , //system reset, low is active;
//output
inout [15:0] FLASH_DQ ,
output reg [20:0] FLASH_ADDR ,
output reg FLASH_CE ,
output reg FLASH_OE ,
output reg FLASH_WE ,
output reg FLASH_RST ,
output reg [ 7:0] LED
);
//Reg define
reg [3:0] div_cnt ;
reg flash_clk ;
reg [31:0] wait_cnt ;
reg [5:0] ctrl_cnt ;
reg [15:0] flash_data_lck ;
reg [15:0] flash_din ;
//Wire define
//************************************************************************************
//** Main Program
//**
//************************************************************************************
// counter used for div osc clk to flash ctrl clk 50M/16 , one flash ctrl clk cycle is 330ns
always @(posedge sys_clk or negedge sys_rst_n) begin
if (sys_rst_n ==1'b0)
div_cnt <= 4'b0;
else
div_cnt <= div_cnt + 4'b1;
end
//gen flash_clk
always @(posedge sys_clk or negedge sys_rst_n) begin
if (sys_rst_n ==1'b0)
flash_clk <= 1'b0 ;
else if ( div_cnt <= 4'd7 )
flash_clk <= 1'b1 ;
else
flash_clk <= 1'b0 ;
end
// flash ctrl signal gen
// read FLASH devid need 5 step :
// ctrl_cnt 10 - 13 is write oxaa in addr 0x5555
// ctrl_cnt 14 - 17 is write ox55 in addr 0x2aaa
// ctrl_cnt 18 - 21 is write ox90 in addr 0x5555
// ctrl_cnt 22 -30 is wait time for TIDA
// ctrl_cnt 31 -34 is read manId in addr 0
// ctrl_cnt 35 -38 is read devid in addr