top of page
Writer's pictureAdam Taylor

MicroZed Chronicles: Python Scripting Solutions with Vitis

To make my blogs and demonstrations illustrative I often use captures from the graphical user interface. However, professionally as an engineer I prefer to use scripting for our Vivado and Vitis projects. Using scripts provides us with a defined and repeatable process, it also enables us to easily work source control as we just need to control the scripts and the source code.

 

For decades TCL was the go to language for scripting of EDA tools, however, given pythons popularity across most domains it is natural that EDA tools are moving to include support for Python scripting.

 

In Vitis 2024.1 includes a Vitis python interpreter and CLI, in this blog we are going to examine how we can script the creation of a hardware platform and embedded application for an embedded application.

 

If you have Vitis installed you should see a Vitis console option, opening the console will enable us to start working with python.

 

Once this opens we are able to see the list of API commands available by clicking on the first line which will open a webpage containing all of the API commands.

 

Using these API commands we can create accelerated, embedded and HLS solutions.

By reading the CLI documentation we are able to understand the commands and their use to create the application script.

To create this project I am going to use an XSA from a project which I have previously created.


The python script to create the platform and application can be seen below


import vitis 

client = vitis.create_client()

client.set_workspace(path="C:\\hdl_projects\\zu_board_adc\\python_mz566\\wksp")

platform_comp=client.create_platform_component(name='platform',
                                               hw_design="C:\\hdl_projects\\zu_board_adc\\zu_adc_wrapper.xsa",
                                               cpu = "psu_cortexa53_0", 
                                               os = "standalone", 
                                               domain_name = "standalone_a53"
                                               )

platform_comp.build()

#template_list = client.get_template('EMBD_APP','hello_world')

app_comp = client.create_app_component(name ='hello_world', 
                                       platform = "C:\\hdl_projects\\zu_board_adc\\python_mz566\\wksp\\platform\\export\\platform\\platform.xpfm", 
                                       domain = "standalone_a53",
                                       template = 'hello_world')
app_comp.build()

client.close()

Lets break this down step by step


The first thing we need to do is to initialise the connection from python to our Vitis environment.


import vitis  - This imports the Vitis API


client = vitis.create_client() – This is called to create an instance of the Vitis Client. This provides the bridge between python and Vitis.


Just as when using the GUI we need to create first a hardware platform based off the XSA. We can do this using the command


platform_comp=client.create_platform_component(name='platform',

                                               hw_design="C:\\hdl_projects\\zu_board_adc\\zu_adc_wrapper.xsa",

                                               cpu = "psu_cortexa53_0",

                                               os = "standalone",

                                               domain_name = "standalone_a53"

                                               )


This creates a new platform of the given name, based of the identified HW design. As I want to create a simple bare metal embedded application. I also need to provide information as to the processor, the OS and the domain name.


After creation of the platform the next step is to build the platform.


platform_comp.build()


The next stage is to create the application program, here we need to give the application a name, define the platform location and the domain. If we want to use a template we are also able to define it at this point, here I called up the template hello world example.


app_comp = client.create_app_component(name ='hello_world',

                                       platform = "C:\\hdl_projects\\zu_board_adc\\python_mz566\\wksp\\platform\\export\\platform\\platform.xpfm",

                                       domain = "standalone_a53",

                                       template = 'hello_world')

 

If we so desire we are able to examine the workspace directory and we will observe the platform and the application created as one would expect.

With the platform and application created the final step is to build the ELF file which can be used on the hardware here the script uses the command


app_comp.build()


The build of the application program will report the application size.

Having created the client, platform, application and built all of the necessary elements the final step of the script is to close the connection with Vitis. This leaves the script in a clean state, such that we can run future commands if so desired.


We can then open the workspace in the Vitis Unified IDE should we desire to start debugging the application on hardware.

If you read the CLI documentation above you will see there is a range of commands which can be used to work effectively with the Python API.


Hopefully this helps you get up and running with using the Python scripts to work with Vitis.


Workshops and Webinars


If you enjoyed the blog why not take a look at the free webinars, workshops and training courses we have created over the years. Highlights include



Boards

Get an Adiuvo development board



Embedded System Book   


Do you want to know more about designing embedded systems from scratch? Check out our book on creating embedded systems. This book will walk you through all the stages of requirements, architecture, component selection, schematics, layout, and FPGA / software design. We designed and manufactured the board at the heart of the book! The schematics and layout are available in Altium here   Learn more about the board (see previous blogs on Bring up, DDR validation, USB, Sensors) and view the schematics here.



0 comments

Recent Posts

See All
bottom of page