Skip to content

Commit

Permalink
soc/cores/spi: make dynamic clk divider optional (can be enabled with…
Browse files Browse the repository at this point in the history
… add_clk_divider method) and only use it in add_spi_sdcard.
  • Loading branch information
enjoy-digital committed Mar 27, 2020
1 parent 86eec1a commit 2e48ab5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions litex/soc/cores/spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,22 @@ def add_csr(self):
CSRField("sel", len(self.cs), reset=1, description="Write ``1`` to corresponding bit to enable Xfer for chip.")
], description="SPI Chip Select.")
self._loopback = CSRStorage(description="SPI loopback mode.\n\n Write ``1`` to enable MOSI to MISO internal loopback.")
self._clk_divider = CSRStorage(16, description="SPI Clk Divider.", reset=self.clk_divider.reset)

self.comb += [
self.start.eq(self._control.fields.start),
self.length.eq(self._control.fields.length),
self.mosi.eq(self._mosi.storage),
self.cs.eq(self._cs.storage),
self.loopback.eq(self._loopback.storage),
self.clk_divider.eq(self._clk_divider.storage),

self._status.fields.done.eq(self.done),
self._miso.status.eq(self.miso),
]

def add_clk_divider(self):
self._clk_divider = CSRStorage(16, description="SPI Clk Divider.", reset=self.clk_divider.reset)
self.comb += self.clk_divider.eq(self._clk_divider.storage)

# SPI Slave ----------------------------------------------------------------------------------------

class SPISlave(Module):
Expand Down
1 change: 1 addition & 0 deletions litex/soc/integration/soc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,5 +1154,6 @@ def add_spi_sdcard(self, name="spisdcard", clk_freq=400e3):
if hasattr(pads, "rst"):
self.comb += pads.rst.eq(0)
spisdcard = SPIMaster(pads, 8, self.sys_clk_freq, 400e3)
spisdcard.add_clk_divider()
setattr(self.submodules, name, spisdcard)
self.add_csr(name)

0 comments on commit 2e48ab5

Please sign in to comment.