# Get started with vivado 24.1

## Create a project

Open vivado, and then click `Create Project`.

<figure><img src="/files/AoTV9R1ZvwB971RyfCI2" alt=""><figcaption></figcaption></figure>

Specify the project name and location. I use the breathing light circuit to demonstrate.

<figure><img src="/files/RNHczNxFCw1VT0fG6uRf" alt=""><figcaption></figcaption></figure>

Select `RTL Project` and check `Do not specify sources at this time`.

<figure><img src="/files/I3Stff1O2H56geonw7zH" alt=""><figcaption></figcaption></figure>

Our device information is at [Our device](https://github.com/byrzhm/build-a-riscv-chip-from-scratch/blob/main/tools/broken-reference/README.md)

<figure><img src="/files/NofikOGc3f4VX1guiEt2" alt=""><figcaption></figcaption></figure>

To create the project, click `Finish`.

<figure><img src="/files/zP2uVPfMLcmCInar8TWr" alt=""><figcaption></figcaption></figure>

## Design

Now, it's time to add our verilog design source code.

<figure><img src="/files/xUy1A1j0ff2ppGCXtdAE" alt=""><figcaption></figcaption></figure>

First click `Create File`, and then specify the `File type` to `SystemVerilog` and `File name` to `led`.

<figure><img src="/files/CG8RPnfBeN5ONz17hbaz" alt=""><figcaption></figcaption></figure>

Here is `led.sv`. You can paste it in.

```verilog
module led (
    input sys_clk,
    input rst_n,
    output reg [3:0] led);
    
    parameter PERIOD = 32'd49_999_999;
    
    reg [31:0] timer_cnt;
    
    always@(posedge sys_clk or negedge rst_n) begin
        if (!rst_n) begin
            led <= 4'd0;
            timer_cnt <= 32'd0;
        end else if (timer_cnt >= PERIOD) begin
            led <= ~led;
            timer_cnt <= 32'd0;
        end else begin
            led <= led;
            timer_cnt <= timer_cnt + 32'd1;
        end
    end
    
endmodule
```

<figure><img src="/files/qGRntEV0hqeRDZcIajoS" alt=""><figcaption></figcaption></figure>

## Simulation

It's a good habit to write testbench for your verilog code. If you don't know how to write a testbench or you don't familiar with it, you should check the tutorials released by [EDAPlayground](https://www.edaplayground.com/), and here is the [link](https://www.youtube.com/playlist?list=PLScWdLzHpkAfbPhzz1NKHDv2clv1SgsMo).

<figure><img src="/files/8xithsX1as3wjraePqpu" alt=""><figcaption></figcaption></figure>

Just name it `testbench`.

<figure><img src="/files/2dUiCoLlpq2xvSIkna1d" alt=""><figcaption></figcaption></figure>

Here is `testbench.sv`. You can change the code as long as you fully understand it.

```verilog
`timescale 1ns / 1ps

module testbench;

    reg clk, rst_n;
    wire [3:0] led;
    
    led #(.PERIOD(4)) dut (
        .sys_clk(clk),
        .rst_n(rst_n),
        .led(led)
        );
        
    initial begin
        clk = 0;
        rst_n = 0;
        #5 rst_n = 1;
        
        #50;
        
        rst_n = 0;
        $5 $finish;
    end
    
    always #5 clk = ~clk;
    
endmodule
```

<figure><img src="/files/c1d3078cGrwmAyEZomHQ" alt=""><figcaption></figcaption></figure>

First click `Run Simulation`, and then click `Run Behavioral Simulation` to run simulation.

<figure><img src="/files/FuWWMNEWcKRCSiRfF9xx" alt=""><figcaption></figcaption></figure>

Here is the waveform.

<figure><img src="/files/NpfvnE73Zn3aQOYbnlUY" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Maybe you need to scale the waveform down. And you can drag dut (design under test) instance to the waveform to see the signals inside the instance.
{% endhint %}

## Schematic

Click `Open Elaborated Design`.

<figure><img src="/files/n7Iy4pCIgDwUYCVbNBC9" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/YZdCd2XTqdflwgN50T8F" alt=""><figcaption></figcaption></figure>

Click `Schematic`, and then you can see an intuitive diagram showing up in the editor area.

<figure><img src="/files/J343mLcr1jscNfkwZcPb" alt=""><figcaption></figcaption></figure>

## Pin planning

In `I/O Ports` window, set the `Package Pin` and `I/O Std`. The settings is related to our [device details](https://github.com/byrzhm/build-a-riscv-chip-from-scratch/blob/main/tools/broken-reference/README.md).

<figure><img src="/files/TMeMCN7tYtj2JQH7r3fa" alt=""><figcaption></figcaption></figure>

Click the upper left corner save icon to save the constrains. Just name it `led`.

<figure><img src="/files/AWC8ekEoxecg0EOLQpil" alt=""><figcaption></figcaption></figure>

You can see `led.xdc` created in your project.

<figure><img src="/files/MEZDs4H9lJ0b8AX0PC5j" alt=""><figcaption></figcaption></figure>

## Synthesis

Now run synthesis.

<figure><img src="/files/K3jlwvaNOpy7iNy61DQ0" alt=""><figcaption></figcaption></figure>

When synthesis completed, click `Cancel`. Because we need to add timing constraints first.

<figure><img src="/files/qdBa0tca52oGlbSDKRSP" alt=""><figcaption></figcaption></figure>

## Timing Constraints

Click `Contraints Wizard` and then click `Next`.

<figure><img src="/files/sd3GAxBZB5e96pLhGtyD" alt=""><figcaption></figcaption></figure>

Set the timing constraints and then click `Skip to Finish`.

<figure><img src="/files/jK5RRdg4QDyaUq3M4ZRb" alt=""><figcaption></figcaption></figure>

Click `Finish`.

<figure><img src="/files/F6xXbh7bPXJWQQSPk7y3" alt=""><figcaption></figcaption></figure>

You can see the timing constraints in `led.xdc` automatically generated.

<figure><img src="/files/adIXws1JFA2BIpHIa0dO" alt=""><figcaption></figcaption></figure>

## Generate Bitstream

Click `Generate Bitstream`.

{% hint style="info" %}
If you haven't run implementation before, vivado will give you a hint to run implementation and you just run it.
{% endhint %}

<figure><img src="/files/ZjFPUIKWCBhHndD9n9gz" alt=""><figcaption></figcaption></figure>

When bitstream generation completed, check `Open Hardware Manager` and then click `OK`.

<figure><img src="/files/aDFVgeDAXfEn5qvM5apT" alt=""><figcaption></figcaption></figure>

Make sure our device is connected and power on.

<figure><img src="/files/EndvY0hUPEWJYrUtYUnz" alt="" width="375"><figcaption></figcaption></figure>

Click `Open target` and then click `auto connect`. If the cable driver is correctly installed, you can see our device in the hardware window.

<figure><img src="/files/h6765MoTqSA9AcebNr0C" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Possible solutions to "vivado cannot find your device" (linux version):

`cd` to directory "`/path/to/Xilinx/Vivado/<vivado-version>/data/xicom/cable_drivers/lin64/install_script/install_drivers`".

* change "/path/to" to the real path to Xilinx for example "/tools" or "/opt"
* change "\<vivado-version>" to the real vivado version for example "2024.1"
* In the directory, there is a `install_drivers` script (same name as the directory name), run using command `sudo ./install_drivers`

[UG973](https://docs.amd.com/r/en-US/ug973-vivado-release-notes-install-license/Install-Cable-Drivers) may be useful to you.
{% endhint %}

<figure><img src="/files/TiwQMAe371zbilYgjWdR" alt=""><figcaption></figcaption></figure>

Right click our device `xc7z020_1`, and then click `Program Device`.

<figure><img src="/files/KKxGVQisLdkSZpi4QhQm" alt=""><figcaption></figcaption></figure>

Leave it the default Bitstream File and click `Program`.

<figure><img src="/files/bu7vfYJQvHJgPaBVZVpC" alt=""><figcaption></figcaption></figure>

Now, you can see the breathing light effect.

<figure><img src="/files/CyEJ00hfuISGYevJVx1a" alt=""><figcaption></figcaption></figure>

## References

* [Tsinghua](https://lab.cs.tsinghua.edu.cn/digital-logic-lab/doc/lab4/vivado_use/)
* [Alinx tutorial](https://www.bilibili.com/video/BV1JJ411u77d?p=2\&vd_source=571900c3ae9bbfdc988accacb2feb8be)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://byrzhm.gitbook.io/build-a-risc-v-chip-from-scratch/tools/get-started-with-vivado-24.1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
