This is a continuation of this post. I am trying to split these up a bit so those of us who are a bit more familiar with Zynq and Xilinx don't have to sift through so much information.
This post will describe what to do once you have exported your hardware from PlanAhead into SDK. We will write a simple HelloWorld program, and load it into the Zynq device on the Zedboard. Cool hu?
Ok, so here is our SDK window loaded with our embedded processor PlanAhead bit file output:
Those among us who have used Eclipse before will immediately be at home, as SDK is built around the Eclipse framework.
First we need to create a new standalone Board Support Package (BSP) to be used by the tools to interface to our hardware. We do this by going to File -> New -> Xilinx Board Support Package.
There are some things you can configure here, including what core you want your code to run on, but for this example we are going to keep the defaults and just click Finish.
The next screen you have the option to select certain libraries that Xilinx includes in it's tools.
I promise I'll do some great how-to's on some of these, but for now keep them all un-checked as we do not need them. Click OK.
At this point your Project Explorer view should looks very similar to this:
You may notice that your code directory is empty! oh noes! Well we better write some code to fill it up!
To add a new C project to our BSP we will go to File -> New -> Xilinx C Project.
This should default to a Hello World example template project. Perfect! There are a great number of project templates that we can pick from. Select the Hello World template, name it appropriately (I am keeping the default of hello_world_0). Click Next.
On this next screen we will see we have the option to create a new BSP or use the existing BSP that we have already created. Since we have one already, there is no sense in creating a new one. Select the radio button for "Target an existing Board Support Package" and make sure our BSP (named standalone_bsp_0) is selected. Click Finish.
Great! Now we have a C project, that will be loaded into our BSP within our hardware platform. Cool! If you go to your C project (hello_world_0) in the Project Explorer, and navigate to the src folder you will see the helloworld.c file. Check out the code. It's pretty simple, and straight forward.
There are two functions that are called within the int main() function: init_platform() and cleanup_platform(). Just make sure any code that you write is in between those two functions, and you are good to go. Those two functions handle all of the register initialization and cleanup that no one wants to fiddle with anyway :D.
Now that we have our hardware and our code we need to generate our linker script so we can compile our code for our hardware. To do this right mouse click on our C project (hello_world_0) and select "Generate Linker Script".
Since our design is so small we can fit into the on-chip memory. To point the linker script to this memory area we need to change the Code, Data, and Heap sections to ps7_ram_0_S_AXI_BASEADDR. Note that we can place the code into DDR, or the internal memory of either of the two processor cores. We will be placing the code into the memory of core 0.
The window's defaults should be the same as those above. Keep the Base Addresses the same, as well as the Heap and Stack Size. Our application is very small, we don't need more than 1K for either of those. Click Generate.
You will be asked if you want to overwrite the existing lscript.ld file. In this case we DO want to overwrite it, as it is setup to execute out of DDR, and we don't need to do that. Some output text will scroll in the Console window at the bottom of SDK, and you should see the linker script be written out successfully with no errors.
Now that we have a linker script, let's build our project. Right mouse click on the project (hello_world_0) and select Build Project.
Note that if autobuild is turned on then your Console will print out "Nothing to do for All". This is fine, it means that your project is already built. If you want to see the output of the build process right mouse click on your project and select "Clean Project" and then right mouse click again and select "Build Project". The output from the build process will scroll by in the Console at the bottom of SDK.
Ok, there are just three things left. First is the configuration of the jumpers on the Zedboard. In my Zedboard Bring Up post I talked about jumper configurations. For this we are going to put it into the Cascade JTAG mode. To do this we want to set all of our jumpers to Sig <-> GND like this:
Once you have your jumpers in the correct place we can can do the second, which is loading up Tera Term. Checkout the how-to on that within my board bring up post here.
The last thing is pushing our bit file and code to the board!
Before we continue we need to program the Programmable Logic (PL) portion of the FPGA so that all of our interconnects are configured correctly.
Right mouse click on our project (hello_world_0) and go down to the "Run As" option, and then "Run Configurations..." option.
We need to create our elf file that will be loaded via our JTAG chain. In the left tree view we can see "Xilinx C/C++ ELF" as an option. Double click this to have it create a new elf item.
Once the new item is created, with a default name of hello_world_0 Debug, we can see that a number of tabs of information has been pre-populated for us. Take a moment to go through the tabs to familiarize yourself with what is goes into creating the elf file. You can click Run when ever you are ready to launch your application.
You may get a window asking you if you want to load your code because it will reset the entire processor system. This is fine since we just want to load our code.
Well that's it! You're officially a bare-metal Zynq-7000 programmer!
If you followed all of the steps your screen should look like this: