blinky_with_pll, works on hardware but verilator does not know how to handle the SB40_PLL_CORE yet

This commit is contained in:
2020-10-19 22:25:27 -05:00
parent 08ff4b2dbb
commit ccdfe6da64
6 changed files with 156 additions and 0 deletions

1
blinky_with_pll/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
blinky

48
blinky_with_pll/Makefile Normal file
View File

@@ -0,0 +1,48 @@
SIM_TARGET = build/blinky
BIN_TARGET = build/blinky.bin
PCF = iceFUN.pcf
YOSYS = yosys
PNR = nextpnr-ice40
IPACK = icepack
BURN = iceFUNprog
VERILATOR=verilator
VERILATOR_ROOT ?= $(shell bash -c 'verilator -V|grep VERILATOR_ROOT | head -1 | sed -e "s/^.*=\s*//"')
VINC := $(VERILATOR_ROOT)/include
SOURCE = blinky.v pll_100MHz.v
.PHONY: all burn
all: $(SIM_TARGET) $(BIN_TARGET)
# -GWIDTH=5 allows passing parameter to verilog module
obj_dir/Vblinky.cpp: $(SOURCE)
@echo "Running verilator"
@$(VERILATOR) --trace -Wall -Wno-fatal -GWIDTH=10 -cc blinky.v pll_100MHz.v ../toolchain-verilator/build-data/share/SB_PLL40_CORE.v --top-module blinky
obj_dir/Vblinky__ALL.a: obj_dir/Vblinky.cpp
@make --no-print-directory -C obj_dir -f Vblinky.mk
# std=c++11 flag is needed from verilator v4.100
$(SIM_TARGET): blinky.cpp obj_dir/Vblinky__ALL.a
@echo "Compiling simulation executable"
@mkdir -p build
@g++ -I$(VINC) -I obj_dir -std=c++11 $(VINC)/verilated.cpp $(VINC)/verilated_vcd_c.cpp \
$^ -o $@
@echo "Run simulation with ./$(TARGET)"
$(BIN_TARGET): $(SOURCE)
@echo "Building binary stream"
@mkdir -p ./build
@$(YOSYS) -p "synth_ice40 -top blinky -json build/blinky.json" -q $^
@$(PNR) -r --hx8k --json build/blinky.json --package cb132 \
--asc build/blinky.asc --opt-timing --pcf $(PCF) -q
@$(IPACK) build/blinky.asc build/blinky.bin
burn: $(BIN_TARGET)
@$(BURN) $<
.PHONY: clean
clean:
rm -rf obj_dir/ build/

View File

@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include "verilated.h"
#include "verilated_vcd_c.h"
#include "Vblinky.h"
void tick(int tickcount, Vblinky *tb, VerilatedVcdC* tfp) {
tb->eval();
if (tfp)
tfp->dump(tickcount * 10 - 2);
tb->sysclk = 1;
tb->eval();
if (tfp)
tfp->dump(tickcount * 10);
tb->sysclk = 0;
tb->eval();
if (tfp) {
tfp->dump(tickcount * 10 + 5);
tfp->flush();
}
}
int main(int argc, char **argv) {
// Call commandArgs first!
Verilated::commandArgs(argc, argv);
// Instantiate our design
Vblinky *tb = new Vblinky;
Verilated::traceEverOn(true);
VerilatedVcdC* tfp = new VerilatedVcdC;
tb->trace(tfp, 00);
tfp->open("build/waveform.vcd");
unsigned tickcount = 0;
int last_led = tb->o_led;
for(int k=0; k<(1 << 12); k++) {
tick(++tickcount, tb, tfp);
if (last_led != tb->o_led) {
printf("k = %7d, led = %d\n", k, tb->o_led);
}
last_led = tb->o_led;
}
}

22
blinky_with_pll/blinky.v Normal file
View File

@@ -0,0 +1,22 @@
`default_nettype none
module blinky(o_led, lcol1, sysclk);
parameter WIDTH = 24;
output wire o_led;
output wire lcol1;
input wire sysclk;
wire clk_100MHz;
wire locked;
pll_100MHz pll_0 (.clock_in(sysclk), .clock_out(clk_100MHz), .locked(locked));
reg [WIDTH-1:0] counter;
always @(posedge clk_100MHz)
counter <= counter + 1'b1;
assign o_led = counter[WIDTH-1];
assign lcol1 = 1'b0;
endmodule

View File

@@ -0,0 +1,5 @@
# For iceFUN board
set_io --warn-no-port o_led C10
set_io --warn-no-port sysclk P7
set_io --warn-no-port lcol1 A12

View File

@@ -0,0 +1,33 @@
/**
* PLL configuration
*
* This Verilog module was generated automatically
* using the icepll tool from the IceStorm project.
* Use at your own risk.
*
* Given input frequency: 12.000 MHz
* Requested output frequency: 50.000 MHz
* Achieved output frequency: 50.250 MHz
*/
module pll_100MHz(
input clock_in,
output clock_out,
output locked
);
SB_PLL40_CORE #(
.FEEDBACK_PATH("SIMPLE"),
.DIVR(4'b0000), // DIVR = 0
.DIVF(7'b1000010), // DIVF = 66
.DIVQ(3'b100), // DIVQ = 4
.FILTER_RANGE(3'b001) // FILTER_RANGE = 1
) uut (
.LOCK(locked),
.RESETB(1'b1),
.BYPASS(1'b0),
.REFERENCECLK(clock_in),
.PLLOUTCORE(clock_out)
);
endmodule