Skip to content

Commit a15fbb6

Browse files
Merge pull request #631 from andelf/enhance/sipeed_tang_name_20k
sipeed_tang_nano_20k: add SPI flash and HDMI support
2 parents 89d96a3 + 2d25408 commit a15fbb6

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

litex_boards/platforms/sipeed_tang_nano_20k.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@
4848
IOStandard("LVCMOS33"),
4949
),
5050

51+
# HDMI
52+
("hdmi", 0,
53+
Subsignal("clk_p", Pins("33")),
54+
Subsignal("clk_n", Pins("34")),
55+
Subsignal("data0_p", Pins("35")),
56+
Subsignal("data0_n", Pins("36")),
57+
Subsignal("data1_p", Pins("37")),
58+
Subsignal("data1_n", Pins("38")),
59+
Subsignal("data2_p", Pins("39")),
60+
Subsignal("data2_n", Pins("40")),
61+
Subsignal("hdp", Pins("26"), IOStandard("LVCMOS18")),
62+
Subsignal("cec", Pins("25"), IOStandard("LVCMOS18")),
63+
Subsignal("sda", Pins("53")),
64+
Subsignal("scl", Pins("52")),
65+
Misc("PULL_MODE=NONE"),
66+
),
67+
5168
# Leds
5269
("led_n", 0, Pins("15"), IOStandard("LVCMOS33")),
5370
("led_n", 1, Pins("16"), IOStandard("LVCMOS33")),

litex_boards/targets/sipeed_tang_nano_20k.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from litex.soc.integration.builder import *
2121
from litex.soc.cores.gpio import GPIOIn
2222
from litex.soc.cores.led import LedChaser, WS2812
23+
from litex.soc.cores.video import VideoGowinHDMIPHY
2324

2425
from litedram.modules import M12L64322A # FIXME: use the real model number
2526
from litedram.phy import GENSDRPHY
@@ -29,10 +30,13 @@
2930
# CRG ----------------------------------------------------------------------------------------------
3031

3132
class _CRG(LiteXModule):
32-
def __init__(self, platform, sys_clk_freq):
33+
def __init__(self, platform, sys_clk_freq, with_hdmi=False):
3334
self.rst = Signal()
3435
self.cd_sys = ClockDomain()
3536
self.cd_por = ClockDomain()
37+
if with_hdmi:
38+
self.cd_hdmi = ClockDomain()
39+
self.cd_hdmi5x = ClockDomain()
3640

3741
# Clk
3842
clk27 = platform.request("clk27")
@@ -50,24 +54,46 @@ def __init__(self, platform, sys_clk_freq):
5054
pll.register_clkin(clk27, 27e6)
5155
pll.create_clkout(self.cd_sys, sys_clk_freq)
5256

57+
# HDMI PLL
58+
if with_hdmi:
59+
self.video_pll = video_pll = GW2APLL(devicename=platform.devicename, device=platform.device)
60+
video_pll.register_clkin(clk27, 27e6)
61+
video_pll.create_clkout(self.cd_hdmi5x, 125e6, margin=1e-2)
62+
self.specials += Instance("CLKDIV",
63+
p_DIV_MODE = "5",
64+
i_RESETN = 1, # Disable reset signal.
65+
i_CALIB = 0, # No calibration.
66+
i_HCLKIN = self.cd_hdmi5x.clk,
67+
o_CLKOUT = self.cd_hdmi.clk
68+
)
69+
5370
# BaseSoC ------------------------------------------------------------------------------------------
5471

5572
class BaseSoC(SoCCore):
5673
def __init__(self, toolchain="gowin", sys_clk_freq=48e6,
5774
with_led_chaser = True,
5875
with_rgb_led = False,
5976
with_buttons = True,
77+
with_spi_flash = False,
78+
with_video_terminal = False,
79+
with_video_colorbars = False,
6080
**kwargs):
6181

6282
platform = sipeed_tang_nano_20k.Platform(toolchain=toolchain)
6383

84+
with_hdmi = with_video_terminal or with_video_colorbars
85+
6486
# CRG --------------------------------------------------------------------------------------
65-
self.crg = _CRG(platform, sys_clk_freq)
87+
self.crg = _CRG(platform, sys_clk_freq, with_hdmi=with_hdmi)
6688

6789
# SoCCore ----------------------------------------------------------------------------------
6890
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Tang Nano 20K", **kwargs)
6991

70-
# TODO: XTX SPI Flash
92+
# SPI Flash: XT25F64B ----------------------------------------------------------------------
93+
if with_spi_flash:
94+
from litespi.modules import W25Q64 as SpiFlashModule # compatible with XT25F64B
95+
from litespi.opcodes import SpiNorFlashOpCodes as Codes
96+
self.add_spi_flash(mode="1x", module=SpiFlashModule(Codes.READ_1_1_1))
7197

7298
# SDR SDRAM --------------------------------------------------------------------------------
7399
if not self.integrated_main_ram_size:
@@ -94,6 +120,15 @@ def __init__(self):
94120
l2_cache_size = 128,
95121
)
96122

123+
# Video ------------------------------------------------------------------------------------
124+
if with_hdmi:
125+
self.videophy = VideoGowinHDMIPHY(platform.request("hdmi"), clock_domain="hdmi")
126+
if with_video_terminal:
127+
# self.add_video_terminal(phy=self.videophy, timings="800x600@60Hz", clock_domain="hdmi")
128+
self.add_video_terminal(phy=self.videophy, timings="640x480@60Hz", clock_domain="hdmi")
129+
if with_video_colorbars:
130+
self.add_video_colorbars(phy=self.videophy, timings="800x600@60Hz", clock_domain="hdmi")
131+
97132
# Leds -------------------------------------------------------------------------------------
98133
if with_led_chaser:
99134
self.leds = LedChaser(
@@ -125,14 +160,23 @@ def main():
125160
parser = LiteXArgumentParser(platform=sipeed_tang_nano_20k.Platform, description="LiteX SoC on Tang Nano 20K.")
126161
parser.add_target_argument("--flash", action="store_true", help="Flash Bitstream.")
127162
parser.add_target_argument("--sys-clk-freq", default=48e6, type=float, help="System clock frequency.")
163+
parser.add_target_argument("--with-spi-flash", action="store_true", help="Enable SPI Flash (MMAPed).")
164+
parser.add_target_argument("--with-rbg-led", action="store_true", help="Enable WS2812 RGB Led.")
128165
sdopts = parser.target_group.add_mutually_exclusive_group()
129166
sdopts.add_argument("--with-spi-sdcard", action="store_true", help="Enable SPI-mode SDCard support.")
130167
sdopts.add_argument("--with-sdcard", action="store_true", help="Enable SDCard support.")
168+
viopts = parser.target_group.add_mutually_exclusive_group()
169+
viopts.add_argument("--with-video-terminal", action="store_true", help="Enable Video Terminal (HDMI).")
170+
viopts.add_argument("--with-video-colorbars", action="store_true", help="Enable Video Colorbars (HDMI).")
131171
args = parser.parse_args()
132172

133173
soc = BaseSoC(
134174
toolchain = args.toolchain,
135175
sys_clk_freq = args.sys_clk_freq,
176+
with_rgb_led = args.with_rbg_led,
177+
with_spi_flash = args.with_spi_flash,
178+
with_video_terminal = args.with_video_terminal,
179+
with_video_colorbars = args.with_video_colorbars,
136180
**parser.soc_argdict
137181
)
138182
if args.with_spi_sdcard:

0 commit comments

Comments
 (0)