
By virtue of my professional activities, I have to work very closely with programming microcontrollers and FPGAs. But if mastering MK is more or less subject to even a housewife, then with FPGA some difficulties may arise. It is about the pitfalls and the look at them from above and I would like to tell you.
Step 0. Acquaintance
My first
shock of familiarity with the FPGA began with the installation of software that came with the debug board. A bunch of shortcuts on the desktop, incomprehensible programs, and with a different interface from each other - “the work is going to be interesting,” I thought. Tons of unintelligible manuals in English, incomprehensible terms for me, lack of simplest tutorials or user guides ... However, less than
six months passed, after trial and error on my thorny path, I can share my experience with a dashing share of competence. Immediately make a reservation, we will focus on Xilinx products: a debug board with a Spartan 3A DSP 1800A chip and the Xilinx ISE / EDK development environment.
Step 1. Bounce the Rig
Well, of course, for a
hello world hardware programmer, blink LEDs. After all, in order to send the cherished two words to the terminal, you still need to grow. The basis in this case should take the hardware description languages: a sweet couple Verilog and VHDL. They can also add the possibility of constructing circuits on primitive logic elements. Immediately I recall the institute course in computing: triggers, registers, logic elements, counters, multiplexers. But let's not get too far ahead, especially since it was described on Habré and to me. I will make a reservation, the Verilog / VHDL languages are far from being trivial, even in comparison with the assembler, therefore a completely different approach is needed to understand them.
Step 2. And if it is more difficult?
Despite the peculiarities with which the languages of the hardware description can scare away an inexperienced user, they have a huge plus: on the FPGA, you can implement a really very fast device, and the DSP modules offer just tremendous opportunities for digital signal processing. If we add to this the ready-made libraries with already implemented modules (IP Cores), then the possibilities are becoming more and more significant. However, it was not done without a fly in the ointment - laboriousness, or as they say, you can't figure it out without a bottle.
')
For the realization of the first two steps, the ISE bundle (aka Project Navigator) + ISim (simulation) + Impact (FPGA firmware) is suitable.
Step 3. Good old microcontroller
Sometimes, well, you just really want something nice ... Please, think about the SoC (System-on-Chip) system on a chip. In our case, this is the processor, bus, memory and a bunch of all peripherals. You can try to make the most similar systems (see step 2), you can fasten the found IP Cores on the Internet. But why reinvent the wheel? The smart guys from the Xilinx office have already invented the PicoBlaze and MicroBlaze soft processors. The first is an eight-bit processor, which is morally obsolete, has not been implemented in SoC for a long time and has open source code. The second, MicroBlaze, has quite good prospects: 32 bits, RISC-architecture, etc., etc.
As memory can be used as an external memory that is connected to the FPGA, and internal, implemented directly inside the FPGA. As a rule, the second is often used to cache instructions and data in the first. In addition, systems that contain more than one processor and use special communication modules for interprocessor communication are quite widely used.
There is a gigantic heap of all sorts of peripherals that can be used in huge quantities - everything is limited only by FPGA resources. In addition, “self-made” modules can be added to the bus exchange with the PLB periphery, but only if they work correctly.
At this stage, the most important tool is the Xilinx Project Stuido (XPS) from the Emedded Development Kit (EDK), by and large it is the output that allows you to get a ready-made FPGA hardware configuration file with the SoC placed on it.
Step 4. And now let's go
Now, as for writing a program for the same MicroBlaze. Included in the Xilinx software is the Software Development Kit (SDK), which allows you to write programs in C / C ++. Yes, yes, you heard right, C ++ is really a rarity for hardware, but not in our case. By the way, the SDK is Eclipse-based, so there is content assist, human refactoring, and also a car of tasty buns. Do not forget about the assembler: sometimes sometimes inserts on the asma are very useful.
GCC is used as a compiler, tailored to the needs of our software processor, it is possible to use RTOS under the expressive name XilKernel, which, by the way, is POSIX-compatible. This means that if a person is not by hearsay familiar with mutexes, threads and semaphores in UNIX-based systems, then it will not be difficult for him to figure out XilKernel.
Step 5. Instead of a resume
FPGA is a powerful and flexible tool that can solve a huge number of tasks. However, you should not try to hammer nails with a microscope - many tasks are perfectly solved on the same microcontrollers using cheaper and more accessible methods (Cortex M3, hello!).
Verilog, VHDL, Behavioral, Implementation - these and many other words can drive you crazy for a long time to scare off development using FPGA, but sometimes you can replace a bunch of outdated payouts with a dozen ancient MCs with one elegant chip and at the same time get a huge moral satisfaction!