Merge pull request #603 from pepijndevos/apicula

make Gowin boards work with Apicula
This commit is contained in:
Gwenhael Goavec-Merou 2024-09-04 10:40:10 +02:00 committed by GitHub
commit 185f8d5da4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 53 additions and 39 deletions

View File

@ -62,8 +62,8 @@ class _CRG(LiteXModule):
# BaseSoC ------------------------------------------------------------------------------------------ # BaseSoC ------------------------------------------------------------------------------------------
class BaseSoC(SoCMini): class BaseSoC(SoCMini):
def __init__(self, sys_clk_freq=48e6, with_led_chaser=True, **kwargs): def __init__(self, toolchain="gowin", sys_clk_freq=48e6, with_led_chaser=True, **kwargs):
platform = sipeed_tang_nano.Platform() platform = sipeed_tang_nano.Platform(toolchain=toolchain)
# CRG -------------------------------------------------------------------------------------- # CRG --------------------------------------------------------------------------------------
self.crg = _CRG(platform, sys_clk_freq) self.crg = _CRG(platform, sys_clk_freq)
@ -90,6 +90,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
soc = BaseSoC( soc = BaseSoC(
toolchain = args.toolchain,
sys_clk_freq = args.sys_clk_freq, sys_clk_freq = args.sys_clk_freq,
**parser.soc_argdict **parser.soc_argdict
) )

View File

@ -53,13 +53,13 @@ class _CRG(LiteXModule):
# BaseSoC ------------------------------------------------------------------------------------------ # BaseSoC ------------------------------------------------------------------------------------------
class BaseSoC(SoCCore): class BaseSoC(SoCCore):
def __init__(self, sys_clk_freq=48e6, def __init__(self, toolchain="gowin", sys_clk_freq=48e6,
with_led_chaser = True, with_led_chaser = True,
with_rgb_led = False, with_rgb_led = False,
with_buttons = True, with_buttons = True,
**kwargs): **kwargs):
platform = sipeed_tang_nano_20k.Platform(toolchain="gowin") platform = sipeed_tang_nano_20k.Platform(toolchain=toolchain)
# CRG -------------------------------------------------------------------------------------- # CRG --------------------------------------------------------------------------------------
self.crg = _CRG(platform, sys_clk_freq) self.crg = _CRG(platform, sys_clk_freq)
@ -131,7 +131,8 @@ def main():
args = parser.parse_args() args = parser.parse_args()
soc = BaseSoC( soc = BaseSoC(
sys_clk_freq = args.sys_clk_freq, toolchain = args.toolchain,
sys_clk_freq = args.sys_clk_freq,
**parser.soc_argdict **parser.soc_argdict
) )
if args.with_spi_sdcard: if args.with_spi_sdcard:

View File

@ -59,12 +59,12 @@ class _CRG(LiteXModule):
# BaseSoC ------------------------------------------------------------------------------------------ # BaseSoC ------------------------------------------------------------------------------------------
class BaseSoC(SoCCore): class BaseSoC(SoCCore):
def __init__(self, sys_clk_freq=27e6, def __init__(self, toolchain="gowin", sys_clk_freq=27e6,
with_hyperram = False, with_hyperram = False,
with_led_chaser = True, with_led_chaser = True,
with_video_terminal = True, with_video_terminal = True,
**kwargs): **kwargs):
platform = sipeed_tang_nano_4k.Platform() platform = sipeed_tang_nano_4k.Platform(toolchain=toolchain)
# CRG -------------------------------------------------------------------------------------- # CRG --------------------------------------------------------------------------------------
self.crg = _CRG(platform, sys_clk_freq, with_video_pll=with_video_terminal) self.crg = _CRG(platform, sys_clk_freq, with_video_pll=with_video_terminal)
@ -151,6 +151,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
soc = BaseSoC( soc = BaseSoC(
toolchain = args.toolchain,
sys_clk_freq = args.sys_clk_freq, sys_clk_freq = args.sys_clk_freq,
with_hyperram = args.with_hyperram, with_hyperram = args.with_hyperram,
with_video_terminal = args.with_video_terminal, with_video_terminal = args.with_video_terminal,

View File

@ -59,11 +59,11 @@ class _CRG(LiteXModule):
# BaseSoC ------------------------------------------------------------------------------------------ # BaseSoC ------------------------------------------------------------------------------------------
class BaseSoC(SoCCore): class BaseSoC(SoCCore):
def __init__(self, sys_clk_freq=27e6, bios_flash_offset=0x0, def __init__(self, toolchain="gowin", sys_clk_freq=27e6, bios_flash_offset=0x0,
with_led_chaser = True, with_led_chaser = True,
with_video_terminal = False, with_video_terminal = False,
**kwargs): **kwargs):
platform = sipeed_tang_nano_9k.Platform() platform = sipeed_tang_nano_9k.Platform(toolchain=toolchain)
# CRG -------------------------------------------------------------------------------------- # CRG --------------------------------------------------------------------------------------
self.crg = _CRG(platform, sys_clk_freq, with_video_pll=with_video_terminal) self.crg = _CRG(platform, sys_clk_freq, with_video_pll=with_video_terminal)
@ -141,6 +141,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
soc = BaseSoC( soc = BaseSoC(
toolchain = args.toolchain,
sys_clk_freq = args.sys_clk_freq, sys_clk_freq = args.sys_clk_freq,
bios_flash_offset = int(args.bios_flash_offset, 0), bios_flash_offset = int(args.bios_flash_offset, 0),
with_video_terminal = args.with_video_terminal, with_video_terminal = args.with_video_terminal,

View File

@ -31,13 +31,14 @@ from litedram.phy import GW2DDRPHY
# CRG ---------------------------------------------------------------------------------------------- # CRG ----------------------------------------------------------------------------------------------
class _CRG(LiteXModule): class _CRG(LiteXModule):
def __init__(self, platform, sys_clk_freq, with_video_pll=False): def __init__(self, platform, sys_clk_freq, with_video_pll=False, with_dram=False):
self.rst = Signal() self.rst = Signal()
self.cd_sys = ClockDomain() self.cd_sys = ClockDomain()
self.cd_por = ClockDomain() self.cd_por = ClockDomain()
self.cd_init = ClockDomain() if with_dram:
self.cd_sys2x = ClockDomain() self.cd_init = ClockDomain()
self.cd_sys2x_i = ClockDomain() self.cd_sys2x = ClockDomain()
self.cd_sys2x_i = ClockDomain()
# # # # # #
@ -58,24 +59,29 @@ class _CRG(LiteXModule):
self.pll = pll = GW2APLL(devicename=platform.devicename, device=platform.device) self.pll = pll = GW2APLL(devicename=platform.devicename, device=platform.device)
self.comb += pll.reset.eq(~por_done) self.comb += pll.reset.eq(~por_done)
pll.register_clkin(clk27, 27e6) pll.register_clkin(clk27, 27e6)
pll.create_clkout(self.cd_sys2x_i, 2*sys_clk_freq) if with_dram:
self.specials += [ # 2:1 clock needed for DDR
Instance("DHCEN", pll.create_clkout(self.cd_sys2x_i, 2*sys_clk_freq)
i_CLKIN = self.cd_sys2x_i.clk, self.specials += [
i_CE = self.stop, Instance("DHCEN",
o_CLKOUT = self.cd_sys2x.clk), i_CLKIN = self.cd_sys2x_i.clk,
Instance("CLKDIV", i_CE = self.stop,
p_DIV_MODE = "2", o_CLKOUT = self.cd_sys2x.clk),
i_CALIB = 0, Instance("CLKDIV",
i_HCLKIN = self.cd_sys2x.clk, p_DIV_MODE = "2",
i_RESETN = ~self.reset, i_CALIB = 0,
o_CLKOUT = self.cd_sys.clk), i_HCLKIN = self.cd_sys2x.clk,
AsyncResetSynchronizer(self.cd_sys, ~pll.locked | self.rst | self.reset), i_RESETN = ~self.reset,
] o_CLKOUT = self.cd_sys.clk),
]
# Init clock domain # Init clock domain
self.comb += self.cd_init.clk.eq(clk27) self.comb += self.cd_init.clk.eq(clk27)
self.comb += self.cd_init.rst.eq(pll.reset) self.comb += self.cd_init.rst.eq(pll.reset)
else:
pll.create_clkout(self.cd_sys, sys_clk_freq)
self.specials += AsyncResetSynchronizer(self.cd_sys, ~pll.locked | self.rst | self.reset)
# Video PLL # Video PLL
if with_video_pll: if with_video_pll:
@ -95,7 +101,7 @@ class _CRG(LiteXModule):
# BaseSoC ------------------------------------------------------------------------------------------ # BaseSoC ------------------------------------------------------------------------------------------
class BaseSoC(SoCCore): class BaseSoC(SoCCore):
def __init__(self, sys_clk_freq=48e6, def __init__(self, toolchain="gowin", sys_clk_freq=48e6,
with_spi_flash = False, with_spi_flash = False,
with_led_chaser = True, with_led_chaser = True,
with_rgb_led = False, with_rgb_led = False,
@ -110,19 +116,21 @@ class BaseSoC(SoCCore):
assert dock in ["standard", "lite"] assert dock in ["standard", "lite"]
platform = sipeed_tang_primer_20k.Platform(dock, toolchain="gowin") platform = sipeed_tang_primer_20k.Platform(dock, toolchain=toolchain)
if dock == "lite": if dock == "lite":
with_led_chaser = False # No leds on core board nor on dock lite. with_led_chaser = False # No leds on core board nor on dock lite.
# CRG -------------------------------------------------------------------------------------- # CRG --------------------------------------------------------------------------------------
self.crg = _CRG(platform, sys_clk_freq, with_video_pll=with_video_terminal) with_dram = (kwargs.get("integrated_main_ram_size", 0) == 0)
assert not (toolchain == "apicula" and with_dram)
self.crg = _CRG(platform, sys_clk_freq, with_video_pll=with_video_terminal, with_dram=with_dram)
# SoCCore ---------------------------------------------------------------------------------- # SoCCore ----------------------------------------------------------------------------------
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Tang Primer 20K", **kwargs) SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Tang Primer 20K", **kwargs)
# DDR3 SDRAM ------------------------------------------------------------------------------- # DDR3 SDRAM -------------------------------------------------------------------------------
if not self.integrated_main_ram_size: if with_dram:
self.ddrphy = GW2DDRPHY( self.ddrphy = GW2DDRPHY(
pads = platform.request("ddram"), pads = platform.request("ddram"),
sys_clk_freq = sys_clk_freq sys_clk_freq = sys_clk_freq
@ -208,6 +216,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
soc = BaseSoC( soc = BaseSoC(
toolchain = args.toolchain,
sys_clk_freq = args.sys_clk_freq, sys_clk_freq = args.sys_clk_freq,
with_spi_flash = args.with_spi_flash, with_spi_flash = args.with_spi_flash,
with_video_terminal = args.with_video_terminal, with_video_terminal = args.with_video_terminal,

View File

@ -71,7 +71,7 @@ class _CRG(LiteXModule):
# BaseSoC ------------------------------------------------------------------------------------------ # BaseSoC ------------------------------------------------------------------------------------------
class BaseSoC(SoCCore): class BaseSoC(SoCCore):
def __init__(self, sys_clk_freq=50e6, def __init__(self, toolchain="gowin", sys_clk_freq=50e6,
with_spi_flash = False, with_spi_flash = False,
with_led_chaser = True, with_led_chaser = True,
with_buttons = True, with_buttons = True,
@ -80,7 +80,7 @@ class BaseSoC(SoCCore):
sdram_rate = "1:2", sdram_rate = "1:2",
**kwargs): **kwargs):
platform = sipeed_tang_primer_25k.Platform(toolchain="gowin") platform = sipeed_tang_primer_25k.Platform(toolchain=toolchain)
assert not with_sdram or (sdram_model in ["sipeed", "mister"]) assert not with_sdram or (sdram_model in ["sipeed", "mister"])
@ -147,6 +147,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
soc = BaseSoC( soc = BaseSoC(
toolchain = args.toolchain,
sys_clk_freq = args.sys_clk_freq, sys_clk_freq = args.sys_clk_freq,
with_spi_flash = args.with_spi_flash, with_spi_flash = args.with_spi_flash,
with_sdram = args.with_sdram, with_sdram = args.with_sdram,