Part 6 - Create & build 2nd software project
Missing Image!Missing Image!Missing Image!

Introduction

This tutorial details the steps required for using Vitis to create & deploy a very simple ARM Cortex-A9 based bare metal software application to access the LED's and slide switches on the ZedBoard hardware.

Aims

The aims of this tutorial are as follows :-
  1. Setup environment
  2. Launch Vitis
  3. Create project
  4. Build platform
  5. Create new source file
  6. Build project
  7. Archive project

1. Setup environment

Setup Xilinx design environment for the 2020.2 toolset.
steve@Linux-Steve:/home/steve$ source xilinx.sh
Xilinx tools available tools at /opt/Xilinx :-
1) 2020.2 - Vivado - SDK - Vitis - PetaLinux
0) Exit
Please select tools required or exit : 1

Tools are as follows :-
vivado @ /opt/Xilinx/Vivado/2020.2/bin/vivado
vitis @ /opt/Xilinx/Vitis/2020.2/bin/vitis
petalinux-build @ /opt/Xilinx/PetaLinux/2020.2/tool/tools/common/petalinux/bin/petalinux-build

2. Launch Vitis

Launch Vitis IDE and specify the new Workspace to create.
steve@Linux-Steve:/home/steve$ vitis -workspace /home/steve/projects/leds_switches/sw &

3. Create project

The Vitis IDE : Welcome window will now appear. Create a project by clicking on Create Application Project under the Project heading. Missing Image! The New Application : Project Create a New Project window will now appear. Review the information provided and then click Next. Missing Image! The New Application Project : Platform window will now appear. Select the exported hardware platform from Vivado by entering the Create a new platform form hardware (XSA) tab and setting the XSA File to /home/steve/projects/leds_switches/fw/system_wrapper.xsa. Click Next to continue. Missing Image! The New Application Project : Application Project Details window will now appear. Set the Application project name to leds_switches and then click Next. Missing Image! The New Application Project : Domain window will now appear. The default settings as shown are fine for this project. Click Next to contune. Missing Image! The New Application Project : Templates window will now appear. Create an empty application by selecting Empty Application from the Available Templates section. Click Finish to contune. Missing Image! The Vitis IDE cockpit window will now appear. This is the window where all the action happens. Missing Image!

4. Build platform

Build the platform by right clicking on system_wrapper inside the Explorer tab and selecting Build Project. Missing Image!

5. Create new source file

Create a new source file inside the leds_switches application project. Right click on src then select New » File. Missing Image! In the Create New File dialog set the File name to leds_switches.c and click Finish to continue. Missing Image! The new source file is automatically opened in the Vitis IDE for editing. Missing Image! Copy the code below into the newly created leds_switches.c and save it by selecting File » Save from the main menu.

leds_switches.c

  1. #include "xparameters.h"
  2. #include "xil_printf.h"
  3. #include "xgpio.h"

  4. #define CHANNEL_LEDS 1
  5. #define CHANNEL_SWITCHES 2

  6. // Print LSB 'bits' from 'number' in binary format
  7. void print_bin(u32 number, u8 bits)
  8. {
  9.   u32 mask = 1 << (bits - 1);
  10.   for(; mask; mask >>= 1)
  11.     xil_printf("%d", (number & mask) != 0);
  12. }


  13. int main()
  14. {
  15.   XGpio_Config *gpio_0_cfg;
  16.   XGpio gpio_0;
  17.   u32 gpio_0_data;

  18.   // Initialise GPIO
  19.   gpio_0_cfg = XGpio_LookupConfig(XPAR_AXI_GPIO_0_BASEADDR);
  20.   XGpio_CfgInitialize(&gpio_0, gpio_0_cfg, gpio_0_cfg->BaseAddress);

  21.   // Print header
  22.   print("LED & Switch Example\n\n\r");
  23.   print("Select required operation :-\n\r");
  24.   print("r - Read from switch register\n\r");
  25.   print("w - Write to LED register\n\r");
  26.   print("q - Quit application\n\r");

  27.   // Wait for user input & perform required operation
  28.   char8 key;
  29.   do
  30.   {
  31.     key = inbyte();

  32.     switch (key)
  33.     {
  34.       case 'r':
  35.         gpio_0_data = XGpio_DiscreteRead(&gpio_0, CHANNEL_SWITCHES);
  36.         xil_printf("Switch Register @ 0x%x = 0b", gpio_0_cfg->BaseAddress);
  37.         print_bin(gpio_0_data, 8);
  38.         print("\n\r");
  39.         break;

  40.       case 'w':
  41.         gpio_0_data = 0b00000001;
  42.         for (u8 i = 0; i <= 15; i++)
  43.         {
  44.           XGpio_DiscreteWrite(&gpio_0, CHANNEL_LEDS, gpio_0_data);
  45.           xil_printf("LED Register @ 0x%x = 0b", gpio_0_cfg->BaseAddress);
  46.           print_bin(gpio_0_data, 8);
  47.           print("\n\r");
  48.           usleep(100000);
  49.           if (i < 7)
  50.             gpio_0_data <<= 1;
  51.           else
  52.             gpio_0_data >>= 1;
  53.         }
  54.         break;
  55.     }
  56.   } while (key != 'q');

  57.   // Print footer
  58.   print("All done!\n\n\r");

  59.   // Exit application
  60.   return 0;
  61. }

6. Build project

Build the project by right clicking on leds_switches under leds_switches_system inside the Explorer tab and selecting Build Project. Missing Image!

7. Archive project

Create an archive so the project can be regenerated and revision controlled (optional). Select File » Export... from the main menu. In the Export Vitis Projects dialog set Archive File to vitis_export_archive.ide.zip, set Directory to /home/steve/projects/leds_switches and tick System Projects & Platform Projects. Click OK to continue. Missing Image! In the Export Vitis Projects status dialog click OK to continue. Missing Image! Add the file /home/steve/projects/leds_switches/vitis_export_archive.ide.zip to the revision control system & commit (optional).

'projects' location : 'repos' location : 'downloads' location :
Copyright © 2021 Steve Haywood
Missing Image!
Missing Image!Missing Image!Missing Image!