Skip to content

Instantly share code, notes, and snippets.

@olofk
Created Dec 5, 2021
Embed
What would you like to do?
set_io q[0] 27
set_io q[1] 25
set_io q[2] 21
set_io q[3] 23
set_io q[4] 26
set_io q[5] 11
set_io q[6] 37
set_io i_clk 35
set_io i_rst 10
module counter
#(parameter width = 8)
(input wire i_clk,
input wire i_rst,
output reg [width-1:0] q);
always @(posedge i_clk) begin
q <= q + 1;
if (i_rst)
q <= {width{1'b0}};
end
endmodule
from edalize import get_flow
Flow = get_flow("lint") # Get the class for the lint flow
edam = {} #Create an initial EDAM file
edam["name"] = "counter_test" # Set name of the design
#Set all (one) files with their file type and optional attributes
edam["files"] = [{"name" : "counter.v", "file_type" : "verilogSource"}]
#Set flow_options for the lint flow. Flow.get_flow_options() lists all options
edam["flow_options"] = {"tool" : "verilator"}
edam["toplevel"] = "counter" # Set toplevel module name
#Set the design parameter width to an integer with the value 9
edam["parameters"] = {"width": {
"datatype": "int", "default" : 7, "paramtype" : "vlogparam"}}
#Create an instance of the flow class with the EDAM and output directories as inputs
lint = Flow(edam, '.')
lint.configure() # Create the flow graph and all configuration files
#Build the design. In the case of the linter flow this means compile and run linter
try:
lint.build()
except RuntimeError as e:
print(e)
exit(1)
#Let's run an FPGA flow now using the icestorm flow
Flow2 = get_flow("icestorm")
#We reuse the EDAM but change flow_options to relevant options for the icestorm flow
edam["flow_options"] = {"nextpnr_options" : ["--up5k", "--package", "sg48"]}
#We also add a pin constraint file
edam["files"].append({"name" : "counter.pcf", "file_type" : "PCF"})
#And again we instantiate the flow, set up the tools and build the design
icestorm = Flow2(edam, '.')
icestorm.configure()
#During the configure stage all project files and the flow graph (e.g. Makefile) is set up, but no EDA tools are run. This means we can do everything up until the build step on one machine and then export the design to another machine doing the actual build if we want. The second machine does not need to have Edalize installed
icestorm.build()
#Now we have a bitstream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment