Skip to content

Instantly share code, notes, and snippets.

@awygle
Created August 28, 2020 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awygle/58b718f7ce3337da7193e5c800a7e2a6 to your computer and use it in GitHub Desktop.
Save awygle/58b718f7ce3337da7193e5c800a7e2a6 to your computer and use it in GitHub Desktop.
def freq_check(module, ports, freq):
from nmigen._toolchain.yosys import find_yosys
from nmigen._toolchain import require_tool
from nmigen.back import verilog
from tempfile import mkstemp
import os
from subprocess import Popen, PIPE
clean_ports = []
print(ports)
for p in ports:
if isinstance(p, Pin):
if p.dir == 'i':
clean_ports.append(p.i)
elif p.dir == 'o':
clean_ports.append(p.o)
elif p.dir == 'io':
clean_ports.append(p.i)
clean_ports.append(p.o)
clean_ports.append(p.oe)
else:
clean_ports.append(p)
yosys = find_yosys(lambda ver: ver >= (0, 9))
nextpnr = require_tool("nextpnr-ecp5")
print(clean_ports)
v = verilog.convert(module, ports=clean_ports)
with open('debug.v', mode='w') as f:
f.write(v)
(f, p) = mkstemp(text=True)
with os.fdopen(f, mode="w") as f:
f.write(v)
f.seek(0)
yosys.run(["-f", "verilog", "-b", "json",
"-p", "synth_ecp5 -abc9",
"-o", 'out.json', p])
popen = Popen([nextpnr, "-r", "--12k", "--package", "CABGA256", "--speed", "6",
"-l", "log.txt", "--json", 'out.json', "--out-of-context", "--placer", "sa",
"--placed-svg", "out.svg", "--freq", str(freq/1e6), "--write", "after.json"],
stdin=PIPE, stdout=PIPE, stderr=PIPE, encoding="utf-8")
stdout, stderr = popen.communicate()
print(stderr)
os.remove(p)
return popen.returncode == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment