Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added spi 1-bit mode, code from litex #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions misoc/cores/spi_flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def _format_cmd(cmd, spi_width):
c &= ~(1<<(b*spi_width))
return c

class SpiIF(object):
def __init__(self, i, o, oe):
self.i = i
self.o = o
self.oe = oe

class SpiFlash(Module, AutoCSR):
def __init__(self, pads, dummy=15, div=2, with_bitbang=True):
Expand All @@ -35,7 +40,12 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True):
Optionally supports software bitbanging (for write, erase, or other commands).
"""
self.bus = bus = wishbone.Interface()
spi_width = len(pads.dq)

if hasattr(pads, "mosi"):
spi_width = 1
else:
spi_width = len(pads.dq)

if with_bitbang:
self.bitbang = CSRStorage(4)
self.miso = CSRStatus()
Expand All @@ -59,8 +69,13 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True):

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:
dq = SpiIF(pads.miso, pads.mosi, Signal())
assert with_bitbang == False, \
"Bitbang not supported with 1-bit SPI flash."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it was not working out of the box because of this line:
https://github.com/m-labs/misoc/blob/master/misoc/cores/spi_flash.py#L85
so I didn't implement it.
If you can explain the code, I can try to implement it.


sr = Signal(max(cmd_width, addr_width, wbone_width))
self.comb += bus.dat_r.eq(sr)
Expand Down