Environment Setup

Get your system ready for Python-based verification. We'll install a simulator, a waveform viewer, and the Cocotb library.

Prerequisites

To run Cocotb, you need three main components:

  1. Python 3.6+: The programming language.
  2. HDL Simulator: To simulate the Verilog/SystemVerilog code (e.g., Icarus Verilog, Verilator).
  3. Cocotb Library: The bridge between Python and the simulator.

1. Install Simulator (Windows)

The easiest free simulator for Windows is Icarus Verilog.

  1. Download the installer from bleyer.org/icarus/.
  2. Run the installer. Crucial: Check the box "Add executable to your User PATH" during installation.
  3. Open a new command prompt (CMD) and type:
iverilog -v

If you see version information, it is installed correctly.

2. Install Cocotb

Cocotb is a standard Python package. Open your terminal or command prompt and run:

pip install cocotb

Verify the installation:

cocotb-config --version

3. Install Waveform Viewer

To debug your digital designs, you need to see the waveforms.

  • GTKWave: Usually included with the Icarus Verilog installer on Windows.
  • Check by typing gtkwave in your terminal.

Makefiles?

Cocotb typically uses Makefiles to automate the simulation flow. On Windows, you might need to install make.

Easy way: If you have Git Bash installed, you likely have `make`. Alternatively, install it via Chocolatey (`choco install make`).

Note: Starting from Cocotb 1.4+, you can also use Python runners to avoid Makefiles entirely! We will cover this in the Advanced section.