OpenCores
URL https://opencores.org/ocsvn/qspiflash/qspiflash/trunk

Subversion Repositories qspiflash

[/] [qspiflash/] [trunk/] [doc/] [src/] [spec.tex] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 dgisselq
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
%%
3
%% Filename:    spec.tex
4
%%
5
%% Project:     Wishbone Controlled Quad SPI Flash Controller
6
%%
7
%% Purpose:     This LaTeX file contains all of the documentation/description
8
%%              currently provided with this Quad SPI Flash Controller.
9
%%              It's not nearly as interesting as the PDF file it creates,
10
%%              so I'd recommend reading that before diving into this file.
11
%%              You should be able to find the PDF file in the SVN distribution
12
%%              together with this PDF file and a copy of the GPL-3.0 license
13
%%              this file is distributed under.
14
%%
15
%%
16
%% Creator:     Dan Gisselquist
17
%%              Gisselquist Tecnology, LLC
18
%%
19
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
%%
21
%% Copyright (C) 2015, Gisselquist Technology, LLC
22
%%
23
%% This program is free software (firmware): you can redistribute it and/or
24
%% modify it under the terms of  the GNU General Public License as published
25
%% by the Free Software Foundation, either version 3 of the License, or (at
26
%% your option) any later version.
27
%%
28
%% This program is distributed in the hope that it will be useful, but WITHOUT
29
%% ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
30
%% FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
31
%% for more details.
32
%%
33
%% You should have received a copy of the GNU General Public License along
34
%% with this program.  (It's in the $(ROOT)/doc directory, run make with no
35
%% target there if the PDF file isn't present.)  If not, see
36
%% <http://www.gnu.org/licenses/> for a copy.
37
%%
38
%% License:     GPL, v3, as defined and found on www.gnu.org,
39
%%              http://www.gnu.org/licenses/gpl.html
40
%%
41
%%
42
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 2 dgisselq
\documentclass{gqtekspec}
44
\project{Quad SPI Flash Controller}
45
\title{Specification}
46
\author{Dan Gisselquist, Ph.D.}
47
\email{dgisselq\at opencores.org}
48
\revision{Rev.~0.1}
49
\begin{document}
50
\pagestyle{gqtekspecplain}
51
\titlepage
52
\begin{license}
53
Copyright (C) \theyear\today, Gisselquist Technology, LLC
54
 
55
This project is free software (firmware): you can redistribute it and/or
56
modify it under the terms of  the GNU General Public License as published
57
by the Free Software Foundation, either version 3 of the License, or (at
58
your option) any later version.
59
 
60
This program is distributed in the hope that it will be useful, but WITHOUT
61
ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
62
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
63
for more details.
64
 
65
You should have received a copy of the GNU General Public License along
66 3 dgisselq
with this program.  If not, see \hbox{<http://www.gnu.org/licenses/>} for a
67
copy.
68 2 dgisselq
\end{license}
69
\begin{revisionhistory}
70
0.1 & 5/13/2015 & Gisselquist & First Draft \\\hline
71
\end{revisionhistory}
72
% Revision History
73
% Table of Contents, named Contents
74
\tableofcontents
75
\listoffigures
76
\listoftables
77
\begin{preface}
78
The genesis of this project was a desire to communicate with and program an
79
FPGA board without the need for any proprietary tools.  This includes Xilinx
80
JTAG cables, or other proprietary loading capabilities such as Digilent's
81
Adept program.  As a result, all interactions with the board need to take
82
place using open source tools, and the board must be able to reprogram itself.
83
\end{preface}
84
 
85
\chapter{Introduction}
86
\pagenumbering{arabic}
87
\setcounter{page}{1}
88
 
89
The Quad SPI Flash controller handles all necessary queries and accesses to
90
and from a SPI Flash device that has been augmented with an additional
91
two data lines and enabled with a mode allowing all four data lines to
92
work together in the same direction at the same time.  Since the interface
93
was derived from a SPI interface, most of the interaction takes place using
94
normal SPI protocols and only some commands work at the higher four bits
95
at a time speed.
96
 
97
This particular controller attempts to mask the underlying operation of the
98
SPI device behind a wishbone interface, to make it so that reads and writes
99
are as simple as using the wishbone interface.  However, the difference
100
between erasing (turning bits from '0' to '1') and programming (turning bits
101
from '1' to '0') breaks this model somewhat.  Therefore, reads from the
102
device act like normal wishbone reads, writes program the device and
103
sort of work with the wishbone, while erase commands require another register
104
to control.  Please read the Operations chapter for a detailed description
105
of how to perform these relevant operations.
106
 
107
This controller implements the interface for the Quad SPI flash found on the
108
Basys-3 board built by Digilent, Inc.  Some portions of the interface may
109
be specific to the Spansion S25FL032P chip used on this board, and the
110
100~MHz system clock found on the board, although there is no reason the
111
controller needs to be limited to this architecture.  It just happens to be
112
the one I have been designing to and for.
113
 
114
For a description of how the internals of this core work, feel free to browse
115
through the Architecture chapter.
116
 
117
The registers that control this core are discussed in the Registers chapter.
118
 
119
As required, you can find a wishbone datasheet in Chapt.~\ref{chap:wishbone}.
120
 
121
The final pertinent information for implementing this core is found in the
122
I/O Ports chapter, Chapt.~\ref{chap:ioports}.
123
 
124
As always, write me if you have any questions or problems.
125
 
126
\chapter{Architecture}\label{chap:arch}
127
 
128
As built, the core consists of only two components: the wishbone quad SPI
129
flash controller, {\tt wbqspiflash}, and the lower level quad SPI driver,
130
{\tt llqspi}.  The controller issues high level read/write commands to the
131
lower level driver, which actually implements the Quad SPI protocol.
132
 
133
Pictorally, this looks something like Fig.~\ref{fig:arch}.
134
\begin{figure}\begin{center}\begin{pspicture}(-2in,0)(2in,3.5in)
135
\rput(0,2.5in){
136
        \rput(-0.9in,0){\psline{->}(0,1in)(0,0in)}
137
                \rput[b]{90}(-0.92in,0.5in){\tt i\_wb\_cyc}
138
        \rput(-0.7in,0){\psline{->}(0,1in)(0,0in)}
139
                \rput[b]{90}(-0.72in,0.5in){\tt i\_wb\_data\_stb}
140
        \rput(-0.5in,0){\psline{->}(0,1in)(0,0in)}
141
                \rput[b]{90}(-0.52in,0.5in){\tt i\_wb\_ctrl\_stb}
142
        \rput(-0.3in,0){\psline{->}(0,1in)(0,0in)}
143
                \rput[b]{90}(-0.32in,0.5in){\tt i\_wb\_we}
144
        \rput(-0.1in,0){\psline{->}(0,1in)(0,0in)}
145
                \rput[b]{90}(-0.12in,0.5in){\tt i\_wb\_addr}
146
        \rput( 0.1in,0){\psline{->}(0,1in)(0,0in)}
147
                \rput[b]{90}( 0.08in,0.5in){\tt i\_wb\_data}
148
        %
149
        \rput( 0.5in,0){\psline{<-}(0,1in)(0,0in)}
150
                \rput[b]{90}( 0.48in,0.5in){\tt o\_wb\_ack}
151
        \rput( 0.7in,0){\psline{<-}(0,1in)(0,0in)}
152
                \rput[b]{90}( 0.68in,0.5in){\tt o\_wb\_stall}
153
        \rput( 0.9in,0){\psline{<-}(0,1in)(0,0in)}
154
                \rput[b]{90}( 0.88in,0.5in){\tt o\_wb\_data}}
155
\rput(0,2.0in){%
156
        \rput(0,0){\psframe(-1.2in,0)(1.2in,0.5in)}
157
        \rput(0,0.25in){\tt wbqspiflash}}
158
\rput(0,1.0in){
159
        \rput(-0.9in,0){\psline{->}(0,1in)(0,0in)}
160
                \rput[b]{90}(-0.92in,0.5in){\tt spi\_wr}
161
        \rput(-0.7in,0){\psline{->}(0,1in)(0,0in)}
162
                \rput[b]{90}(-0.72in,0.5in){\tt spi\_hold}
163
        \rput(-0.5in,0){\psline{->}(0,1in)(0,0in)}
164
                \rput[b]{90}(-0.52in,0.5in){\tt spi\_in}
165
        \rput(-0.3in,0){\psline{->}(0,1in)(0,0in)}
166
                \rput[b]{90}(-0.32in,0.5in){\tt spi\_len}
167
        \rput(-0.1in,0){\psline{->}(0,1in)(0,0in)}
168
                \rput[b]{90}(-0.12in,0.5in){\tt spi\_spd}
169
        \rput( 0.1in,0){\psline{->}(0,1in)(0,0in)}
170
                \rput[b]{90}( 0.08in,0.5in){\tt spi\_dir}
171
        % \rput(-0.9in,0){\psline{->}(0,1in)(0,0in)}
172
                % \rput[b]{90}(-0.92in,0.5in){\tt i\_wb\_cyc}
173
        \rput( 0.5in,0){\psline{->}(0,1in)(0,0in)}
174
                \rput[b]{90}( 0.48in,0.5in){\tt spi\_out}
175
        \rput( 0.7in,0){\psline{->}(0,1in)(0,0in)}
176
                \rput[b]{90}( 0.68in,0.5in){\tt spi\_valid}
177
        \rput( 0.9in,0){\psline{->}(0,1in)(0,0in)}
178
                \rput[b]{90}( 0.88in,0.5in){\tt spi\_busy}}
179
\rput(0,0.5in){
180
        \rput(0,0){\psframe(-1.25in,0)(1.25in,0.5in)}
181
        \rput(0,0.25in){\tt llqspi}}
182
        \rput(0,0){\psline{<->}(-0.3in,0.5in)(-0.3in,0)
183
                \psline{<->}(-0.1in,0.5in)(-0.1in,0)
184
                \psline{<->}(0.1in,0.5in)(0.1in,0)
185
                \psline{<->}(0.3in,0.5in)(0.3in,0)}
186
        \rput[l](0.4in,0.25in){Quad SPI I/O lines}
187
\end{pspicture}\end{center}
188
\caption{Architecture Diagram}\label{fig:arch}
189
\end{figure}
190
This is also what you will find if you browse through the code.
191
 
192
While it isn't relevant for operating the device, a quick description of these
193
internal wires may be educational.  The lower level device is commanded by
194
asserting a {\tt spi\_wr} signal when the device is not busy (i.e. {\tt
195
spi\_busy} is low).  The actual command given depends upon the other
196
signals.  {\tt spi\_len} is a two bit value indicating whether this is an
197
8 bit (2'b00), 16 bit (2'b01), 24 bit (2'b10), or 32 bit (2'b11) transaction.
198
The data to be sent out the port is placed into {\tt spi\_in}.
199
 
200
Further, to support Quad I/O, {\tt spi\_spd} can be set to one to use all four
201
bits.  In this case, {\tt spi\_dir} must also be set to either 1'b0 for
202
writing, or 1'b1 to read from the four bits.
203
 
204
When data is valid from the lower level driver, the {\tt spi\_valid} line
205
will go high and {\tt spi\_out} will contain the data with the most recently
206
read bits in the lower bits.  Further, when the device is idle, {\tt spi\_busy}
207
will go low, where it may then read another command.
208
 
209
Sadly, this simple interface as originally designed doesn't work on a
210
device where transactions can be longer than 32~bits.  To support these
211
longer transactions, the lower level driver checks the {\tt spi\_wr} line
212
before it finishes any transaction.  If the line is high, the lower level
213
driver will deassert {\tt spi\_busy} for one cycle while reading the command
214
from the controller on the previous cycle.  Further, the controller can also
215
assert the {\tt spi\_hold} line which will stop the clock to the device
216
and force everything to wait for further instructions.
217
 
218
This hold line interface was necessary to deal with a slow wishbone bus that
219
was writing to the device, but that didn't have it's next data line ready.
220
Thus, by holding the {\tt i\_wb\_cyc} line high, a write could take many
221
clocks and the flash would simply wait for it.  (I was commanding the device
222
via a serial port, so writes could take {\em many} clock cycles for each
223
word to come through, i.e. 1,500 clocks or so per word and that's at high
224
speed.)
225
 
226
The upper level component, the controller {\tt wbqspiflash}, is little more
227
than a glorified state machine that interacts with the wishbone bus.
228
From it's idle state, it can handle any command, whether data or control,
229
and issue appropriate commands to the lower level driver.  From any other
230
state, it will stall the bus until it comes back to idle--with a few exceptions.
231
Subsequent data reads, while reading data, will keep the device reading.
232
Subsequent data writes, while in program mode, will keep filling the devices
233
buffer before starting the write.  In other respects, the device will just
234
stall the bus until it comes back to idle.
235
 
236
While they aren't used in this design, the wishbone error and retry signals
237
would've made a lot of sense here.  Specifically, it should be an error to
238
read from the device while it is in the middle of an erase or program command.
239
Instead, this core stalls the bus--trying to do good for everyone.  Perhaps
240
a later, updated, implementation will make better use of these signals instead
241
of stalling.  For now, this core just stalls the bus.
242
 
243
Perhaps the best takeaway from this architecture section is that the varying
244
pieces of complexity have each been separated from each other.  There's a
245
lower level driver that handles actually toggling the lines to the port,
246
while the higher level driver maintains the state machine controlling which
247
commands need to be issued and when.
248
 
249
\chapter{Operation}\label{chap:ops}
250
This implementation attempts to encapsulate (hide) the details of the chip
251
from the user, so that the user does not need to know about the various
252
subcommands going to and from the chip.  The original goal was to make the
253
chip act like any other read/write memory, however the difference between
254
erasing and programming the chip made this impossible.  Therefore a separate
255
register is given to erase any given sector, while reads and writes may proceed
256
(almost) as normal.
257
 
258
The wishbone bus that this controller works with, however, is a 32--bit
259
bus.  Address one on the bus addresses a completely different 32--bit word
260
from address zero or address two.  Bus select lines are not implemented,
261
all operations are 32--bit.  Further, the device is little--endian, meaning
262
that the low order byte is the first byte that will be or is stored on the
263
flash.
264
 
265
\section{High Level}
266
From a high level perspective, this core provides read/write access to the
267
device either via the wishbone (read and program), or through a control
268
register found on the wishbone (the EREG).  Programming the device consists of
269
first erasing the region of interest.  This will set all the bits to '1' in
270
that region.  After erasing the region, the region can then be programmed,
271
setting some of the '1' bits to '0's.  When neither erase nor program
272
operation is going on, the device may be read.  The section will describe
273
each of those operations in detail.
274
 
275
To erase a sector of the device, two writes are required to the EREG register.
276
The first write turns off the write protect bit, whereas the second write
277
commands the erase itself.  The first write should equal \hbox{0x1000\_0000},
278
the second should be any address within the sector to be erased together
279
with setting the high bit of the register or \hbox{0x8000\_0000} plus the
280
address.  After this second write, the controller will issue a write--enable
281
command to the device, followed by a sector erase command.  In summary,
282
\begin{enumerate}
283
\item Disable write protect by writing \hbox{\tt 0x1000\_0000} to the EREG
284
        register
285
\item Command the erase by writing \hbox{\tt 0x8000\_0000} plus the device
286
        address to the EREG register.  (Remember, this is the {\em word
287
        address} of interest, not the {\em byte address}.)
288
\end{enumerate}
289
 
290
While the device is erasing, the controller will idle while checking the
291
status register over and over again.  Should you wish to read from the EREG
292
during this time, the high order bit of the EREG register will be set.
293
Once the erase is complete, this bit will clear, the interrupt line will
294
be strobed high, and other operations may take then place on the part.  Any
295
attempt to perform another operation on the part prior to that time will stall
296
the bus until the erase is complete.
297
 
298
Once an area has been erased, it may then be programmed.  To program the device,
299
first disable the write protect by writing a {\tt 0x1000\_0000} to the EREG
300
register.  After that, you may then write to the area in question whatever
301
values you wish to program.  One 256~byte (64~bus word) page may be programmed
302
at a time.  Pages start on even boundaries, such as addresses {\tt 0x040},
303
{\tt 0x080}, {\tt 0x0100}, etc.  To program a whole page at a time, write the
304
64~words of the page to the controller without dropping the {\tt i\_wb\_cyc}
305
line.  Attempts to write more than 64~words will stall the bus, as will
306
attempts to write more than one page.  Writes of less than a page work as well.
307
In summary,
308
\begin{enumerate}
309
\item Disable the write protect by writing a {\tt 0x1000\_0000} to the EREG
310
        register.
311
\item Write the page of interest to the data memory of the device.
312
 
313
        The first address should start at the beginning of a page (bottom six
314
        bits zero), and end at the end of the page (bottom six bits one, top
315
        bits identical).  Writes of less than a page are okay.  Writes crossing
316
        page boundaries will stall the device.
317
\end{enumerate}
318
 
319
While the device is programming a page, the controller will idle while
320
checking the status register as it did during an erase.  During this idle,
321
both the EREG register and the device status register may be queried.  Once
322
the status register drops the write in progress line, the top level bit of
323
the EREG register will be cleared and the interrupt line strobed.  Prior to this
324
time, any other bus operation will stall the bus until the write completes.
325
 
326
Reads are simple, you just read from the device and the device does everything
327
you expect.  Reads may be pipelined.  Further, if the device is ever commanded
328
to read the configuration register, revealing that the quad SPI mode is
329
enabled, then reads will take place four bits at a time from the bus.
330
In general, it will take 72 device clocks (at 50~MHz) to read the first word
331
from memory, and 32 for every pipelined word read thereafter provided that
332
the reads are in memory order.  Likewise, in quad SPI mode, it will
333
instead take 28 device clocks to read the first word, and 8 device clocks
334
to read every word thereafter again provided that the subsequent pipelined
335
reads are in memory order.
336
 
337
The Quad SPI device provides for a special mode following a read, where the
338
next read may start immediately in Quad I/O mode following a 12~clock
339
setup.  This controller leaves the device in this mode following any initial
340
read.  Therefore, back to back reads as part of separate bus cycles will only
341
take 20~clocks to read the first word, and 8~clocks per word thereafter.
342
Other commands, however, such as erasing, writing, reading from the status,
343
configuration, or ID registers, will take require a 32~device clock operation
344
before entering.
345
 
346
\section{Low Level}
347
 
348
At a lower level, this core implements the following Quad SPI commands:
349
\begin{enumerate}
350
\item FAST\_READ, when a read is requested and Quad mode has not been enabled.
351
\item QIOR, or quad I/O high performance read mode.  This is the default read
352
        command when Quad mode has been enabled, and it leaves the device
353
        in the Quad I/O High Performance Read mode, ready for a faster second
354
        read command.
355
\item RDID, or Read identification
356
\item WREN, or Write Enable, is issued prior to any erase, program, or
357
                write register (i.e. configuration or status) command.
358
        This detail is hidden from the user.
359
\item RDSR, or read status register, is issued any time the user attempts
360
        to read from the status register.  Further, following an erase or a
361
        write command, the device is left reading this register over and over
362
        again until the write completes.
363
\item RCR, or read configuration, is issued any time a request is made to
364
        read from the configuration register.  Following such a read, the
365
        quad I/O may be enabled for the device, if it is enabled in this
366
        register.
367
\item WRR, or write registers, is issued upon any write to the status or
368
        configuration registers.  To separate the two, the last value read
369
        from the status register is written to the status register when
370
        writing the configuration register.
371
\item PP, or page program, is issued to program the device in serial mode
372
        whenever programming is desired and the quad I/O has not been enabled.
373
\item QPP, or quad page program, is used to program the device whenever
374
        a write is requested and quad I/O mode has been enabled.
375
\item SE, or sector erase, is the only type of erase this core supports.
376
\item CLSR, or Clear Status Register, is issued any time the last status
377
        register had the bits {\tt P\_ERR} or {\tt E\_ERR} set and the
378
        write to the status register attempts to clear one of these.  This
379
        command is then issued following the WRR command.
380
\end{enumerate}
381
 
382
\chapter{Registers}\label{chap:regs}
383
 
384
This implementation supports four control registers.  These are the EREG
385
register, the configuration register, the status register, and the device ID,
386
as shown and listed in Table.~\ref{tbl:reglist}.
387
\begin{table}[htbp]
388
\begin{center}
389
\begin{reglist}
390
EREG & 0 & 32 & R/W & An overall control register, providing instant status
391
        from the device and controlling erase commands.\\\hline
392
Config & 1 & 8 & R/W & The devices configuration register.\\\hline
393
Status & 2 & 8 & R/W & The devices status register.\\\hline
394
ID & 3 & 16 & R & Reads the 16-bit ID from the device.\\\hline
395
\end{reglist}
396
\caption{List of Registers}\label{tbl:reglist}
397
\end{center}\end{table}
398
 
399
\section{EREG Register}
400
The EREG register was designed to be a replacement for all of the device
401
registers, leaving all the other registers a part of a lower level access
402
used only in debugging the device.  This would've been the case, save that
403
one may need to set bit one of the configuration register to enter high
404
speed mode.
405
 
406
The bits associated with this register are listed in Tbl.~\ref{tbl:eregbits}.
407
 
408
\begin{table}[htbp]
409
\begin{center}
410
\begin{bitlist}
411
31 & R/W & Write in Progress/Erase.  On a read, this bit will be high if any
412
        write or erase operation is in progress, zero otherwise.  To erase
413
        a sector, set this bit to a one.  Otherwise, writes should keep this
414
        register at zero.\\\hline
415
30 & R & Dirty bit.  The sector referenced has been written to since it
416
        was erased.  This bit is meaningless between startup and the first
417
        erase, but valid afterwards.\\\hline
418
29 & R & Busy bit.  This bit returns a one any time the lower level Quad
419
        SPI core is active.  However, to read this register, the lower level
420
        core must be inactive, so this register should always read zero.
421
        \\\hline
422
28 & R/W & Disable write protect.  Set this to a one to disable the write
423
        protect mode, or to a zero to re--enable write protect on this chip.
424
        Note that this register is not self--clearing.  Therefore, write
425
        protection may still be disabled following an erase or a write.
426
        Clear this manually when you wish to re--enable write protection.
427
        \\\hline
428
27 & R & Returns a one if the device is in high speed (4-bit I/O) mode.
429
        To set the device into high speed mode, set bit~1 of the configuration
430
        register.\\\hline
431
20--26 & R & Always return zero.\\\hline
432
14--19 & R/W & The sector address bits of the last sector erased.  If the
433
        erase line bit is set while writing this register, these bits
434
        will be set as well with the sector being erased.\\\hline
435
0--13 & R & Always return zero.\\\hline
436
\end{bitlist}
437
\caption{EREG bit definitions}\label{tbl:eregbits}
438
\end{center}\end{table}
439
 
440
In general, only three bits and an address are of interest here.
441
 
442
The first bit of interest is bit 27, which will tell you if you are in Quad--I/O
443
mode.  The device will automatically start up in SPI serial mode.  Upon
444
reading the configuration register, it will transition to Quad--I/O mode if
445
the QUAD bit is set.  Likewise, if the bit is written to the configuration
446
register it will transition to Quad--I/O mode.
447
 
448
While this may seem kind of strange, I have found this setup useful.  It allows
449
me to debug commands that might work in serial mode but not quad I/O mode,
450
and it allows me to explicitly switch to Quad I/O mode.  Further, writes to the
451
configuration register are non--volatile and in some cases permanent.
452
Therefore, it doesn't make sense that a controller should perform such a write
453
without first being told to do so.  Therefore, this bit is set upon
454
noticing that the QUAD bit is set in the configuration register.
455
 
456
The second bit of interest is the write protect disable bit.  Write a '1'
457
to this bit before any erase or program operation, and a '0' to this bit
458
otherwise.  This allows you to make sure that accidental bus writes to the
459
wrong address won't reprogram your flash (which they would do otherwise).
460
 
461
The final bit of interest is the write in progress slash erase bit.  On read,
462
this bit mirrors the WIP bit in the status register.  It will be a one during
463
any ongoing erase or programming operation, and clear otherwise.  Further,
464
to erase a sector, disable the write protect and then set this bit to a one
465
while simultaneously writing the sector of interest to the device.
466
 
467
The last item of interest in this register is the sector address of interest.
468
This was placed in bits 14--19 so that any address within the sector
469
would work.  Thus, to erase a sector, write the sector address, together with
470
an erase bit, to this register.
471
 
472
\section{Config Register}
473
 
474
The Quad Flash device also has a non--volatile configuration register, as
475
shown in Tbl.~\ref{tbl:confbits}.  Writes to this register are program events,
476
which will stall subsequent bus operations until the write in progress bit
477
of either the status or EREG registers clears.  Note that some bits, once
478
written, cannot be cleared such as the BPNV bit.
479
 
480
Writes to this register are not truly independent of the status register,
481
as the Write Registers (WRR) command writes the status register before the
482
configuration register.  Therefore, the core implements this by writing the
483
status register with the last value that was read by the core, or zero
484
if the status register has yet to be read by the core.  Following the
485
status register write, the new value for the configuration register is
486
written.
487
\begin{table}[htbp]\begin{center}
488
\begin{bitlist}
489
8--31 & R & Always return zero.\\\hline
490
6--7 & R & Not used.\\\hline
491
5 & R/W & TBPROT. Configures the start of block protection.  See device
492
        documentation for more information.  (Default 0)\\\hline
493
4 & R/W & Do not use.  (Default 0)\\\hline
494
3 & R/W & BPNV, configures BP2--0 bits in the status register.  If this bit
495
        is set to 1, these bits are volatile, if set to '0' (default) the
496
        bits are non--volatile.  {\em Note that once this bit has been set,
497
        it cannot be cleared!}\\\hline
498
2 & R/W & TBPARM.  Configures the parameter sector location.  See device
499
        documentation for more detailed information.  (Default 0)\\\hline
500
1 & R/W & QUAD.  Set to '1' to place the device into Quad I/O (4--bit) mode,
501
        '0' to leave in dual or serial I/O mode.  (This core does not support
502
        dual I/O mode.)  (Most programmers will set this to '1'.)\\\hline
503
 
504
        otherwise.  (Default 0).\\\hline
505
        \\\hline
506
\end{bitlist}
507
\caption{Configuration bit definitions}\label{tbl:confbits}
508
\end{center}\end{table}
509
 
510
Further information on this register is available in the device data sheet.
511
 
512
\section{Status Register}
513
The definitions of the bits in the status register are shown in
514
Tbl.~\ref{tbl:statbits}.  For operating this core, only the write in progress
515
bit is relevant.  All other bits should be set to zero.
516
 
517
\begin{table}[htbp]
518
\begin{center}
519
\begin{bitlist}
520
8--31 & R & Always return zero.\\\hline
521
7 & R/W & Status register write disable.  This setting is irrelevant in the
522
        current core configuration, since the W\#/ACC line is always kept
523
        high.\\\hline
524
6 & R/W & P\_ERR.  The device will set this to a one if a programming error
525
        has occurred.  Writes with either P\_ERR or E\_ERR cleared will
526
        clear this bit.\\\hline
527
5 & R/W & E\_ERR.  The device will set this to a one if an erase error has
528
        occurred, zero otherwise.  Writes clearing either P\_ERR or E\_ERR
529
        will clear this bit.
530
        \\\hline
531
2--4 & R/W & Block protect bits.  This core assumes these bits are zero.
532
        See device documentation for other possible settings.\\\hline
533
1 & R & Write Enable Latch.  This bit is handled internally by the core,
534
        being set before any program or erase operation and cleared by
535
        the operation itself.  Therefore, reads should always read this
536
        line as low.\\\hline
537
 
538
        program operation is in progress.  It will be cleared upon completion.
539
        \\\hline
540
\end{bitlist}
541
\caption{Status bit definitions}\label{tbl:statbits}
542
\end{center}\end{table}
543
 
544
\section{Device ID}
545
 
546
Reading from the Device ID register causes the core controller to issue
547
a RDID {\tt 0x9f} command.  The bytes returned are first the manufacture
548
ID of the part ({\tt 0x01} for this part), followed by the device ID
549
({\tt 0x0215} for this part), followed by the number of extended bytes that
550
may be read ({\tt 0x4D} for this part).  This controller provides no means
551
of reading these extended bytes.  (See Tab.~\ref{tbl:idbits})
552
 
553
\begin{table}[htbp]\begin{center}
554
\begin{bitlist}
555
0--31 & R & Always reads {\tt 0x0102154d}.\\\hline
556
\end{bitlist}
557
\caption{Read ID bit definitions}\label{tbl:idbits}
558
\end{center}\end{table}
559
 
560
\chapter{Wishbone Datasheet}\label{chap:wishbone}
561
Tbl.~\ref{tbl:wishbone} is required by the wishbone specification, and so
562
it is included here.
563
\begin{table}[htbp]
564
\begin{center}
565
\begin{wishboneds}
566
Revision level of wishbone & WB B4 spec \\\hline
567
Type of interface & Slave, (Block) Read/Write \\\hline
568
Port size & 32--bit \\\hline
569
Port granulity & 32--bit \\\hline
570
Maximum Operand Size & 32--bit \\\hline
571
Data transfer ordering & Little Endian \\\hline
572
Clock constraints & Must be 100~MHz or slower \\\hline
573
Signal Names & \begin{tabular}{ll}
574
                Signal Name & Wishbone Equivalent \\\hline
575
                {\tt i\_clk\_100mhz} & {\tt CLK\_I} \\
576
                {\tt i\_wb\_cyc} & {\tt CYC\_I} \\
577
                {\tt i\_wb\_ctrl\_stb} & {\tt STB\_I} \\
578
                {\tt i\_wb\_data\_stb} & {\tt STB\_I} \\
579
                {\tt i\_wb\_we} & {\tt WE\_I} \\
580
                {\tt i\_wb\_data} & {\tt DAT\_I} \\
581
                {\tt o\_wb\_ack} & {\tt ACK\_O} \\
582
                {\tt o\_wb\_stall} & {\tt STALL\_O} \\
583
                {\tt o\_wb\_data} & {\tt DAT\_O}
584
                \end{tabular}\\\hline
585
\end{wishboneds}
586
\caption{Wishbone Datasheet for the Quad SPI Flash controller}\label{tbl:wishbone}
587
\end{center}\end{table}
588
 
589
\chapter{Clocks}\label{chap:clocks}
590
 
591
This core is based upon the Basys--3 design.  The Basys--3 development board
592
contains one external 100~MHz clock.  This clock is divided by two to create
593
the 50~MHz clock used to drive the device.   According to the data sheet,
594
it should be possible to run this core at up to 160~MHz, however I have not
595
tested it at such speeds.  See Table.~\ref{tbl:clocks}.
596
\begin{table}[htbp]
597
\begin{center}
598
\begin{clocklist}
599
i\_clk\_100mhz & External & 160 & & System clock.\\\hline
600
\end{clocklist}
601
\caption{List of Clocks}\label{tbl:clocks}
602
\end{center}\end{table}
603
 
604
\chapter{I/O Ports}\label{chap:ioports}
605
There are two interfaces that this device supports: a wishbone interface, and
606
the interface to the Quad--SPI flash itself.  Both of these have their own
607
section in the I/O port list.  For the purpose of this table, the wishbone
608
interface is listed in Tbl.~\ref{tbl:iowishbone}, and the Quad SPI flash
609
interface is listed in Tbl.~\ref{tbl:ioqspi}.  The two lines that don't really
610
fit this classification are found in Tbl.~\ref{tbl:ioother}.
611
\begin{table}[htbp]
612
\begin{center}
613
\begin{portlist}
614
i\_wb\_cyc & 1 & Input & Wishbone bus cycle wire.\\\hline
615
i\_wb\_data\_stb & 1 & Input & Wishbone strobe, when the access is to the data
616
                memory.\\\hline
617
i\_wb\_ctrl\_stb & 1 & Input & Wishbone strobe, for when the access is to
618
        one of control registers.\\\hline
619
i\_wb\_we & 1 & Input & Wishbone write enable, indicating a write interaction
620
                to the bus.\\\hline
621
i\_wb\_addr & 19 & Input & Wishbone address.  When accessing control registers,
622
                only the bottom two bits are relevant all other bits are
623
                ignored.\\\hline
624
i\_wb\_data & 32 & Input & Wishbone bus data register.\\\hline
625
o\_wb\_ack & 1 & Output & Return value acknowledging a wishbone write, or
626
                signifying valid data in the case of a wishbone read request.
627
                \\\hline
628
o\_wb\_stall & 1 & Output & Indicates the device is not yet ready for another
629
                wishbone access, effectively stalling the bus.\\\hline
630
o\_wb\_data & 32 & Output & Wishbone data bus, returning data values read
631
                from the interface.\\\hline
632
\end{portlist}
633
\caption{Wishbone I/O Ports}\label{tbl:iowishbone}
634
\end{center}\end{table}
635
 
636
While this core is wishbone compatible, there was one necessary change to
637
the wishbone interface to make this possible.  That was the split of the
638
strobe line into two separate lines.  The first strobe line, the data strobe,
639
is used when the access is to data memory--such as a read or write (program)
640
access.  The second strobe line, the control strobe, is for reads and writes
641
to one of the four control registers.  By splitting these strobe lines,
642
the wishbone interconnect designer may place the control registers in a
643
separate location of wishbone address space from the flash memory.  It is
644
an error for both strobe lines to be on at the same time.
645
 
646
With respect to the Quad SPI interface itself, one piece of glue logic
647
is necessary to tie the Quad SPI flash I/O to the in/out port at the top
648
level of the device.  Specifically, these two lines must be added somewhere:
649
\begin{tabbing}
650
assign {\tt io\_qspi\_dat} = \= (\~{\tt qspi\_mod[1]})?(\{2'b11,1'bz,{\tt qspi\_dat[0]}\}) \hbox{\em // Serial mode} \\
651
        \> :(({\tt qspi\_bmod[0]})?(4'bzzzz):({\tt qspi\_dat[3:0]}));
652
                \hbox{\em // Quad mode}
653
\end{tabbing}
654
These provide the transition between the input and output ports used by this
655
core, and the bi--directional inout ports used by the actual part.  Further,
656
because the two additional lines are defined to be ones during serial I/O
657
mode, the hold and write protect lines are effectively eliminated in this
658
design in favor of faster speed I/O (i.e., Quad I/O).
659
 
660
\begin{table}[htbp]
661
\begin{center}
662
\begin{portlist}
663
o\_qspi\_sck & 1 & Output & Serial clock output to the device.  This pin
664
                will be either inactive, or it will toggle at 50~MHz.\\\hline
665
o\_qpsi\_cs\_n & 1 & Output & Chip enable, active low.  This will be
666
                set low at the beginning of any interaction with the chip,
667
                and will be held low throughout the interaction.\\\hline
668
o\_qspi\_mod & 2 & Output & Two mode lines for the top level to control
669
        how the output data lines interact with the device.  See the text
670
        for how to use these lines.\\\hline
671
o\_qspi\_dat & 4 & Output & Four output lines, the least of which is the
672
        old SPI MOSI line.  When selected by the o\_qspi\_mod, this output
673
        becomes the command for all 4 QSPI I/O lines.\\\hline
674
i\_qspi\_dat & 4 & Input & The four input lines from the device, of which
675
        line one, {\tt i\_qspi\_dat[1]}, is the old MISO line.\\\hline
676
\end{portlist}
677
\caption{List of Quad--SPI Flash I/O ports}\label{tbl:ioqspi}
678
\end{center}\end{table}
679
 
680
Finally, the clock line is not specific to the wishbone bus, and the interrupt
681
line is not specific to any of the above.  These have been separated out here.
682
\begin{table}[htbp]
683
\begin{center}
684
\begin{portlist}
685
i\_clk\_100mhz & 1 & Input & The 100~MHz clock driving all interactions.\\\hline
686
o\_interrupt & 1 & Output & An strobed interrupt line indicating the end of
687
        any erase or write transaction.  This line will be high for exactly
688
        one clock cycle, indicating that the core is again available for
689
        commanding.\\\hline
690
\end{portlist}
691
\caption{Other I/O Ports}\label{tbl:ioother}
692
\end{center}\end{table}
693
% Appendices
694
% Index
695
\end{document}
696
 
697
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.