Skip to content

Commit

Permalink
Modified SPI flash core to support 1x non-IO SPI flash
Browse files Browse the repository at this point in the history
  • Loading branch information
kaolpr committed Sep 28, 2022
1 parent f1dc58d commit 7d9a09c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions misoc/cores/spi_flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True, endianness="big", d
"""
adr_width = 32-log2_int(dw//8)
self.bus = bus = wishbone.Interface(data_width=dw, adr_width=adr_width)
spi_width = len(pads.dq)
if hasattr(pads, "dq"):
spi_width = len(pads.dq)
else:
spi_width = 1
if with_bitbang:
self.bitbang = CSRStorage(4)
self.miso = CSRStatus()
Expand All @@ -62,8 +65,16 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True, endianness="big", d

pads.cs_n.reset = 1

dq = TSTriple(spi_width)
self.specials.dq = dq.get_tristate(pads.dq)
if spi_width > 1:
dq = TSTriple(spi_width)
self.specials.dq = dq.get_tristate(pads.dq)
else:
class TripleMock:
def __init__(self):
self.i = pads.miso
self.o = pads.mosi
self.oe = Signal()
dq = TripleMock()

sr = Signal(max(cmd_width, addr_width, dw))
if endianness == "big":
Expand All @@ -88,7 +99,8 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True, endianness="big", d
dq.oe.eq(1)
),
If(self.bitbang.storage[1],
self.miso.status.eq(dq.i[1])
self.miso.status.eq(dq.i) if spi_width == 1 \
else self.miso.status.eq(dq.i[1])
)
]
if spi_width > 1:
Expand Down

0 comments on commit 7d9a09c

Please sign in to comment.