Showing results for 
Show  only  | Search instead for 
Did you mean: 

Zynq and MicroZed say “Hello World”-- Adam Taylor’s MicroZed Chronicles, Part 3

Xilinx Employee
Xilinx Employee
0 1 122K

By Adam Taylor –


A quick recap of the last two blogs shows we have defined our Zynq-based MicroZed system using Vivado and established the baseline within the Software Development Kit (SDK). Now we’re ready to create our first application. “Hello world” is the traditional program used to test the entire work flow for microprocessors and to get quick proof that the it’s working as intended (much like a flashing LED is the FPGA equivalent). Helpfully, SDK creates a hello world project for us. However, just using this application as is does not provide an understanding of what is happening or what’s required to write software for the Zynq All Programmable SoC so let’s look at this file in a little more detail.


If you open the helloworld.c file under the used_app src directory, you will find a pretty simple and short program after the comments at the top:


Image1 MicroZed Hello World Program Listing.jpg 


Two header files are included. The first, stdio.h, is contained within the standard C library. Header files contained within the standard C library can be found under the includes section of the software application.  You can tell that this header file is within the standard C library due to the angle brackets “< >” used to enclose the call.



Image2 MicroZed Hello World Include Files.jpg 


Stdio.h contains input and output functions for the Zynq system, provided that you have correctly configured the STDIN and STDOUT within the board support package (BSP) properties.


Image3 MicroZed BSP Settings.jpg 


The second header file, platform.h, is a local file. It is located with the other application files. This file contains the function prototypes for initializing and closing down the platform. If you open this file you will notice first the include guards to prevent multiple definitions of the header file followed by the function prototypes. You will also notice there is no code defining these functions. The functionality is defined within the pre-compiled Xilinx C Library, which I defined under the BSP and is seen in libxi.a. This library also contains a number of other functions for you to use. 


The source code for inclusions within this library can be seen under the libsrc directory within your BSP:


Image4 MicroZed libsrc files.jpg 



This file includes the stdio.h header, which can be used to send and receive data over the stdin and stdout ports. In this case, these ports are the Zynq All Programmable device’s UART located in the Processing System.


Using stdio.h can increase the size of the application file, which is not always desirable for embedded applications. Hence the example from Xilinx uses the PRINT function, which is declared under the libsrc->standalone_v3_08_a directory in your BSP folder. This function is a much simpler output routine. Information on this function and others can be found in Xilinx user guide UG643 (“OS and Libraries Document Collection”).


Because there is no header file for the PRINT function, the “Hello world” program defines the PRINT function prototype just after listing the include files. This definition allows the PRINT function within the main file to compile and link without error.


The main function follows. It calls the init_platform function, which as I explained above is defined within platform.h


The next line of code is the data we wish to output over the UART. This line uses the PRINT function to display the text entered between the quote marks. The final line of the code, “return 0,” stops the program.


Building and running the file as it appears above results in the following being displayed upon your terminal.


Image5 MicroZed Console Output.jpg 


The console window will also report the size of the ELF file which can be seen below:


Image6 MicroZed program size.jpg 


Changing the file to use the STDIO PRINTF function in place of the PRINT function dramatically increases the size of the program. For the Zynq-based MicroZed system, program size is not too important because we have lots of DDR SDRAM capacity. However, program size can be considerable for smaller MicroBlaze-based applications.


Image7 MicroZed program size with stdio.h printf.jpg 


I hope this explanation helps you to understand how the “Hello world” program works and what its dependencies and libraries are. In my next instalment, we will look at how we execute this program on the MicroZed board and the Zynq All Programmable SoC.


Image8 MicroZed console output with various print functions.jpg 


Note: To ensure the best demonstration, I commented out the stdio.h header file from the project when I used the PRINT function and did a similar sort of thing when using “printf” with the print function prototype.


This blog post is part 3 of an ongoing series of posts exploring the Avnet MicroZed evaluation board. Previous posts in the series:


Bringing up the Avnet MicroZed with Vivado


Adam Taylor’s MicroZed Chronicles: Setting the SW Scene

Tags (2)
1 Comment