add spi master function
add spi master function and dts wrapper for zephyr. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
parent
4e044f54c7
commit
44b6fb5a28
|
@ -1965,6 +1965,27 @@ class LiteXSoC(SoC):
|
||||||
add_ip_address_constants(self, "REMOTEIP", ethmac_remote_ip)
|
add_ip_address_constants(self, "REMOTEIP", ethmac_remote_ip)
|
||||||
add_mac_address_constants(self, "MACADDR", ethmac_address)
|
add_mac_address_constants(self, "MACADDR", ethmac_address)
|
||||||
|
|
||||||
|
# Add SPI Master --------------------------------------------------------------------------------
|
||||||
|
def add_spi_master(self, name="spimaster", pads=None, data_width=8, spi_clk_freq=1e6, with_clk_divider=True, **kwargs):
|
||||||
|
# Imports.
|
||||||
|
from litex.soc.cores.spi import SPIMaster
|
||||||
|
|
||||||
|
self.check_if_exists(f"{name}")
|
||||||
|
|
||||||
|
if pads is None:
|
||||||
|
pads = self.platform.request(name)
|
||||||
|
|
||||||
|
spim = SPIMaster(pads, data_width, self.sys_clk_freq, spi_clk_freq, **kwargs)
|
||||||
|
|
||||||
|
if with_clk_divider:
|
||||||
|
spim.add_clk_divider()
|
||||||
|
|
||||||
|
self.add_module(name=f"{name}", module=spim)
|
||||||
|
|
||||||
|
self.add_constant(f"{name}_FREQUENCY", spi_clk_freq)
|
||||||
|
self.add_constant(f"{name}_DATA_WIDTH", data_width)
|
||||||
|
self.add_constant(f"{name}_MAX_CS", len(pads.cs_n))
|
||||||
|
|
||||||
# Add SPI Flash --------------------------------------------------------------------------------
|
# Add SPI Flash --------------------------------------------------------------------------------
|
||||||
def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None, phy=None, rate="1:1", software_debug=False, **kwargs):
|
def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None, phy=None, rate="1:1", software_debug=False, **kwargs):
|
||||||
# Imports.
|
# Imports.
|
||||||
|
|
|
@ -181,6 +181,26 @@ def i2s_handler(name, parm, csr):
|
||||||
return dtsi
|
return dtsi
|
||||||
|
|
||||||
|
|
||||||
|
def spimaster_handler(name, parm, csr):
|
||||||
|
registers = get_registers_of(name, csr)
|
||||||
|
if len(registers) == 0:
|
||||||
|
raise KeyError
|
||||||
|
|
||||||
|
dtsi = dts_reg(registers)
|
||||||
|
dtsi += dts_reg_names(registers)
|
||||||
|
|
||||||
|
dtsi += indent("clock-frequency = <{}>;\n".format(
|
||||||
|
csr['constants'][name + '_frequency']))
|
||||||
|
|
||||||
|
dtsi += indent("data-width = <{}>;\n".format(
|
||||||
|
csr['constants'][name + '_data_width']))
|
||||||
|
|
||||||
|
dtsi += indent("max-cs = <{}>;\n".format(
|
||||||
|
csr['constants'][name + '_max_cs']))
|
||||||
|
|
||||||
|
return dtsi
|
||||||
|
|
||||||
|
|
||||||
def peripheral_handler(name, parm, csr):
|
def peripheral_handler(name, parm, csr):
|
||||||
registers = get_registers_of(name, csr)
|
registers = get_registers_of(name, csr)
|
||||||
if len(registers) == 0:
|
if len(registers) == 0:
|
||||||
|
@ -219,10 +239,13 @@ overlay_handlers = {
|
||||||
'alias': 'eth0',
|
'alias': 'eth0',
|
||||||
'config_entry': 'ETH_LITEETH'
|
'config_entry': 'ETH_LITEETH'
|
||||||
},
|
},
|
||||||
|
'spimaster': {
|
||||||
|
'handler': spimaster_handler,
|
||||||
|
'alias': 'spi0',
|
||||||
|
},
|
||||||
'spiflash': {
|
'spiflash': {
|
||||||
'handler': peripheral_handler,
|
'handler': peripheral_handler,
|
||||||
'alias': 'spi0',
|
'alias': 'spi1',
|
||||||
'config_entry': 'SPI_LITESPI'
|
|
||||||
},
|
},
|
||||||
'sdcard_block2mem': {
|
'sdcard_block2mem': {
|
||||||
'handler': peripheral_handler,
|
'handler': peripheral_handler,
|
||||||
|
|
Loading…
Reference in New Issue