Migen is a Python tool which helps you to describe hardware(like Verilog and VHDL) in Python langauge. Like a C compiler which converts C language to assembly, Migen converts Python code to Verilog/VHDL statements. Migen helps in describing hardware in a more Object-oriented manner which would be hard to realise in Verilog/VHDL. A free and open source project (https://github.com/m-labs/migen), Migen is also used for designing the SoC (MiSoc) of an open source hardware project Milkymist One.
Migen toolset contains the Migen itself, the Mibuild and the simulator. Migen converts the Python code to Verilog/VHDL. Mibuild is for converting the Verilog/VHDL code to bitstream file and transfering to the FPGA. If your FPGA is not supported by Mibuild, you can add support for it or you can paste your Verilog/VHDL code to your FPGA tool. The simulator just integrates Migen with Icarus Verilog for simulation. Simulation requires a test bench which is also written in Python. I will explain here how to install Migen and the simulator. Installing Mibuild will be done later(once I get my FPGA board).
Though there exist a tutorial about installing and using Migen, I faced some problems while installing in my Ubuntu machine which was not as per the tutorial. After reading this post, I would recommend to read the official tutorial from the Migen page. This will provide some more clarity. Also make sure to read this post complete before proceeding on your machine.
1) Make sure you have installed Python3, setuptool and git. On an Ubuntu machine this can be done using the below command
sudo apt-get install git python3 python3-setuptools
2) Get the Migen tool to your machine
git clone https://github.com/m-labs/migen.git
3) Move into Migen folder and install
python3 setup.py install
Note: There is an option to use Migen – without installation! Just you need the project in your machine. Show the path to Python so that next time when you import Migen modules, Python will search those paths. For this you don’t need the python3-setuptools mentioned in Step 1. Clone the project to the machine using Step 2 and then run
Now the simulator installation. Once you are inside the Migen folder(
cd migen), move into the vpi folder using
cd vpi. We need to run the make file inside the vpi folder. But before that there are some more things to be done.
1) Install Icarus Verilog which is the actual simulator. Also the simulator generates a wave dump of the simulation which can be viewed using GTKWave.
sudo apt-get install verilog gtkwave
2) Run the following commands inside the vpi folder to install the Migen simulator.
sudo make install
You might get an error while running sudo make install. In my machine the error was
install: accessing ‘/usr/lib/ivl’: No such file or directory
This might be beacuse the path were Icarus Verilog is installed might be at a different location. A peak into the Makefile and also to the error can give you some hints on what to search for. I need to find where the ivl folder is. For that I used the find command
find /usr/ -name ivl\*. I have to pass the new found path (/usr/lib/i386-linux-gnu/ivl) to the make install command. Run the following to install
sudo make install INSTDIR=/usr/lib/i386-linux-gnu/ivl/
Thats it! You have successfully installed Migen and its simulator.
There is another tutorial about Migen. Read it – Designing a D flip-flop using Migen