Skip to content

Commit 5c22d4a

Browse files
Merge pull request #746 from litex-hub/cyclonev_hps
terasic_de10nano: Add Cyclone V HPS (cyclonev_hps) CPU support
2 parents a9208ae + 077c076 commit 5c22d4a

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

litex_boards/targets/terasic_de10nano.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44
# This file is part of LiteX-Boards.
55
#
66
# Copyright (c) 2020 Paul Sajna <sajattack@gmail.com>
7+
# Copyright (c) 2026 Florent Kermarrec <florent@enjoy-digital.fr>
78
# SPDX-License-Identifier: BSD-2-Clause
89

10+
# Cyclone V HPS (MiSTer) use:
11+
# ./terasic_de10nano.py --cpu-type=cyclonev_hps --build [--with-mister-sdram] [--with-f2h-sdram]
12+
# Copy the bitstream to the MiSTer and load it:
13+
# scp build/terasic_de10nano/gateware/terasic_de10nano.rbf root@<mister-ip>:/media/fat/litex.rbf
14+
# ssh root@<mister-ip> "echo load_core /media/fat/litex.rbf > /dev/MiSTer_cmd"
15+
# LiteX CSRs are then accessible from the HPS at 0xff20_0000 (addresses in csr.csv), ex:
16+
# devmem <ctrl_scratch_addr> -> 0x12345678.
17+
918
from migen import *
1019

1120
from litex.gen import *
@@ -16,6 +25,7 @@
1625

1726
from litex.soc.cores.clock import CycloneVPLL
1827
from litex.soc.integration.soc import *
28+
from litex.soc.integration.soc import SoCRegion
1929
from litex.soc.integration.builder import *
2030
from litex.soc.cores.video import VideoVGAPHY
2131
from litex.soc.cores.led import LedChaser
@@ -65,6 +75,8 @@ def __init__(self, sys_clk_freq=50e6,
6575
with_led_chaser = True,
6676
with_mister_sdram = True,
6777
with_mister_video_terminal = False,
78+
with_h2f_bridge = False,
79+
with_f2h_sdram = False,
6880
sdram_rate = "1:1",
6981
**kwargs):
7082
platform = terasic_de10nano.Platform()
@@ -73,8 +85,40 @@ def __init__(self, sys_clk_freq=50e6,
7385
self.crg = _CRG(platform, sys_clk_freq, with_sdram=with_mister_sdram, sdram_rate=sdram_rate)
7486

7587
# SoCCore ----------------------------------------------------------------------------------
88+
if kwargs.get("cpu_type", None) == "cyclonev_hps":
89+
kwargs["with_uart"] = False # Console is on HPS UART0 (Linux on MiSTer).
90+
kwargs["integrated_sram_size"] = 0 # SRAM region is in HPS DDR3 (Linker-only).
7691
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on DE10-Nano", **kwargs)
7792

93+
# Cyclone V HPS Integration ----------------------------------------------------------------
94+
if kwargs.get("cpu_type", None) == "cyclonev_hps":
95+
# HPS DDR3 Regions (Linker-only, enable BIOS compilation as on Zynq targets).
96+
self.bus.add_region("sram", SoCRegion(
97+
origin = self.cpu.mem_map["sram"],
98+
size = 15 * MEGABYTE,
99+
))
100+
self.bus.add_region("rom", SoCRegion(
101+
origin = self.cpu.mem_map["rom"],
102+
size = 8 * MEGABYTE,
103+
linker = True,
104+
))
105+
# H2F Bridge (LiteX bus/Fabric SDRAM visible to the ARM at 0xc000_0000).
106+
if with_h2f_bridge or with_mister_sdram:
107+
self.bus.add_master(name="h2f", master=self.cpu.add_axi_h2f_master())
108+
# F2SDRAM Port 1 (64-bit): first 256MB of HPS DDR3 visible on the LiteX bus at
109+
# 0xd000_0000 (non-coherent with the ARM caches; useful for Fabric DMAs and as a
110+
# F2SDRAM smoke test from the ARM through the H2F bridge).
111+
if with_f2h_sdram:
112+
from litex.soc.interconnect.avalon import Wishbone2AvalonMM
113+
f2h_sdram_region = SoCRegion(origin=0xd000_0000, size=256 * MEGABYTE)
114+
self.f2h_sdram = Wishbone2AvalonMM(
115+
data_width = 64,
116+
avalon_address_width = 29,
117+
avalon_base_address = f2h_sdram_region.origin >> 3,
118+
)
119+
self.comb += self.f2h_sdram.w2a_avl.connect(self.cpu.add_fpga2sdram_port(n=1))
120+
self.bus.add_slave(name="f2h_sdram", slave=self.f2h_sdram.w2a_wb, region=f2h_sdram_region)
121+
78122
# SDR SDRAM --------------------------------------------------------------------------------
79123
if with_mister_sdram and not self.integrated_main_ram_size:
80124
sdrphy_cls = HalfRateGENSDRPHY if sdram_rate == "1:2" else GENSDRPHY
@@ -104,13 +148,17 @@ def main():
104148
parser.add_target_argument("--sys-clk-freq", default=50e6, type=float, help="System clock frequency.")
105149
parser.add_target_argument("--with-mister-sdram", action="store_true", help="Enable SDRAM with MiSTer expansion board.")
106150
parser.add_target_argument("--with-mister-video-terminal", action="store_true", help="Enable Video Terminal with Mister expansion board.")
151+
parser.add_target_argument("--with-h2f-bridge", action="store_true", help="Enable H2F bridge (with cyclonev_hps CPU).")
152+
parser.add_target_argument("--with-f2h-sdram", action="store_true", help="Enable F2SDRAM port (with cyclonev_hps CPU).")
107153
parser.add_target_argument("--sdram-rate", default="1:1", help="SDRAM Rate (1:1 Full Rate or 1:2 Half Rate).")
108154
args = parser.parse_args()
109155

110156
soc = BaseSoC(
111157
sys_clk_freq = args.sys_clk_freq,
112158
with_mister_sdram = args.with_mister_sdram,
113159
with_mister_video_terminal = args.with_mister_video_terminal,
160+
with_h2f_bridge = args.with_h2f_bridge,
161+
with_f2h_sdram = args.with_f2h_sdram,
114162
sdram_rate = args.sdram_rate,
115163
**parser.soc_argdict
116164
)

0 commit comments

Comments
 (0)