Skip to content

Commit

Permalink
spi: rename "extended" SPI to "standard"
Browse files Browse the repository at this point in the history
* N28Q125A calls the 1-MISO 1-MOSI protocol "extended" because it supports sending the command on 1 pin while receiving the data on 2 or 4 pins like "dual" or "quad".
  • Loading branch information
HarryMakes committed Feb 5, 2020
1 parent 5406337 commit 259225c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions nmigen_stdio/spiflash.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class _SPIFlashReaderBase:
"""
CMD_WIDTH = 8
CMD_DICT = {
"extended": None,
"standard": None,
"dual" : None,
"quad" : None
}
Expand All @@ -27,7 +27,7 @@ def _format_cmd(self):
the input cmd_value is extended/interleaved to full DQ width
even if DQ1-DQ3 are "don't care" during the command phase:
eg: 1 1 1 0 1 0 1 1 (extended SPI mode)
eg: 1 1 1 0 1 0 1 1 (standard SPI mode)
11 11 11 10 11 10 11 11 (dual I/O SPI mode)
1111 1111 1111 1110 1111 1110 1111 1111 (quad I/O SPI mode)
"""
Expand All @@ -43,9 +43,9 @@ def _format_cmd(self):

def __init__(self, *, protocol, data_width,
divisor=1, pins=None):
if protocol not in ["extended", "dual", "quad"]:
if protocol not in ["standard", "dual", "quad"]:
raise ValueError("Invalid SPI protocol {!r}; must be one of "
"\"extended\", \"dual\", or \"quad\""
"\"standard\", \"dual\", or \"quad\""
.format(protocol))
self._protocol = protocol
self._data_width = data_width
Expand All @@ -58,7 +58,7 @@ def __init__(self, *, protocol, data_width,

self._pins = pins

if self._protocol == "extended":
if self._protocol == "standard":
self.spi_width = 1
elif self._protocol == "dual":
self.spi_width = 2
Expand All @@ -68,7 +68,7 @@ def __init__(self, *, protocol, data_width,
self.cs = Signal(reset=0) # Equivalent to ~CS_N
self.clk = Signal()

if protocol == "extended":
if protocol == "standard":
self.mosi = Signal()
self.miso = Signal()
elif protocol == "dual":
Expand Down Expand Up @@ -104,7 +104,7 @@ def _add_spi_hardware_logic(self, platform, module):
# (e.g. by instantiating a USRMCLK Instance) must NOT pass a CLK on the SPI flash
if hasattr(self._pins, "clk"):
module.d.comb += self._pins.clk.o.eq(self.clk)
if self._protocol == "extended":
if self._protocol == "standard":
module.submodules += FFSynchronizer(self._pins.miso.i, self.miso)
module.d.comb += self._pins.mosi.o.eq(self.mosi)
elif self._protocol in ["dual", "quad"]:
Expand Down Expand Up @@ -141,7 +141,7 @@ def _add_spi_hardware_logic(self, platform, module):
# MISO starts latching bit/byte from slave
with module.If((counter == self._divisor_val >> 1) & self.cs):
module.d.sync += self.clk.eq(1)
if self._protocol == "extended":
if self._protocol == "standard":
module.d.sync += dq_i.eq(self.miso)
elif self._protocol in ["dual", "quad"]:
module.d.sync += dq_i.eq(self.dq.i)
Expand All @@ -158,9 +158,9 @@ def _add_spi_hardware_logic(self, platform, module):
with module.Elif(self.cs):
module.d.sync += counter.eq(counter - 1)

# MOSI logic for Extended SPI protocol:
# MOSI logic for Standard SPI protocol:
# MOSI always output the leftmost bit of shreg
if self._protocol == "extended":
if self._protocol == "standard":
module.d.comb += self.mosi.eq(shreg[-1])
# MOSI logic for Dual and Quad SPI protocols:
# Whenever DQ output should be enabled,
Expand All @@ -174,11 +174,11 @@ def _add_spi_hardware_logic(self, platform, module):

class SPIFlashSlowReader(_SPIFlashReaderBase, Elaboratable):
"""An SPI flash controller module for normal reading
(i.e. only available in Extended protocol and a lower frequency,
(i.e. only available in Standard protocol and a lower frequency,
but no dummy cycles of waiting are required).
"""
CMD_DICT = {
"extended": 0x03,
"standard": 0x03,
"dual" : None,
"quad" : None
}
Expand Down Expand Up @@ -287,7 +287,7 @@ class SPIFlashFastReader(_SPIFlashReaderBase, Elaboratable):
but dummy cycles of waiting are required)
"""
CMD_DICT = {
"extended": 0x0b,
"standard": 0x0b,
"dual" : 0x3b,
"quad" : 0x6b
}
Expand Down
4 changes: 2 additions & 2 deletions nmigen_stdio/test/test_spiflash.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def elaborate(self, platform):
m.d.sync += self.dut.dq.i.eq(0)
return m

def test_extended(self):
self.dut = SPIFlashFastReader(protocol="extended",
def test_standard(self):
self.dut = SPIFlashFastReader(protocol="standard",
addr_width=24,
data_width=32,
divisor=49,
Expand Down

0 comments on commit 259225c

Please sign in to comment.