soc/cores/spi: make dynamic clk divider optional (can be enabled with add_clk_divider method) and only use it in add_spi_sdcard.

This commit is contained in:
Florent Kermarrec 2020-03-27 18:44:48 +01:00
parent 86eec1a413
commit 2e48ab568b
2 changed files with 5 additions and 2 deletions

View File

@ -137,7 +137,6 @@ class SPIMaster(Module, AutoCSR):
CSRField("sel", len(self.cs), reset=1, description="Write ``1`` to corresponding bit to enable Xfer for chip.") CSRField("sel", len(self.cs), reset=1, description="Write ``1`` to corresponding bit to enable Xfer for chip.")
], description="SPI Chip Select.") ], description="SPI Chip Select.")
self._loopback = CSRStorage(description="SPI loopback mode.\n\n Write ``1`` to enable MOSI to MISO internal loopback.") 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.comb += [
self.start.eq(self._control.fields.start), self.start.eq(self._control.fields.start),
@ -145,12 +144,15 @@ class SPIMaster(Module, AutoCSR):
self.mosi.eq(self._mosi.storage), self.mosi.eq(self._mosi.storage),
self.cs.eq(self._cs.storage), self.cs.eq(self._cs.storage),
self.loopback.eq(self._loopback.storage), self.loopback.eq(self._loopback.storage),
self.clk_divider.eq(self._clk_divider.storage),
self._status.fields.done.eq(self.done), self._status.fields.done.eq(self.done),
self._miso.status.eq(self.miso), 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 ---------------------------------------------------------------------------------------- # SPI Slave ----------------------------------------------------------------------------------------
class SPISlave(Module): class SPISlave(Module):

View File

@ -1154,5 +1154,6 @@ class LiteXSoC(SoC):
if hasattr(pads, "rst"): if hasattr(pads, "rst"):
self.comb += pads.rst.eq(0) self.comb += pads.rst.eq(0)
spisdcard = SPIMaster(pads, 8, self.sys_clk_freq, 400e3) spisdcard = SPIMaster(pads, 8, self.sys_clk_freq, 400e3)
spisdcard.add_clk_divider()
setattr(self.submodules, name, spisdcard) setattr(self.submodules, name, spisdcard)
self.add_csr(name) self.add_csr(name)