Line 1... |
Line 1... |
//
|
///////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Filename: wbspiflash.v
|
// Filename: wbspiflash.v
|
//
|
//
|
// Project: FPGA library development (Basys3 development board)
|
// Project: Wishbone Controlled Quad SPI Flash Controller
|
//
|
//
|
// Purpose: Access a Quad SPI flash via a WISHBONE interface. This
|
// Purpose: Access a Quad SPI flash via a WISHBONE interface. This
|
// includes both read and write (and erase) commands to the SPI
|
// includes both read and write (and erase) commands to the SPI
|
// flash. All read/write commands are accomplished using the
|
// flash. All read/write commands are accomplished using the
|
// high speed (4-bit) interface. Further, the device will be
|
// high speed (4-bit) interface. Further, the device will be
|
// left/kept in the 4-bit read interface mode between accesses,
|
// left/kept in the 4-bit read interface mode between accesses,
|
// for a minimum read latency.
|
// for a minimum read latency.
|
//
|
//
|
// Wishbone Registers (See Basys3 Wishbone HTML page):
|
// Wishbone Registers (See spec sheet for more detail):
|
// 0: local config(r) / erase commands(w) / deep power down cmds / etc.
|
// 0: local config(r) / erase commands(w) / deep power down cmds / etc.
|
// R: (Write in Progress), (dirty-block), (spi_port_busy), 1'b0, 9'h00,
|
// R: (Write in Progress), (dirty-block), (spi_port_busy), 1'b0, 9'h00,
|
// { last_erased_sector, 14'h00 } if (WIP)
|
// { last_erased_sector, 14'h00 } if (WIP)
|
// else { current_sector_being_erased, 14'h00 }
|
// else { current_sector_being_erased, 14'h00 }
|
// current if write in progress, last if written
|
// current if write in progress, last if written
|
// W: (1'b1 to erase), (12'h ignored), next_erased_block, 14'h ignored)
|
// W: (1'b1 to erase), (12'h ignored), next_erased_block, 14'h ignored)
|
// 1: Read ID (read only)
|
// 1: Configuration register
|
// 2: Status register (R(/w?)), reads update the WIP bit ...
|
// 2: Status register (R/w)
|
|
// 3: Read ID (read only)
|
// (19 bits): Data (R/w, but expect writes to take a while)
|
// (19 bits): Data (R/w, but expect writes to take a while)
|
//
|
//
|
//
|
//
|
// Creator: Dan Gisselquist
|
// Creator: Dan Gisselquist
|
// Gisselquist Tecnology, LLC
|
// Gisselquist Tecnology, LLC
|
//
|
//
|
// Copyright: 2015
|
///////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
|
//
|
|
// This program is free software (firmware): you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License as published
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
|
// your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
// for more details.
|
//
|
//
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
|
// target there if the PDF file isn't present.) If not, see
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
//
|
//
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
|
// http://www.gnu.org/licenses/gpl.html
|
|
//
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////
|
`define WBQSPI_RESET 0
|
`define WBQSPI_RESET 0
|
`define WBQSPI_RESET_WEN 1
|
`define WBQSPI_RESET_WEN 1
|
`define WBQSPI_IDLE 2
|
`define WBQSPI_IDLE 2
|
`define WBQSPI_RDIDLE 3 // Idle, but in fast read mode
|
`define WBQSPI_RDIDLE 3 // Idle, but in fast read mode
|
`define WBQSPI_WBDECODE 4
|
`define WBQSPI_WBDECODE 4
|
Line 67... |
Line 89... |
i_wb_addr, i_wb_data,
|
i_wb_addr, i_wb_data,
|
// Wishbone return values
|
// Wishbone return values
|
o_wb_ack, o_wb_stall, o_wb_data,
|
o_wb_ack, o_wb_stall, o_wb_data,
|
// Quad Spi connections to the external device
|
// Quad Spi connections to the external device
|
o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat,
|
o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat,
|
o_interrupt,
|
o_interrupt);
|
// Info for a wbscope
|
|
o_debug);
|
|
input i_clk_100mhz;
|
input i_clk_100mhz;
|
// Wishbone, inputs first
|
// Wishbone, inputs first
|
input i_wb_cyc, i_wb_data_stb, i_wb_ctrl_stb, i_wb_we;
|
input i_wb_cyc, i_wb_data_stb, i_wb_ctrl_stb, i_wb_we;
|
input [19:0] i_wb_addr;
|
input [19:0] i_wb_addr;
|
input [31:0] i_wb_data;
|
input [31:0] i_wb_data;
|
Line 86... |
Line 106... |
output wire [1:0] o_qspi_mod;
|
output wire [1:0] o_qspi_mod;
|
output wire [3:0] o_qspi_dat;
|
output wire [3:0] o_qspi_dat;
|
input [3:0] i_qspi_dat;
|
input [3:0] i_qspi_dat;
|
// Interrupt line
|
// Interrupt line
|
output reg o_interrupt;
|
output reg o_interrupt;
|
// Debug/scope
|
|
output wire [31:0] o_debug;
|
|
|
|
reg spi_wr, spi_hold, spi_spd, spi_dir;
|
reg spi_wr, spi_hold, spi_spd, spi_dir;
|
reg [31:0] spi_in;
|
reg [31:0] spi_in;
|
reg [1:0] spi_len;
|
reg [1:0] spi_len;
|
wire [31:0] spi_out;
|
wire [31:0] spi_out;
|
wire spi_valid, spi_busy;
|
wire spi_valid, spi_busy;
|
wire [22:0] spi_dbg;
|
|
llqspi lldriver(i_clk_100mhz,
|
llqspi lldriver(i_clk_100mhz,
|
spi_wr, spi_hold, spi_in, spi_len, spi_spd, spi_dir,
|
spi_wr, spi_hold, spi_in, spi_len, spi_spd, spi_dir,
|
spi_out, spi_valid, spi_busy,
|
spi_out, spi_valid, spi_busy,
|
o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat,
|
o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat,
|
i_qspi_dat,
|
i_qspi_dat);
|
spi_dbg);
|
|
|
|
// Erase status tracking
|
// Erase status tracking
|
reg write_in_progress, write_protect;
|
reg write_in_progress, write_protect;
|
reg [5:0] erased_sector;
|
reg [5:0] erased_sector;
|
reg dirty_sector;
|
reg dirty_sector;
|
Line 124... |
Line 140... |
reg [5:0] spif_return;
|
reg [5:0] spif_return;
|
reg spif_ctrl, spif_req;
|
reg spif_ctrl, spif_req;
|
wire [5:0] spif_sector;
|
wire [5:0] spif_sector;
|
assign spif_sector = spif_addr[19:14];
|
assign spif_sector = spif_addr[19:14];
|
|
|
assign o_debug = { spi_wr, spi_spd, spi_hold, state, spi_dbg };
|
|
|
|
initial state = `WBQSPI_RESET;
|
initial state = `WBQSPI_RESET;
|
initial o_wb_ack = 1'b0;
|
initial o_wb_ack = 1'b0;
|
initial o_wb_stall = 1'b1;
|
initial o_wb_stall = 1'b1;
|
initial spi_wr = 1'b0;
|
initial spi_wr = 1'b0;
|
initial spi_len = 2'b00;
|
initial spi_len = 2'b00;
|