Skip to content

Commit ee407b8

Browse files
authored
Merge pull request #113 from zapta/main
Updated examples
2 parents 5f0e21e + 965db7f commit ee407b8

File tree

8 files changed

+120
-15
lines changed

8 files changed

+120
-15
lines changed
12 KB
Binary file not shown.

examples/alhambra-ii/pll/main.v

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,52 @@
22
//-- Using PLL for 48Mhz clock.
33
//------------------------------------------------------------------
44

5-
module main (
6-
input ext_clk, // 12MHz clock
7-
output LED // LED to blink
5+
module main #(
6+
parameter integer DIV = 8_000_000
7+
) (
8+
input ext_clk, // 12MHz clock
9+
output reg LED // LED to blink
810
);
911

10-
// PLL 12Mhz -> 28Mhz
12+
// PLL 12Mhz -> 48Mhz
1113
//
1214
// Generated with:
1315
// apio raw -- icepll -i 12 -o 48 -q -m -f pll.v
1416
// apio format pll.v
1517
//
1618
// (See pll.v for additional args that were added manually)
1719

20+
// 48 Mhz clock from the pll.
1821
wire sys_clk;
1922

23+
// Generates the main clock .
2024
pll pll (
21-
.clock_in(ext_clk),
22-
.clock_out(sys_clk),
25+
.clock_in(ext_clk), // In 12 Mhz
26+
.clock_out(sys_clk), // Out 48 Mhz
2327
.locked()
2428
);
2529

26-
reg [23:0] counter = 0;
30+
reg initialized = 1'b0;
31+
32+
reg [31:0] counter;
33+
34+
always @(posedge sys_clk) begin
35+
if (!initialized) begin
36+
// One time initialization.
37+
initialized <= 1'b1;
38+
LED <= 1'b1;
39+
counter <= 0;
40+
end else if (counter >= (DIV - 1)) begin
41+
// Delay reached, flip LED and and reset counter.
42+
LED <= !LED;
43+
counter <= 0;
44+
end else begin
45+
// Incrementing the delay counter.
46+
counter <= counter + 1;
47+
end
48+
end
2749

28-
always @(posedge sys_clk) counter <= counter + 1;
2950

30-
// Should blink at about 2.82Hz
31-
// 48M / 2^24 = 2.82
32-
assign LED = counter[23];
3351

3452
endmodule
3553

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[*]
2+
[*] GTKWave Analyzer v3.4.0 (w)1999-2022 BSI
3+
[*] Wed Jan 28 17:32:05 2026
4+
[*]
5+
[dumpfile] "/Volumes/projects/apio-examples-dev/repo/examples/alhambra-ii/pll/_build/default/main_tb.vcd"
6+
[dumpfile_mtime] "Wed Jan 28 17:30:44 2026"
7+
[dumpfile_size] 1283
8+
[savefile] "/Volumes/projects/apio-examples-dev/repo/examples/alhambra-ii/pll/main_tb.gtkw"
9+
[timestart] 0
10+
[size] 1000 600
11+
[pos] -1 -1
12+
*-15.913198 71800 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
13+
[treeopen] main_tb.
14+
[treeopen] main_tb.main.
15+
[sst_width] 253
16+
[signals_width] 136
17+
[sst_expanded] 1
18+
[sst_vpaned_height] 158
19+
@28
20+
main_tb.ext_clk
21+
main_tb.main.sys_clk
22+
@200
23+
-
24+
@28
25+
main_tb.main.initialized
26+
@200
27+
-
28+
@24
29+
main_tb.main.counter[31:0]
30+
@200
31+
-
32+
@29
33+
[color] 2
34+
main_tb.LED
35+
[pattern_trace] 1
36+
[pattern_trace] 0

examples/alhambra-ii/pll/main_tb.v

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
`timescale 1ns / 1ps
2+
3+
module main_tb;
4+
5+
// Inputs
6+
reg ext_clk = 0;
7+
8+
// Outputs
9+
wire LED;
10+
11+
// Instantiate the Unit Under Test (UUT)
12+
main #(
13+
.DIV(4) // Reduced for faster simulation.
14+
) main (
15+
.ext_clk(ext_clk),
16+
.LED(LED)
17+
);
18+
19+
// Continious clock
20+
always #5 ext_clk = ~ext_clk;
21+
22+
initial begin
23+
// Dump signals to Apio specified .vcd file.
24+
$dumpvars(0, main_tb);
25+
26+
// Run for 20 full clock cycles
27+
repeat (20) @(posedge ext_clk);
28+
29+
// Finish simulation
30+
$finish;
31+
end
32+
33+
endmodule

examples/alhambra-ii/pll/pll.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ module pll (
1616
output locked
1717
);
1818

19+
`ifdef SYNTHESIS
20+
21+
// Real implemenation using a primitive cell for synthesis.
22+
1923
SB_PLL40_CORE #(
2024
.FEEDBACK_PATH("SIMPLE"),
2125
.DIVR(4'b0000), // DIVR = 0
@@ -39,4 +43,13 @@ module pll (
3943
.DYNAMICDELAY()
4044
);
4145

46+
`else
47+
48+
// Fake implementation for simulation
49+
50+
assign clock_out = clock_in;
51+
assign locked = 1'b1;
52+
53+
`endif
54+
4255
endmodule

examples/sipeed-tang-nano-20k/blinky/blinky.cst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// See examples here https://github.com/sipeed/TangNano-20K-example
55

66
IO_LOC "sys_clk" 4;
7-
IO_PORT "sys_clk" PULL_MODE=UP BANK_VCCIO=1.8;;
7+
IO_PORT "sys_clk" PULL_MODE=UP IO_TYPE=LVCMOS33 BANK_VCCIO=3.3;
88

99
IO_LOC "led" 15; // Active low
10-
IO_PORT "led" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
10+
IO_PORT "led" PULL_MODE=UP DRIVE=8 IO_TYPE=LVCMOS33 BANK_VCCIO=3.3;
1111

1212
// Per https://github.com/YosysHQ/nextpnr/issues/1515
1313
CLOCK_LOC "sys_clk" BUFG;

examples/sipeed-tang-nano-20k/speed-test/pinout.cst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// See examples here https://github.com/sipeed/TangNano-20K-example
55

66
IO_LOC "CLK" 4;
7-
IO_PORT "CLK" PULL_MODE=UP BANK_VCCIO=1.8;;
7+
IO_PORT "clk" PULL_MODE=UP IO_TYPE=LVCMOS33;
88

99
IO_LOC "LED" 15; // Active low
10-
IO_PORT "LED" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
10+
IO_PORT "led" PULL_MODE=UP DRIVE=8 IO_TYPE=LVCMOS33;
1111

1212
// Per https://github.com/YosysHQ/nextpnr/issues/1515
1313
CLOCK_LOC "CLK" BUFG;

test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def test_example_env(
118118

119119
run_cmd(["apio", "build", "-e", env_name])
120120
run_cmd(["apio", "lint", "-e", env_name])
121+
run_cmd(["apio", "lint", "--nosynth", "-e", env_name])
121122
run_cmd(["apio", "graph", "-n", "-e", env_name])
122123
run_cmd(["apio", "report", "-e", env_name])
123124

@@ -128,6 +129,10 @@ def test_example_env(
128129
for testbench in testbenches:
129130
test_testbench_output(env_name, testbench)
130131

132+
# -- Test 'apio test --default'
133+
if testbenches:
134+
run_cmd(["apio", "test", "--default", "-e", env_name])
135+
131136
# -- Test 'apio sim' (default testbench)
132137
if testbenches:
133138
run_cmd(["apio", "clean"])

0 commit comments

Comments
 (0)