{"id":487360,"date":"2016-10-06T14:17:15","date_gmt":"2016-10-06T13:17:15","guid":{"rendered":"http:\/\/antonpotocnik.com\/?p=487360"},"modified":"2018-07-01T14:21:41","modified_gmt":"2018-07-01T13:21:41","slug":"redpitaya-fpga-project-1-led-blinker","status":"publish","type":"post","link":"https:\/\/antonpotocnik.com\/?p=487360","title":{"rendered":"Red Pitaya FPGA Project 1 &#8211; LED Blinker"},"content":{"rendered":"<h1 style=\"text-align: justify;\">Introduction<\/h1>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/redpitaya.com\/\" target=\"_blank\">Red Pitaya<\/a> is a <a href=\"http:\/\/www.xilinx.com\/products\/silicon-devices\/soc\/zynq-7000.html\" target=\"_blank\">Zynq7 FPGA-<\/a>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 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Field-programmable_gate_array\" target=\"_blank\">field-programmable-gate-array (FPGA).<\/a> 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, <a href=\"http:\/\/redpitaya.com\/red-pitaya-as-sdr-transceiver\/\" target=\"_blank\">radio systems<\/a>, vector-network-analyzer, etc.<\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-487394\" src=\"https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/IMG_2895-e1475425225603.jpg\" alt=\"RedPitaya\" width=\"500\" height=\"333\" \/><\/p>\n<p style=\"text-align: justify;\">Available documentation for Red Pitaya&#8217;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.<\/p>\n<p style=\"text-align: justify;\">Our projects will be similar to the ones made by <a href=\"http:\/\/pavel-demin.github.io\/red-pitaya-notes\/development-machine\/\" target=\"_blank\">Pavel Demin<\/a> where we will even use some of his\u00a0Red-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 <a href=\"http:\/\/bazaar.redpitaya.com\/\" target=\"_blank\">bazaar apps<\/a> and is thus unnecessarily complex. Instead we will start with a minimal system and gradually add new components.<\/p>\n<p style=\"text-align: justify;\">In the first post we will set up a development platform for\u00a0programming FPGA using Xilinx&#8217;s Vivado software and create the simplest example &#8211; a hardware equivalent of the Hello World &#8211; 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 <a href=\"http:\/\/redpitaya.com\/examples-new\/fpga-blink-led-tutorial\/\" target=\"_blank\">RedPitaya&#8217;s (for Vivado 2013.3)<\/a> or <a href=\"http:\/\/pavel-demin.github.io\/red-pitaya-notes\/development-machine\/\" target=\"_blank\">Pavel Demin&#8217;s (for Vivado 2016.2) <\/a>page.<\/p>\n<h1 style=\"text-align: justify;\">Installation<\/h1>\n<p style=\"text-align: justify;\">At this stage it is assumed that Red Pitaya is successfully connected the local network with an established ssh (or <a href=\"http:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/download.html\">Putty<\/a>) connection. If not, follow Red Pitaya&#8217;s official <a href=\"http:\/\/redpitaya.com\/quick-start\/\" target=\"_blank\">quick-start instructions<\/a>.<\/p>\n<p style=\"text-align: justify;\">For the FPGA development platform we will use <a href=\"https:\/\/www.xilinx.com\/support\/download.html\" target=\"_blank\">Xilinx&#8217;s Vivado Design Suite with SDK<\/a>. 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.<\/p>\n<p style=\"text-align: justify;\">To install Vivado follow these steps:<\/p>\n<ol style=\"text-align: justify;\">\n<li>Register, download and install latest <a href=\"https:\/\/www.xilinx.com\/support\/download.html\" target=\"_blank\">Vivado Design Suite with SDK.<\/a><\/li>\n<li>Obtain free WebPACK licence<\/li>\n<li>Optionally download and install <a href=\"https:\/\/www.xilinx.com\/support\/download\/index.html\/content\/xilinx\/en\/downloadNav\/design-tools.html\" target=\"_blank\">Lab tools <\/a><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">After the installation of Vivado is complete download project source files from <a href=\"https:\/\/github.com\/apotocnik\/redpitaya_guide\" target=\"_blank\">https:\/\/github.com\/apotocnik\/redpitaya_guide <\/a>or if git is installed execute in command prompt<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit clone https:\/\/github.com\/apotocnik\/redpitaya_guide.git\r\n<\/pre>\n<h1 style=\"text-align: justify;\"><\/h1>\n<h1 style=\"text-align: justify;\">LED blinker<\/h1>\n<p style=\"text-align: justify;\">Now, we are ready to build our first project <em>1_led_blink<\/em>. Open Vivado and in Vivado Tcl Console navigate to the base folder: <em>redpitaya_guide\/<\/em> . There execute the following line<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsource make_project.tcl\r\n<\/pre>\n<p style=\"text-align: justify;\"><em>make_project.tcl<\/em> automatically creates a full project in the <em>tmp\/1_led_blink\/<\/em> folder. Take a moment to examine the Block Design. If it is not open click on<em> Open Block Design<\/em> on the left-hand side of the window. When you are ready click <em>Generate Bitstream <\/em>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.<\/p>\n<p style=\"text-align: justify;\">When synthesis, implementation and bitstream generation are successfully finished the bit file can be found <em>at redpitaya_guide\/tmp\/1_led_blink\/1_led_blink.runs\/impl_1\/system_wrapper.bit<\/em><\/p>\n<p style=\"text-align: justify;\">Copy newly generated bit file to the RedPitaya&#8217;s <em>\/root\/tmp<\/em> folder using <a href=\"https:\/\/winscp.net\/eng\/index.php\" target=\"_blank\">WinSCP <\/a>or type the following commands in Linux console<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd redpitaya_guide\/tmp\/1_led_blink\/1_led_blink.runs\/impl_1\/\r\nscp system_wrapper.bit root@your_rp_ip:led_blink.bit\r\n<\/pre>\n<p style=\"text-align: justify;\">Finally, we are ready to program the FPGA with our own bitstream file located in the <em>\/root\/<\/em> folder on Red Pitaya. To program the FPGA simply execute the following line in the Linux console on your Red Pitaya (use Putty):<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncat \/root\/led_blink.bit &gt; \/dev\/xdevcfg\r\n<\/pre>\n<p style=\"text-align: justify;\">Now, you should see the 0th LED blink. Don&#8217;t worry, you did not destroy your Red Pitaya. If you want to roll back to the official Red Pitaya FPGA program run<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncat \/opt\/redpitaya\/fpga\/fpga_X.XX.bit &gt; \/dev\/xdevcfg\r\n<\/pre>\n<p style=\"text-align: justify;\">or simply restart Red Pitaya. In case you want to upload your bitstream during the boot-up follow <a href=\"http:\/\/pavel-demin.github.io\/red-pitaya-notes\/led-blinker\/\" target=\"_blank\">Pavel&#8217;s instructions<\/a> on how to create custom SD card for Red Pitaya.<\/p>\n<h2 style=\"text-align: justify;\">Description<\/h2>\n<p style=\"text-align: justify;\">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.<\/p>\n<p style=\"text-align: justify;\">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\u00a0(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.<\/p>\n<p style=\"text-align: justify;\">During the project creation the script specifies Red Pitaya&#8217;s FPGA part name <em>xc7z010clg400-1. <\/em>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 <em>Sources <\/em>tab under<em> Constraints\/constrs_1\/port.xdc <\/em>(or<em> redpitaya_guide\/cfg\/port.xdc<\/em>)<em>.<\/em><\/p>\n<div id=\"attachment_487407\" style=\"width: 1026px\" class=\"wp-caption alignleft\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-487407\" class=\"wp-image-487407 size-full\" src=\"https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_simple_bd.png\" alt=\"led_blink_simple_bd\" width=\"1016\" height=\"493\" srcset=\"https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_simple_bd.png 1016w, https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_simple_bd-300x146.png 300w, https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_simple_bd-768x373.png 768w\" sizes=\"auto, (max-width: 1016px) 100vw, 1016px\" \/><p id=\"caption-attachment-487407\" class=\"wp-caption-text\">Block Design of 1_led_blink project<\/p><\/div>\n<p style=\"text-align: justify;\">Next, the script adds the Zynq <em>processing_system7<\/em> block with Red Pitaya specific settings set by <em>redpitaya_guide\/cfg\/red_pitaya.xml<\/em>. 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 <em>processing_system7<\/em> can be found on the <a href=\"http:\/\/www.xilinx.com\/video\/soc\/zynq-processing-system-highlights.html\" target=\"_blank\">Xilinx&#8217;s video page<\/a>.<\/p>\n<p style=\"text-align: justify;\">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.<\/p>\n<p style=\"text-align: justify;\">To achieve LED blinking with an interval of around 1 s we use <em>FCLK_CLK0<\/em> clock from the <em>processing_system7<\/em> block running at 125 MHz. To reduce the frequency from 125 MHz to 1 Hz we connect FCLK_CLK0 to <em>32-bit Binary Counter<\/em> block and then to the <em>Slice<\/em> block which selects only 26th bit. The time interval of 26th bit is therefore<\/p>\n<pre>2 * 2^26\/125 MHz = 1.07 s.<\/pre>\n<p style=\"text-align: justify;\">The 26-th bit is finally wired to the led(0) which makes LED(0) blink on the Red Pitaya board.\u00a0You can change the size of the <em>Binary Counter<\/em> or the <em>Slice<\/em> 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 <em>Run Block Automation<\/em> option on top of the <em>Block Design<\/em> area which can automatically connects ports and even adds additional blocks when needed. Further information on how to use Vivado&#8217;s IP Integrator (Block Design) can be found in Xilinx <a href=\"http:\/\/www.xilinx.com\/support\/documentation\/sw_manuals\/xilinx2015_1\/ug994-vivado-ip-subsystems.pdf\">documentation<\/a>.<\/p>\n<h1 style=\"text-align: justify;\">Extension 1<\/h1>\n<p style=\"text-align: justify;\">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&#8217;s IP cores when right clicking on the empty space on the Block Design and choosing <em>Add IP &#8230;<\/em>. Don&#8217;t forget to change the <em>LEFT<\/em> attribute of the <em>led<\/em> port to 3.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/knightRider2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-488287 size-full\" src=\"https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/knightRider2.png\" alt=\"knightrider2\" width=\"1544\" height=\"485\" srcset=\"https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/knightRider2.png 1544w, https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/knightRider2-300x94.png 300w, https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/knightRider2-768x241.png 768w, https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/knightRider2-1024x322.png 1024w\" sizes=\"auto, (max-width: 1544px) 100vw, 1544px\" \/><\/a><\/p>\n<h1 style=\"text-align: justify;\">Extension 2<\/h1>\n<p style=\"text-align: justify;\">Instead of connecting our periodic signal to the LED (<em>led_o[0]<\/em>) we can also connect it to an extension port <em>exp_tri_p_io[0]<\/em> linked with the <em>DIO0_p<\/em> pin on the extension connector E1. Since the exp_tri_p_io is bidirectional we cannot simply wire it in the block_design. There are two ways to solve this problem. (1) Delete the <em>exp_tri_p_io<\/em> port and create a new one with the same name and different direction. You can create the port by right-clicking on the block design area and select <em>Create Port&#8230;<\/em> or modify a tcl command found on line 38 in <em>cfg\/port.tcl<\/em> file and execute it in the tcl console. (2) The second solution is much simpler. Use the following tcl command to connect your signal to the desired bidirectional port (<em>exp_tri_p_io<\/em>)<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nconnect_bd_net &#x5B;get_bd_pins xlconcat_0\/In0] &#x5B;get_bd_pins exp_p_tri_io]\r\n<\/pre>\n<p>We can check if the <em>DIO0_p<\/em> pin has a periodic signal by connecting it to the neighbouring pin <em>DIO0_n<\/em> on the E1 connector with an external wire. We can use the same technique to connect the corresponding <em>exp_tri_n_io[0]<\/em> port to the second LED in the block design. Check the <a href=\"http:\/\/redpitaya.readthedocs.io\/en\/latest\/developerGuide\/125-14\/extent.html\" rel=\"noopener\" target=\"_blank\">Extension connector&#8217;s manual<\/a> to locate appropriate pins. If all goes well, as soon as you connect <em>DIO0_p<\/em> and <em>DIO0_n<\/em> pins two LEDs should blink at the same time. Be careful when connecting any external signals to the E1 connector. Always check the voltage requirements first. The following schematics shows how to assemble the block design.<\/p>\n<p><a href=\"https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_io.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_io.png\" alt=\"\" width=\"1036\" height=\"149\" class=\"aligncenter size-full wp-image-566556\" srcset=\"https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_io.png 1036w, https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_io-300x43.png 300w, https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_io-768x110.png 768w, https:\/\/antonpotocnik.com\/wp-content\/uploads\/2016\/10\/led_blink_io-1024x147.png 1024w\" sizes=\"auto, (max-width: 1036px) 100vw, 1036px\" \/><\/a><\/p>\n<h1 style=\"text-align: justify;\">Conclusion<\/h1>\n<p style=\"text-align: justify;\">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&#8217;s Linux and used it to configure the programmable logic. Since here all Red-Pitaya specific components are present,<em> LED blinker<\/em> is an ideal starting point for more advanced projects.<\/p>\n<table width=\"100%\">\n<tbody>\n<tr>\n<td><\/td>\n<td align=\"right\"><a href=\"https:\/\/antonpotocnik.com\/?p=488784\">Red Pitaya Project 2 &#8211; The Knight Rider Lights &gt;&gt;<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1 style=\"text-align: justify;\">Useful References<\/h1>\n<ul>\n<li style=\"text-align: justify;\"><a href=\"http:\/\/www.redpitaya.com\">RedPitaya.com<\/a>, <a href=\"http:\/\/wiki.redpitaya.com\">Wiki<\/a>, <a href=\"http:\/\/forum.redpitaya.com\" target=\"_blank\">Forum<\/a>, <a href=\"http:\/\/redpitaya.readthedocs.io\/en\/latest\/\" target=\"_blank\">Documentation<\/a><\/li>\n<li style=\"text-align: justify;\"><a href=\"http:\/\/pavel-demin.github.io\/red-pitaya-notes\/\" target=\"_blank\">Pavel Demin&#8217;s Red Pitaya Notes<\/a><\/li>\n<li style=\"text-align: justify;\"><a href=\"http:\/\/redpitaya.com\/examples-new\/fpga-blink-led-tutorial\/\" target=\"_blank\">Red Pitaya Blink tutorial<\/a><\/li>\n<li style=\"text-align: justify;\"><a href=\"http:\/\/www.xilinx.com\/support\/documentation\/user_guides\/ug585-Zynq-7000-TRM.pdf\" target=\"_blank\">Xilinx Zynq 7000 Technical Manual<\/a><\/li>\n<li style=\"text-align: justify;\"><a href=\"https:\/\/www.youtube.com\/watch?v=-VE97r5XpEU&amp;list=PLRr5m7hDN9TKiMF5fhq3EyoOjQVHyZkry\" target=\"_blank\">Xilinx&#8217;s Zynq Video Tutorials<\/a><\/li>\n<li style=\"text-align: justify;\"><a href=\"https:\/\/www.youtube.com\/watch?v=zD-5LQCOelI\" target=\"_blank\">Youtube channel of MESD Research group <\/a><\/li>\n<li style=\"text-align: justify;\"><a href=\"http:\/\/redpitaya.readthedocs.io\/en\/latest\/developerGuide\/125-14\/extent.html\" target=\"_blank\">Extension connectors<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction 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&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[29],"tags":[],"class_list":["post-487360","post","type-post","status-publish","format-standard","hentry","category-fpga"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3Hjcy-22ME","_links":{"self":[{"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=\/wp\/v2\/posts\/487360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=487360"}],"version-history":[{"count":40,"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=\/wp\/v2\/posts\/487360\/revisions"}],"predecessor-version":[{"id":572463,"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=\/wp\/v2\/posts\/487360\/revisions\/572463"}],"wp:attachment":[{"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=487360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=487360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/antonpotocnik.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=487360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}