trellis: Pass speed grade argument to nextpnr
authorKonrad Beckmann <konrad.beckmann@gmail.com>
Tue, 7 Jan 2020 22:15:13 +0000 (23:15 +0100)
committerKonrad Beckmann <konrad.beckmann@gmail.com>
Wed, 8 Jan 2020 07:42:29 +0000 (08:42 +0100)
litex/build/lattice/trellis.py

index 770c336ced0fd8f50a6d248678434cd5add5d09e..dcc2e38dedaf868eb0517c84e8db83831f543de5 100644 (file)
@@ -99,16 +99,19 @@ def nextpnr_ecp5_package(package):
         return "CABGA756"
     raise ValueError("Unknown package {}".format(package))
 
+def nextpnr_ecp5_speed_grade(package):
+    return package[0] if package[0] in ["6", "7", "8"] else "6"
+
 # Script -------------------------------------------------------------------------------------------
 
 _build_template = [
     "yosys -q -l {build_name}.rpt {build_name}.ys",
     "nextpnr-ecp5 --json {build_name}.json --lpf {build_name}.lpf --textcfg {build_name}.config  \
-    --{architecture} --package {package} {timefailarg}",
+    --{architecture} --package {package} --speed {speed_grade} {timefailarg}",
     "ecppack {build_name}.config --svf {build_name}.svf --bit {build_name}.bit"
 ]
 
-def _build_script(source, build_template, build_name, architecture, package, timingstrict):
+def _build_script(source, build_template, build_name, architecture, package, speed_grade, timingstrict):
     if sys.platform in ("win32", "cygwin"):
         script_ext = ".bat"
         script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n\n"
@@ -124,6 +127,7 @@ def _build_script(source, build_template, build_name, architecture, package, tim
             build_name      = build_name,
             architecture    = architecture,
             package         = package,
+            speed_grade     = speed_grade,
             timefailarg     = "--timing-allow-fail" if not timingstrict else "",
             fail_stmt       = fail_stmt)
 
@@ -202,11 +206,12 @@ class LatticeTrellisToolchain:
         # Translate device to Nextpnr architecture/package
         (family, size, package) = platform.device.split("-")
         architecture = nextpnr_ecp5_architectures[(family + "-" + size).lower()]
+        speed_grade  = nextpnr_ecp5_speed_grade(package)
         package      = nextpnr_ecp5_package(package)
 
         # Generate build script
         script = _build_script(False, self.build_template, build_name, architecture, package,
-            timingstrict)
+            speed_grade, timingstrict)
 
         # Run
         if run: