cores/spi_flash: Minor cosmetic cleanups, SpiFlashQuadReadWrite has also been moved to the end with a Note since should probably be re-factored.

This commit is contained in:
Florent Kermarrec 2021-03-03 09:15:51 +01:00
parent 61dcd1e8fd
commit 134c628357
1 changed files with 73 additions and 67 deletions

View File

@ -61,20 +61,22 @@ class SpiFlashCommon(Module):
# Xilinx 7-series
if device[:3] == "xc7":
self.specials += Instance("STARTUPE2",
i_CLK=0,
i_GSR=0,
i_GTS=0,
i_KEYCLEARB=0,
i_PACK=0,
i_USRCCLKO=self.pads.clk,
i_USRCCLKTS=0,
i_USRDONEO=1,
i_USRDONETS=1)
i_CLK = 0,
i_GSR = 0,
i_GTS = 0,
i_KEYCLEARB = 0,
i_PACK = 0,
i_USRCCLKO = self.pads.clk,
i_USRCCLKTS = 0,
i_USRDONEO = 1,
i_USRDONETS = 1
)
# Lattice ECP5
elif device[:4] == "LFE5":
self.specials += Instance("USRMCLK",
i_USRMCLKI=self.pads.clk,
i_USRMCLKTS=0)
i_USRMCLKI = self.pads.clk,
i_USRMCLKTS = 0
)
else:
raise NotImplementedError
self.clk_primitive_registered = True
@ -83,6 +85,7 @@ class SpiFlashCommon(Module):
if hasattr(self, "clk_primitive_needed"):
assert self.clk_primitive_registered == True
class SpiFlashDualQuad(SpiFlashCommon, AutoCSR):
def __init__(self, pads, dummy=15, div=2, with_bitbang=True, endianness="big"):
"""
@ -119,7 +122,6 @@ class SpiFlashDualQuad(SpiFlashCommon, AutoCSR):
dq_oe = Signal()
wbone_width = len(bus.dat_r)
read_cmd_params = {
4: (_format_cmd(_QIOFR, 4), 4*8),
2: (_format_cmd(_DIOFR, 2), 2*8),
@ -228,6 +230,7 @@ class SpiFlashDualQuad(SpiFlashCommon, AutoCSR):
self.sync += timeline(bus.cyc & bus.stb & (i == div - 1), tseq)
class SpiFlashSingle(SpiFlashCommon, AutoCSR):
def __init__(self, pads, dummy=15, div=2, with_bitbang=True, endianness="big"):
"""
@ -348,8 +351,59 @@ def SpiFlash(pads, *args, **kwargs):
else:
return SpiFlashDualQuad(pads, *args, **kwargs)
# Xilinx 7-Series FPGAs SPI Flash (non-memory-mapped) ----------------------------------------------
class S7SPIFlash(Module, AutoCSR):
def __init__(self, pads, sys_clk_freq, spi_clk_freq=25e6):
self.submodules.spi = spi = SPIMaster(None, 40, sys_clk_freq, spi_clk_freq)
self.specials += Instance("STARTUPE2",
i_CLK = 0,
i_GSR = 0,
i_GTS = 0,
i_KEYCLEARB = 0,
i_PACK = 0,
i_USRCCLKO = spi.pads.clk,
i_USRCCLKTS = 0,
i_USRDONEO = 1,
i_USRDONETS = 1
)
if hasattr(pads, "vpp"):
pads.vpp.reset = 1
if hasattr(pads, "hold"):
pads.hold.reset = 1
if hasattr(pads, "cs_n"):
self.comb += pads.cs_n.eq(spi.pads.cs_n)
self.comb += [
pads.mosi.eq(spi.pads.mosi),
spi.pads.miso.eq(pads.miso)
]
# Lattice ECP5 FPGAs SPI Flash (non-memory-mapped) -------------------------------------------------
class ECP5SPIFlash(Module, AutoCSR):
def __init__(self, pads, sys_clk_freq, spi_clk_freq=25e6):
self.submodules.spi = spi = SPIMaster(None, 40, sys_clk_freq, spi_clk_freq)
self.specials += Instance("USRMCLK",
i_USRMCLKI = spi.pads.clk,
i_USRMCLKTS = 0
)
if hasattr(pads, "vpp"):
pads.vpp.reset = 1
if hasattr(pads, "hold"):
pads.hold.reset = 1
if hasattr(pads, "cs_n"):
self.comb += pads.cs_n.eq(spi.pads.cs_n)
self.comb += [
pads.mosi.eq(spi.pads.mosi),
spi.pads.miso.eq(pads.miso)
]
# SpiFlash Quad Read/Write (memory-mapped) ---------------------------------------------------------
# Note: This code too complicated and should probably be re-factored.
class SpiFlashQuadReadWrite(SpiFlashCommon, AutoCSR):
def __init__(self, pads, dummy=15, div=2, with_bitbang=True, endianness="big"):
"""
@ -579,51 +633,3 @@ class SpiFlashQuadReadWrite(SpiFlashCommon, AutoCSR):
self.sync += timeline(queue.status[0] & ~self.en_quad.storage[0] & (i == div - 1), accumulate_timeline_deltas(read_seq))
self.sync += timeline(queue.status[1] & ~self.en_quad.storage[0] & (i == div - 1), accumulate_timeline_deltas(write_seq))
# Xilinx 7-Series FPGAs SPI Flash (non-memory-mapped) ----------------------------------------------
class S7SPIFlash(Module, AutoCSR):
def __init__(self, pads, sys_clk_freq, spi_clk_freq=25e6):
self.submodules.spi = spi = SPIMaster(None, 40, sys_clk_freq, spi_clk_freq)
self.specials += Instance("STARTUPE2",
i_CLK=0,
i_GSR=0,
i_GTS=0,
i_KEYCLEARB=0,
i_PACK=0,
i_USRCCLKO=spi.pads.clk,
i_USRCCLKTS=0,
i_USRDONEO=1,
i_USRDONETS=1
)
if hasattr(pads, "vpp"):
pads.vpp.reset = 1
if hasattr(pads, "hold"):
pads.hold.reset = 1
if hasattr(pads, "cs_n"):
self.comb += pads.cs_n.eq(spi.pads.cs_n)
self.comb += [
pads.mosi.eq(spi.pads.mosi),
spi.pads.miso.eq(pads.miso)
]
# Lattice ECP5 FPGAs SPI Flash (non-memory-mapped) -------------------------------------------------
class ECP5SPIFlash(Module, AutoCSR):
def __init__(self, pads, sys_clk_freq, spi_clk_freq=25e6):
self.submodules.spi = spi = SPIMaster(None, 40, sys_clk_freq, spi_clk_freq)
self.specials += Instance("USRMCLK",
i_USRMCLKI = spi.pads.clk,
i_USRMCLKTS = 0
)
if hasattr(pads, "vpp"):
pads.vpp.reset = 1
if hasattr(pads, "hold"):
pads.hold.reset = 1
if hasattr(pads, "cs_n"):
self.comb += pads.cs_n.eq(spi.pads.cs_n)
self.comb += [
pads.mosi.eq(spi.pads.mosi),
spi.pads.miso.eq(pads.miso)
]