If you don't happen to have a $60 JTAG programming cable handy and you don't want to have to take the SD card out to reprogram the Snickrdoodle, then this post is for you. Now that file sharing is working, one can transfer the .bit file over to Linux and then flash it down to the FPGA. There is one catch however in that the .bit file can not be read by Linux as one must use the .bin file. This is why the project.tcl script file contains the below line of code.
The 'chmod' command gives execution privileges to the file and the cat command copies down the binary file to the FPGA. This method of transferring a .bin file to the FPGA can be very versatile as one could write a python program that can flash different images down to the FPGA based upon user input, or various circumstances.
The best way to transfer files between your Snickerdoodle and your PC is to setup a Samba file share on the Snickerdoodle that can be accessed via your PC. To do this a couple packages must be downloaded via the Linux prompt. Log into the Snickerdoodle and perform a 'sudo -i' to attain super user privileges. Then type:
path = /snickerdoodle
guest ok = yes
browsable = yes
create mask = 0775
directory mask = 0775
read only = no
force user = root
force group = root
Once you have saved the file, enter the below three lines at the command prompt:
Open up a Windows Explorer window and type \\xxx.xxx.xxx.xxx where the x's represent the Snickerdoodle IP address. For me it would be \\192.168.0.18
Once you enter the Snickerdoodle IP address you should see the contents of the /snickerdoodle folder which was the hello.txt file!
Congratulations you not have Snickerdoodle file sharing up and running!
The next couple blog posts are about configuring Linux on the Snickerdoodle. In order to do so, one must be able to communicate with the board via the USB port. You will need to download the STM USB-UART driver here before the Snickerdoodle is recognized by your computer. You will also need to download a terminal program such as Putty or TeraTerm. Once you have downloaded the UART driver an a terminal program, power on the Snickerdoodle by connecting it to the PC via the USB cable. After powering on, open up Tera Term, click the "Serial" option and select the STMicroelectronics Virtual Com Port. If you do not see the port you might have to unplug the Snickerdoodle, close Tera Term, and try it again. Make sure that you have a properly configured SD card installed in the system.
Once the system boots you will be prompted for some login information. The login and password for the factor default SD card image is 'snickerdoodle' and 'snickerdoodle'
After logging in you will be prompted to type in your own password.
After setting up your own password, be sure to write it down somewhere. The next step is to get super user privileges by typing 'sudo -i' and then your new password.
Also notice that when you type 'ifconfig' that wlan0 doesn't have any IP address associated with it. We will be fixing that in a bit.
Navigate to the /etc folder and type 'vi wpa_supplicant.conf' in order to open up the text editor.
You will need to modify your wpa_supplicant.conf file to match the one below. There will be two differences, namely the name of your routers SSID and your router password. Also for those that are not VI experts, here is a link to some useful VI commands. The technique I recommend is to type the network section into a text editor on your PC and then to copy it onto the PC clipboard. With Tera Term, one can simply right click and then paste the whole thing into the file. You may need to type "Shift i" beforehand though to put the VI editor into 'insert' mode.
After typing in your network credentials, save them by typing:
When you reboot, login, and then type 'ifconfig'. You should see that you now have a valid IP address from your router!
One of the problems with copying the system.bit file to the SD card for a firmware change is that one has to take the SD card out of the Snickerdoodle and load it into a PC. This is fine once or twice but it can get very frustrating when you am making many firmware updates.. especially late at night. A better way is to purchase a Breaky Breaky and a JTAG programming cable from Digilent like the one shown below and program the FPGA via JTAG. JTAG not only allows for programming without taking the SD card out of the Snickerdoodle but one can also perform real-time debugging of the FPGA with logic viewers and advanced triggering.
There is one interesting point to note however regarding how SD cards and JTAG play together. If you do not put an SD card in the Snickerdoodle and try to program the .bit directly via JTAG, the FPGA clock will be frozen. The reason for this is that the FPGA clock is initialized via the SD card boot sequence in the first stage boot loader. The way to successfully program the Snickerdoodle via JTAG is to follow the steps below.
The first step that has to be done before anything though is to generate a Vivado project and a .bit file. This can be done by pulling down the blink firmware project and the blink IP and compiling a project.
Remember that it doesn't matter where you save your blink project or your blink IP as long as the ip_repo_paths property is correctly set in the project.tcl file as shown below.
Onc can see that my VHDL IP folder is located two folders above the blink project as shown in the image below. Once the .bit file has been created open up Vivado.
When Vivado opens up click on the "Open Hardware Manager" text.
After the Hardware Manager opens up click on "Open target" and then "Auto Connect." Make sure that the JTAG programmer is plugged into the Snickerdoodle and that the Snickerdoodle is powered on either via USB or wall plug.
Hopefully the JTAG chain will be found and then you can click on "Program device."
Navigate to the system.bit output file and click "Program."
That should do it. Hopefully you see the LED blinking just the same as in the previous blog. If you want to mix it up, change the blink rate and try programming it again via JTAG.
The first thing you must do in order to setup your Snickerdoodle SD card is to pull down a disk imager utility such as win32 Disk Imager.
The next step is to pull down the Snickerdoodle Ubuntu 16.04 SD Card Image for the correct Snickerdoodle version. Once you unzip the image then copy it onto a blank SD card by use of the win32 Disk Imager by selecting the .img file and clicking "Write."
Once the image is finished writing you should be able to browse to the boot sector of the SD card via windows explorer and see the below files. Explaining what all of these files are is beyond the scope of this tutorial. However, all you need to know is that in order to boot with your .bit file loaded you must copy the .bit file into this directory and rename it to system.bit
Remember that the actual blink .bit file was located at the below directory: D:\craftDrones\firmware\blink\blink.runs\impl_1\design_1_wrapper.bit and that it needs to be copied to the boot sector as shown below.
Once the design_1_wrapper.bit file has been copied then rename it to system.bit in order for the boot files to recognize it.
If you just went through the last blog post about creating a Vivado project you are probably exhausted. Thankfully there is a much easier way to develop your VHDL code via a scripting methodology. This post will perform the exact same task as the previous post but with only the click of a single button. There are a couple steps that one needs to take however in order to setup the scripting environment. The first step is to make sure that the correct version of Vivado is listed on the system path. On Windows 7 you will need to open up the system properties window and then click on environment variables.
After you have added Vivado to the system path, pull down the blink.zip file and the blink_ip file shown below.
Remember that it doesn't matter where you save your blink project or your blink IP as long as the ip_repo_paths property is correctly set in the project.tcl file as shown below. We will cover the project.tcl file in the next section.
You can see in the below image that the blink.zip file contains a src folder as well as a project.tcl file and a batch file. The project.tcl file contains all of the Vivado project information that was generated via the GUI in the previous blog post, and the batch file simply kicks off the Vivado project file.
It is important to note that the script file has four main options that can be set by the user.
Inside the src folder there are two files.
After clicking on "startScript.bat" Vivado is kicked off in batch mode [no GUI appears] and a couple minutes later a system.bit and system.bin file magically show up in the project folder. These are the same files that were generated via the Vivado GUI a couple blog posts ago! I highly recommend only using the GUI for updating the block diagram as scripting is very efficient and makes for very easy versioning and code portability. Also if you do have any errors during the build process you can take a look at the vivado.jou file or open up the GUI for troubleshooting. Note that the system.bit file is the only file we care about right now as the system.bin file is used in a later post for flashing the FPGA image via Linux.
Now that you have Vivado all setup and some blink IP created, let's create a blink project. Click on the Vivado icon and then select "Create Project"
I chose to save my project in the firmware folder and I named my project blink. Note that a blink subfolder will be created within the firmware directory.
Click "Next" for the following three screens.
On this screen make sure to select the "Boards" icon and then select your Snickerdoodle board.
Click "Finish" and the Vivado project GUI will open up.
The first thing you need to do is to create a block diagram by clicking on the "Create Block Design" text on the left of the screen.
I typically leave the default design name of "design_1" but you can put in anything that you like. Then click "OK"
A new blank block diagram will be created and I typically like to maximize it.
The first part that will be added to every Zynq design is the actual Zynq processor. Add the part by clicking the + button and typing zynq into the IP search window as shown below.
After placing the Zynq block click on "Run Block Automation" to allow Vivado to connect up the block to various ports such as the DDR memory.
Leave the defaults here and click "OK." This will link up the DDR per the board preset file that we selected in the beginning of this tutorial.
Now that the DDR and fixed inputs/outputs are setup, connect the FCLK_CLK0 to the M_AXI_GPIO_ACLK port. This is somewhat confusing but it is basically connecting up the AXI system to the clock. Don't worry about the details but just know that one always has to perform this step.
Now that the Zynq block is all set it's time to add the blink IP package that we created before. The problem is that Vivado doesn't know where that IP is located. To show Vivado where our IP is located click on the "Settings" text on the left side of the scree.
Navigate to the Repository section and click the + button to add your repository to the list. Notice how I did not select the location of the blink IP but rather the location of the global IP folder which contains the blink IP.
You should get a pop-up windows stating that indeed the blink IP was added to the project.
Now go back to the block diagram and hit "CTRL + Q" in order to minimize the left hand toolbar. Now that you have a full screen block diagram do a right-click and select "Add IP" as shown below.
Start typing blink and you should see your IP show up.
Place your blink IP on the block diagram and connect it up as follows.
You will need to right-click on the blink_out port and select "Create Port" from the dropdown box.
Name the port "led" as this name will be used in the constraints file down the road.
Hit F6 or click on the icon shown in the image to validate your design. You should get a success pop-up as shown below.
Now click on the sources tab to the left of the screen as we need to create a VHDL wrapper to contain the block diagram.
Right-click on the design_1 text and click on the "Create HDL Wrapper" option from the dropdown list.
Typically I select to let Vivado manage my wrapper unless I am working on an advanced project.
When you hit "OK" you will see that a design_1_wrapper.vhd file is created. If you called your block diagram something different then the wrapper name might be different as well. Below I have shown the top portion of the wrapper file as viewed through notepad++. Notice that the top level entity lists all of the special DDR and fixed input/output pins as well as your new "led" pin. Every time you add any external port to the block diagram you need to make sure that Vivado successfully updates this file which it should do automatically if you selected that option previously.
The last thing to do before compiling the project is to add a constraints file so that Vivado knows which pin to send the led signal out to. Right-click on the constrs_1 text and select the "Add Sources" option from the dropdown list.
Click "Create File"
Type in "constraints" and click "OK"
Now you have a blank constraints file that needs to be populated.
One can either pull down the Snickerdoodle constrains file from github or just use this one which I have pulled down. Note that the constraints are located in the snickerdoodle_GPIO\snickerdoodle_GPIO.srcs\constrs_1\new folder if you pull it down from github.
The constraints file is setup for some of the Snickerdoodle example projects and we will need to modify it a bit. The below image shows that the constraint associated with the 4th pin on connector JA1 is G14.
At this point I highly recommend pulling down the snickerdoodle book which shows the location of the Snickerdoodle pins in the appendix. The image below shows exactly where pin JA1.4 is located on the JA1 connector.
Simply copy lines 15 and 16 from the original constraints file and paste them into your new constraints file. Don't forget to rename the signal to "led" as shown below.
Save the constraints file and click on "Generate Bitstream" in the lower left corner of the screen.
Go get a cup of coffee and when you return hopefully you will see the below window. Congratulations! You have created your first Vivado bit file. If you like you can view the reports, but after that feel free to exit Vivado.
After all of that hard work it can be very confusing about what to do next. The key thing to know is the location of your .bit file which is located in the directory below. Note that your directory can be a little different based upon your naming conventions.
Now that you have a blink .bit file the next step is to flash it onto the Snickerdoodle. There are two main ways to do this:
Now that you have Vivado installed and the snickerdoodle board files in place it's time to setup your IP and project folder structure. I like to put my IP folder on the same level as my firmware folder. The reason why I am not putting my IP folder in the firmware folder is that I have other non-vhdl subfolders such as c, eagle, python, etc in my IP folder. If you are only working with vhdl in your IP folder, one option is to put your IP folder inside your firmware folder. It really doesn't matter where you put your IP folder as long as it makes logical sense to you. Note: The green and red icons are from SVN version control... don't worry if you don't see them on your folders. I do highly recommend using version control though.
After you have your desired folder structure setup, copy the below blink.vhd file into the blink folder. For those new to vhdl, this file will accept a generic 'max_count' and the clock will count to that number before toggling the output. For example, with a 50 MHz input clock if 'max_count' is set to 25,000,000 which is its default, then the output bill blink at a 1 Hz rate.
Once you have copied the blink.vhd into the blink folder then open up Vivado and you should see the below screen. Click on the "Manage IP" text and then select "New IP Location" in order to open the Vivado IP manager.
Just click "Next" to proceed.
There are two things that need to be done with the below screen. The first thing is to click on the ... button under part and select the snickerdoodle board as shown in the Select Device image below. The next thing is to put in the location of your IP folder from the step above. Be sure not to put the location of the blink folder as this is the location of your global IP folder which contains the blink folder.
After hitting "OK" the vivado IP manager will open up and you should see something like the image below. Now that your IP location is setup you need to package the blink folder. Packaging is a process that basically adds a couple of files to your folder so that the IP can be imported into a vivado block diagram. So click on Tools => Create and Package New IP.
Click "Next" for the next two screens as we will be packaging a specific directory.
Select the blink directory located within your global IP directory.
I always just accept the defaults for the below screen but you could put in a specific directory if you like. Basically every packaged IP can have a full project associated with it but it is too much bloat for me. By using the default directories every IP directory that is packaged uses the same temporary project files. Don't worry about the details of this if you are a beginner and just click "Next"
Now you will be transported to the official blink IP packager. I changed the vendor information from xilinx.com to craftdrones but you can put in anything that you like. Like I said before, this is actually a full up vivado project that contains your blink code. I typically recommend clicking on "Run Synthesis" to verify that the code can at least compile before packaging it up.
Since I know that the code works I will skip synthesizing it and just click on the "Package IP" button which becomes visible when one clicks on the "Review and Package" button.
After the IP is packaged just close the project.
Back in the IP manager you will see that the blink IP has been created and resides in the UserIP folder as specified in the IP settings a couple screens ago. Congratulations! You have created your first vivado IP package.
For those of you that use version control you will want to know exactly what files were created by the packaging process. The actual blink.vhd file is unchanged however an xgui directory and a component.xml file have been created. The xgui is used to customize that appearance of the block that is placed within the vivado block editor and the component.xml file is used to hold all of the settings specified during the packaging process.
Now that you have some IP, you can finally create your first blink project and run it on your snickerdoodle!
Once you have Vivado installed the next thing you will need to do is install the snickerdoodle board files. These files make it easy to create a snickerdoodle project by loading in several snickerdoode specific defaults. The board files can be downloaded or cloned here.
After pulling down the files, they need to be copied into the Vivado board directory. On my computer it was:
After placing the board files into the Vivado directory, start up Vivado and you should see the below screen.
Click on "Create Project" and then click on "Next" through the next couple of windows until you hit the window below.
This project is just a test to see if the snickerdoodle board files are recognized by Vivado, so I just used a simple test folder for the project. I will cover how to create your first blink project in the next blog post. After entering the path for the project, hit "Next" until you see the below screen.
Click on the "Boards" icon in the top left and you should see the vairous snickerdoodle development boards show up. Congratulations! You are ready to create your first blink project.
So you just got your new Snickerdoodle and you are excited to hit the ground running. Before you can make your first LED blink you need to take a step back and install the Xilinx FPGA tool ecosystem. The first step is to Download Vivado which is the tool used to create VHDL designs for the FPGA portion of the Snickerdoodle. Below is a chart that shows the different versions of Vivado, and for this tutorial I chose the WebPACK as it's free and it will work with the 7010 and 7020 chips that are on the Snickerdoodle.
You can choose to pull down the entire 20 GB package or the web installer which is what I chose. I selected the top link since I am running Vivado on a Windows 7 computer.
After clicking your link of choice, save the file and then execute it to start up the installation process. You will either need to create a Xilinx account or sign in with an existing account.
Once the installer has downloaded, click on it in order to start the installation.
You might need to enter your Xilinx login information again, and then select the "Download and Install Now" option.
Check off all of the agreement boxes after closely reading all of the legal information..... or you can just check them as fast as you can and then hit "next."
Select the Vivado HL Webpack as it is free and is compatible with all Snickerdoodles.
For this step I chose the smallest installation possible. If you wan to try your hand at writing bare metal C code that can run on one or both of the linux processors I would recommend checking the Software Development Kit box. Note: This will add about 10 GB to your install.
I used the default install directory of C:\Xilinx but you can install it anywhere. Note: You will have to remember where you install Vivado for when you are adding it to your system path in order to enable scripting.
It should take around 30 min to pull down and install everything, but then you should get something that looks like the below screen shot. Congratulations you have just installed Vivado 2017.2.