In [1]:
import magma as m
# default mantle target is coreir, so no need to do this unless you want to be explicit
# m.set_mantle_target("coreir")
In [2]:
from mantle import Counter
from loam.boards.icestick import IceStick
icestick = IceStick()
icestick.Clock.on()
icestick.D5.on()
N = 22
main = icestick.main()
counter = Counter(N)
m.wire(counter.O[N-1], main.D5)
m.EndCircuit()
To compile to coreir, we simply set the output parameter to the m.compile command to "coreir".
In [3]:
m.compile("build/blink_coreir", main, output="coreir")
We can inspect the generated .json file.
In [4]:
%cat build/blink_coreir.json
We can use the coreir command line tool to generate verilog.
In [5]:
%%bash
coreir -i build/blink_coreir.json -o build/blink_coreir.v
And now we can inspect the generated verilog from coreir, notice that includes the verilog implementations of all the coreir primitives.
In [6]:
%cat build/blink_coreir.v
In [7]:
%%bash
cd build
yosys -q -p 'synth_ice40 -top main -blif blink_coreir.blif' blink_coreir.v
arachne-pnr -q -d 1k -o blink_coreir.txt -p blink_coreir.pcf blink_coreir.blif
icepack blink_coreir.txt blink_coreir.bin
#iceprog blink_coreir.bin
In [ ]: