Simplified formatting, list should now be numbered.
[libreriscv.git] / docs / learning_nmigen.mdwn
1 # Learning nmigen
2
3 * links to community <https://nmigen.info/nmigen/latest/tutorial.html>
4 * Useful counter tutorial (gtkwave and verilog) for latest nmigen <https://nmigen.info/nmigen/latest/start.html>
5 * Robert Baruch's nmigen tutorials are really good:
6 <https://github.com/RobertBaruch/nmigen-tutorial>
7 * <https://github.com/GuzTech/ulx3s-nmigen-examples>
8 * <https://github.com/icebreaker-fpga/icebreaker-nmigen-examples>
9 * <https://github.com/kbob/nmigen-examples>
10 * <https://vivonomicon.com/2020/04/14/learning-fpga-design-with-nmigen/54>
11 * <https://www.youtube.com/watch?v=yDJNwxY05-s>
12
13 # Sanity Check (*You'll need it*) Tutorial - Simulation Waveforms, Verilog, Block Diagram
14
15 ## Testbench, GTKWave, Verilog Output
16
17 * nMigen code for counter and testbench here: <https://nmigen.info/nmigen/latest/start.html>
18
19 1. Create a file called "up_counter.py" containing the 16-bit up counter code from "Implementing a counter" section.
20
21 1. Create a file called "tb_up_counter.py" containing the testbench from "Testing a counter".
22
23 1. To the testbench file, add the import statement "from up_counter import UpCounter" for the counter module (better get used to separating your sim/stimulus and module classes from the beginning):
24
25 1. Create a file called "conv_to_verilog.py" and copy the code from "Converting a counter" section. Also add the import statement as with the testbench.
26
27 1. Generate GTKWave .vcd file by running the testbench script.
28
29 1. Launch GTKWave. Now you should be able to inspect the signals and check counter behaviour (although the test bench also does this).
30
31 1. To generate the verilog equivalent, call the file we created earlier. The script will create a up_counter.v verilog file.
32
33 Commands:
34
35 $python3 tb_up_counter.py
36 $gtkwave up_counter.vcd &
37 $python3 conv_to_verilog.py
38
39 ## Block Digram with Yosys
40
41 1. Open yosys in interactive mode and load the generated verilog file. Calling "show" should generate the diagram .dot file (as a temp file "~/.yosys_show.dot") and open it using xdot. *You may need to install xdot separately with apt*. Xdot is **interactive** (you can click on blocks and nodes!).
42
43 Yosys commands:
44
45 $yosys
46 yosys> read_verilog up_counter.v
47 yosys> show
48
49 Outside of Yosys, commands for diagram (SVG format for static images also supported):
50
51 $xdot ~/.yosys_show.dot
52 $dot ~/.yosys_show.dot -Tpng -o up_counter.png
53
54 Here's a sight to behold:
55
56 [[!img nmigen_verilog_tb.png size="600x"]]
57
58 Now you can improve your understanding with the nMigen, verilog, and block diagram views side-by-side!