📜 ⬆️ ⬇️

The first project on FPGA Altera and USB-Blaster connection in Linux



We continue to master the FPGA Altera. In the first part, I described the installation process of Altera Quartus software under CentOS7. Now we’ll finally try to do something “iron”, for example, LED lighting. But before a small entry.

One of my areas of activity is teaching in the robotics group in a small town in Belarus. Having plunged into this whole kitchen and having participated in various contests not only as a team coach, but also as a judge, I came to the conclusion that in particular arduino and microcontrollers are not the best base for competitive robots in general (I’m silent in general). It is more effective to solve many tasks at the level of bare electronics. In addition, 90% of the circles and “schools” of robotics do not even provide basic knowledge of electronics, focusing purely on “learning” the programming of finished structures. But purely electronic robots (for example, undeservedly forgotten BEAM) are sharpened for a specific task and changing the conditions of the competition will lead to the need for a significant restructuring of the robot, which is not always possible. Here I remembered about the programmable logic. As a result of searching for information on the use of FPGAs in training, I came across the blog of Yuri Panchul YuriPanchul . Taking this opportunity, I want to publicly express my gratitude to him. Thanks to him, our circle received a free TerasIC DE0-CV with Altera Cyclone V on board.
')
Actually this and subsequent publications will be a real educational material, which we implement on the circle. And I will be grateful for constructive criticism and comments, as the use of FPGAs on the circles for schoolchildren is an area that is not yet similar.

So here we go. This publication will describe the first steps in Quartus, the description of elementary digital logic in the Verilog language, and the upload of the configuration to the Altera Cyclone V FPGA. We will work with the TerasIC DE0-CV board, which has an onboard USB Blaster on board. We will also touch upon the issue of “launching” USB-Blaster under Linux.

Launch Quartus:



Select "Create a New Project". The dialogue of the project creation wizard is launched. Then simply click Next.



And now we need to choose a working directory for the project (do not forget about access rights!). We invent the name of the project:



In the next step, we are offered to add additional files to the project. At this stage, we do not need it, but in the future, to facilitate the work, we should add at least the output destination file.



Now it is time for important settings. At this step, we need to choose a crystal for which the project is written. In principle, if you make a mistake or want to recompile a project for another device, this can be corrected later.



Here we are offered to choose additional tools. We still leave everything as it is and click Next.



Well, we have completed the initial settings and created the project. Click Finish.



Now we need to create a file that describes the logic of the project. Go to the menu File / New , a dialog appears in which you want to select the type of file. In principle, the logic can be drawn in a special graphic editor, but now we select Verilog HDL File:



The file is created, we write the text of our program describing the elements NO, AND, OR, XOR . As inputs, we use switches on the board (key *), and the output state is indicated by LEDs (led *). A small remark: the manufacturer of the board offers to create a configuration file for I / O in a special program that works only under Windows. If you go this way, you need to make sure that the names of the "wires" and "registers" in the program coincide with those in the configuration file. But we will now do everything manually, so we are free to choose any names.



Now save the file. The important point is that for correct operation it is necessary that the file name coincides with the name of the module described in the program (In our example, basic_logic ).

image

Now you need to make a number of settings for the successful compilation of the project. First, we point out which module we have is the main one. Specifically in this project it is not relevant, but for complex projects with multiple modules, this step is required. Go to the menu Project / Set As Top Level Entity. Is done. Next, you need to make a number of settings for a particular crystal. Select the menu item Assignments / Device . A dialogue opens in which we have the opportunity to change the type of crystal (or check that we previously indicated it correctly):



Now press the Device and Pin Option button and in the dialog that opens, first set the status for unused pins. By default, all unused pins on the chip are connected to zero by power. But we do not know how these conclusions are physically separated on the board, and such a configuration can lead to a short circuit and failure of the chip. Therefore, it is safer to make unused pins with high impedance inputs - As input tri-stated



The next necessary step is to indicate which physical legs of the chip correspond to the inputs and outputs of the module described by us. To do this, go to the menu Assignments / Assignment Editor. In the window that opens, we make the assignments we need according to the scheme of our board. In the To column enter the name of the input or output. In the Assignment Name column, select the Location setting we need from the list. In the Value column we enter the name of the contact of the microcircuit:



A logical question: where does the name of the contacts come from? Usually there is a PIN OUT label on the datasheet for a card or a specific chip. Just as I wrote earlier, a special program can be created with the board that creates the configuration file. And now you can use this data:



Finally, you can click the Start Compilation button!





We receive 16 warnings. Nothing serious.



You can see the report:



Now connect the board and run the programmer program: Tools / Programmer. Linux automatically picks up the USB-Blaster, but the firmware does not work ... Well, open your favorite console, arm yourself with a tambourine and dive into the documentation for Quartus ...

First, make sure that the system sees the programmer:

dmesg | tail 



Go to the folder /etc/profile.d/ , where we create the file custom.sh



And then in the /etc/udev/rules.d/ folder a file called 51-usbblaster.rules and fill it
meaning:



Now everything works and the firmware is perfectly loaded into the chip:



We admire the result, play with the switches, blinking LEDs:

Source: https://habr.com/ru/post/310816/


All Articles