Skip to content

Commit

Permalink
soc/cores: fix vivado issue with SPIRegister (at least with Vivado 20…
Browse files Browse the repository at this point in the history
…17.x+, mosi was not generated correctly), create cs_n signal if pads does not exists
  • Loading branch information
enjoy-digital committed Jul 27, 2017
1 parent 04646b2 commit c02de16
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions litex/soc/cores/spi.py
Expand Up @@ -45,18 +45,19 @@ def __init__(self, width):
self.o.eq(Mux(self.lsb, self.data[0], self.data[-1])),
]
self.sync += [
If(self.shift,
If(self.lsb,
self.data[:-1].eq(self.data[1:]),
).Else(
self.data[1:].eq(self.data[:-1]),
If(self.lsb,
If(self.shift,
self.data[:-1].eq(self.data[1:])
),
If(self.sample,
self.data[0].eq(self.i)
)
),
If(self.sample,
If(self.lsb,
self.data[-1].eq(self.i),
).Else(
self.data[0].eq(self.i),
).Else(
If(self.shift,
self.data[1:].eq(self.data[:-1]),
),
If(self.sample,
self.data[0].eq(self.i)
)
)
]
Expand Down Expand Up @@ -317,14 +318,17 @@ def __init__(self, pads):
]

# I/O
if hasattr(pads, "cs_n"):
cs_n_t = TSTriple(len(pads.cs_n))
self.specials += cs_n_t.get_tristate(pads.cs_n)
self.comb += [
cs_n_t.oe.eq(~self.config.offline),
cs_n_t.o.eq((cs & Replicate(machine.cs, len(cs))) ^
Replicate(~self.config.cs_polarity, len(cs))),
]
if not hasattr(pads, "cs_n"):
self.cs_n = Signal()
else:
self.cs_n = pads.cs_n
cs_n_t = TSTriple(len(self.cs_n))
self.specials += cs_n_t.get_tristate(self.cs_n)
self.comb += [
cs_n_t.oe.eq(~self.config.offline),
cs_n_t.o.eq((cs & Replicate(machine.cs, len(cs))) ^
Replicate(~self.config.cs_polarity, len(cs))),
]

clk_t = TSTriple()
self.specials += clk_t.get_tristate(pads.clk)
Expand All @@ -342,6 +346,7 @@ def __init__(self, pads):
machine.reg.i.eq(Mux(self.config.half_duplex, mosi_t.i,
getattr(pads, "miso", mosi_t.i))),
]
self.mosi_t = mosi_t


class SPIMaster(Module, AutoCSR):
Expand Down

0 comments on commit c02de16

Please sign in to comment.