Red Pitaya is a Zynq7 FPGA-based low cost electronic board with many components such as two core ARM processor, fast ADCs, fast DACs, USB, LAN, etc. In many aspects Red Pitaya is similar to the Arduino or Rasbery Pi with a large community of enthusiasts and increasing collection of open-source material. What makes Red Pitaya even better are the two fast ADCs, two fast DACs and most of all the programmable logic or field-programmable-gate-array (FPGA). With an on-chip FPGA Red Pitaya could be used for high performance computing, state-of-the-art measurement system, signal processing and much more. Having both linux-based processing system and programmable logic Red Pitaya is an ideal board for introduction to the FPGA programming and ultimately for building powerful professional and non-professional projects such as radar, radio systems, vector-network-analyzer, etc.
Available documentation for Red Pitaya’s FPGA development is at the moment rather scarce and can be quite confusing for total beginners. In this series of Red Pitaya FPGA projects I would like to reduce this confusion and help people to quickly start developing their own ideas.
Our projects will be similar to the ones made by Pavel Demin where we will even use some of his Red-Pitaya specific IP cores. Here posts will similarly not start with a modification of the official Red Pitaya source code as it contains many components required by bazaar apps and is thus unnecessarily complex. Instead we will start with a minimal system and gradually add new components.
In the first post we will set up a development platform for programming FPGA using Xilinx’s Vivado software and create the simplest example – a hardware equivalent of the Hello World – the LED blink. For convenience all steps presented here will be shown for Windows operating system, although most of them will also work on Linux. For more information regarding Vivado installation under Linux see RedPitaya’s (for Vivado 2013.3) or Pavel Demin’s (for Vivado 2016.2) page.
For the FPGA development platform we will use Xilinx’s Vivado Design Suite with SDK. At the time of writing the latest version was Vivado 2016.2, however, other versions would also work. The Vivado Suite can be installed for free with WebPACK licence, which can be downloaded after registration from their webpage.
To install Vivado follow these steps:
- Register, download and install latest Vivado Design Suite with SDK.
- Obtain free WebPACK licence
- Optionally download and install Lab tools
After the installation of Vivado is complete download project source files from https://github.com/apotocnik/redpitaya_guide or if git is installed execute in command prompt
git clone https://github.com/apotocnik/redpitaya_guide.git
Now, we are ready to build our first project 1_led_blink. Open Vivado and in Vivado Tcl Console navigate to the base folder: redpitaya_guide/ . There execute the following line
make_project.tcl automatically creates a full project in the tmp/1_led_blink/ folder. Take a moment to examine the Block Design. If it is not open click on Open Block Design on the left-hand side of the window. When you are ready click Generate Bitstream at the bottom-left part of the window to generate bitstream file. After you confirm that both Synthesis and Implementation will be executed beforehand the longer process starts.
When synthesis, implementation and bitstream generation are successfully finished the bit file can be found at redpitaya_guide/tmp/1_led_blink/1_led_blink.runs/impl_1/system_wrapper.bit
Copy newly generated bit file to the RedPitaya’s /root/tmp folder using WinSCP or type the following commands in Linux console
cd redpitaya_guide/tmp/1_led_blink/1_led_blink.runs/impl_1/ scp system_wrapper.bit root@your_rp_ip:tmp/led_blink.bit
Finally, we are ready to program the FPGA with our own bitstream file located in the /root/tmp/ folder on Red Pitaya. To program the FPGA simply execute the following line in the Linux console on your Red Pitaya (use Putty):
cat /root/tmp/led_blink.bit > /dev/xdevcfg
Now, you should see the 0th LED blink. Don’t worry, you did not destroy your Red Pitaya. If you want to roll back to the official Red Pitaya FPGA program run
cat /opt/redpitaya/fpga/fpga_X.XX.bit > /dev/xdevcfg
or simply restart Red Pitaya. In case you want to upload your bitstream during the boot-up follow Pavel’s instructions on how to create custom SD card for Red Pitaya.
Congratulations, you have just programmed your FPGA! But now, you are probably asking yourself what just happened? Let us quickly go though the most important steps to understand how we made one of the LEDs blink.
In this project we did not need to write any hardware description language (HDL) code. Instead we use IP cores which are a packaged code already available in Vivado and connect them in the IP Integrator. IP integrator (Block Design) is a useful addition to Vivado, which offers a visual representation of our program flow. It also helps us connect relevant blocks and navigate between our code. We will learn how to add our code as a block in the Block Design in the next project.
During the project creation the script specifies Red Pitaya’s FPGA part name xc7z010clg400-1. This information is important for synthesis, implementation and bitstream generation. Later, the script creates Red Pitaya specific external ports related to the chip pins as described in the constraint file shown in Sources tab under Constraints/constrs_1/port.xdc (or redpitaya_guide/cfg/port.xdc).
Next, the script adds the Zynq processing_system7 block with Red Pitaya specific settings set by redpitaya_guide/cfg/red_pitaya.xml. This IP core represents an interface between the processing system used for running Linux and the programmable logic (FPGA). There are many useful shared ports such as a clock (FCLK_CLK0), and communication interface ports (M_AXI_GPIO) which we will use in the future projects. Quick introduction to processing_system7 can be found on the Xilinx’s video page.
Some of the external ports are differential and therefore need to be properly handled. For this reason the script adds three buffers with differential ports (IBUFDS type) and connects them to those external ports (adc_clk_*, 2 x dasy_*). These buffers play no role in our LED blinking algorithm but should be there for proper implementation.
To achieve LED blinking with an interval of around 1 s we use FCLK_CLK0 clock from the processing_system7 block running at 125 MHz. To reduce the frequency from 125 MHz to 1 Hz we connect FCLK_CLK0 to 32-bit Binary Counter block and then to the Slice block which selects only 26th bit. The time interval of 26th bit is therefore
2 * 2^26/125 MHz = 1.07 s.
The 26-th bit is finally wired to the led(0) which makes LED(0) blink on the Red Pitaya board. You can change the size of the Binary Counter or the Slice position by double clicking on the block and changing its parameters. The connections (wires) are simply made by clicking on a free port and dragging it another port or wire. IP Integrator will check port types and sizes and allow a connection only if these are compatible. Sometimes IP Integrator offers a Run Block Automation option on top of the Block Design area which can automatically connects ports and even adds additional blocks when needed. Further information on how to use Vivado’s IP Integrator (Block Design) can be found in Xilinx documentation.
This concludes our first project. We have learned how to install Zynq FPGA Vivado development suite and created a simple project where we run the synthesis, the implementation and generated a bitstream file. We uploaded the bit-file to Red Pitaya’s Linux and used it to configure the programmable logic. Since here all Red-Pitaya specific components are present, LED blinker is an ideal starting point for more advanced projects.
One can play and create more exciting blinking LEDs sequences. For fun try changing blocks responsible for blinking to the following diagram and see what happens. For this you can use a number of available Xilinx’s IP cores when right clicking on the empty space on the Block Design and choosing Add IP …. Don’t forget to change the LEFT attribute of the led port to 3.
|Red Pitaya Project 2 – The Knight Rider Lights >>|