Interfacing a USB WebCam and Enable USB Tethering on ZYNQ-7000 AP SoC Running Linux

My other articles :

In the previous tutorial, I explained how to install Ubuntu on ZYNQ-7000 AP SoC ( Xilinx ZC-702 board ). This tutorial, as a continuation of the previous one, will explain how to interface a USB camera to Xilinx ZC-702 board running any Linux distribution (does not depend on Ubuntu). PetaLinux SDK will be used in this tutorial.

Why Interface a USB WebCam to ZC-702 ?

If you are developing an image processing or video processing application, you might need a video input to Xilinx ZC-702. But if you buy Xilinx ZC-702 Video Imaging Kit, it comes with a HDMI FMC card and a high quality image sensor. If that’s the case, most probably you will not have to interface a USB webcam for a video input.

But if,

  • What you have is Xilinx ZC-702 Evaluation Kit (which does not include a FMC card and image sensor) and FMC card, image sensor is too expensive for you.
  • You don’t need a high quality video input, webcam video quality is sufficient for your application.

If you are in any of the above scenarios, interfacing a USB webcam is the solution for you.

Stuff You Need :

  1. Xilinx ZC-702 Development Board
  2. SD card ( 8 GB or bigger)
  3. SD card reader
  4. PC with Linux installed (Preferably Ubuntu 16.04 or later)
  5. PC with Vivado 2014.4 or later installed
  6. Webcam that supports UVC(USB Video Class) Driver [Check this for list of supported devices by UVC driver]

Introduction

For interfacing a USB webcam, we need to install/include few kernel modules to the Linux kernel image. This can be done using PetaLinux. After setting the configurations using PetaLinux, we also need to edit the device tree so that USB hardware on ZC-702 is identified by the Linux kernel. These steps will be explained in detail.

Note : Device-tree is a file (or set of files) that’s responsible for informing the operating system kernel about the hardware included in the processing system and the drivers used for each of those hardware.

Other than interfacing a USB cam, enabling kernel modules related to USB tethering will be also included in this tutorial, as an extra tip. (I found this really useful because you can tether your phone to the board and you have Internet access from the board. Otherwise you have to connect the Ethernet cable, which was comparatively troublesome for me.)

Step 1 : Follow Steps 1 to 4 in My Previous Tutorial

Follow the referred steps to install PetaLinux, create hardware design and create PetaLinux project from created hardware, if you haven’t done already. Don’t run “petalinux-build” command yet.

If you already have a PetaLinux project with a hardware design imported (This hardware design must satisfy the requirements for running Linux on ZYNQ, see step 3 of previous tutorial for these requirements), ignore this step and start from step 2.

Step 2 : Enabling Various Drivers in the Linux Kernel of PetaLinux Project

Run the following command to configure the Linux kernel of PetaLinux project.

petalinux-config -c kernel

This command will bring up the below screen (there is a issue with the colors, don’t worry about it)

PetaLinux Kernel Configuration Menu

Note : Refer the Update on the previous article if you encountered an error executing this.

There are several features/configurations that we need to enable to add the drivers for USB camera and USB tethering. We will go through them one by one.

Important : You can press “/” key and search for any feature in above kernel configuration menu, it will show whether its enabled or not and the location of the feature in the menu.

  1. USB Video Class(UVC) Driver

Navigate to Device Drivers section and enable following features by pressing “y” key.

  • USB support
  • USB support > USB ULPI PHY interface support
  • USB support > EHCI HCD (USB 2.0) support
  • USB support > ChipIdea Highspeed Dual Role Controller
  • USB support > ChipIdea device controller
  • USB support > ChipIdea host controller
  • USB support > USB Gadget Support

Note : There are several drivers that need to be enabled in “USB support > USB Gadget Support” section for both USB webcam and USB tethering, I will provide screenshots for them after the next section.

2. Drivers for USB Tethering

Go to “Device Drivers > USB support” from main kernel configuration menu and enable following features.

  • USB Modem (CDC ACM) Support
  • USB wireless device management support
  • USB Mass Storage support
  • USB/IP Support
  • Host Driver (Under USB/IP support)

Go to “Device Drivers > Network device support” from kernel configuration main menu and enable following features.

  • Ethernet team driver support
  • Ethernet driver support
  • PHY device support and infrastructure
  • USB network adapters
  • USB network adapters > Multi-functional USB Networking framework (Following features will be shown under this after enabling this feature)
  • CDC Ethernet support (Smart devices such as cable modems)
  • CDC EEM Support
  • CDC NCM Support
  • Host for RNDIS and ActiveSync devices
  • Simple USB network links (CDC Ethernet Subset)

3. Enable following features in the “Device Drivers > USB support > USB Gadget Support” as in the figures.

Note : In following figures, “M” means this feature is added to the kernel as a module. Press “m” key to do this.

USB Gadget Support Kernel Configuration
USB Gadget Support Kernel Configuration

Kernel configuration is done, Exit the menu and save the new configuration.

Step 3 : Adding the Device-Tree entries for USB

We need to add USB entries to the device tree so that kernel will identify the hardware (and related registers, clocks and interrupts) and assign the correct driver for that hardware at boot time. (We will also add Ethernet device-tree entries to enable Ethernet in our development board)

First we will build device tree for the current hardware so that PetaLinux generate the device tree source files that we can edit later.

Run the following command in the command line inside the project folder,

petalinux-build -c device-tree

After device-tree building is done, goto the following folder and open the file “system-top.dts”.

<project-folder>/project-spec/meta-user/recipes-dt/device-tree/files/

File will contain few lines at the top, copy the following entries to the file after those lines,

&gem0 {
phy-handle = <&phy0>;
ps7_ethernet_0_mdio: mdio {
#address-cells = <1>;
#size-cells = <0>;
phy0: phy@7 {
device_type = "ethernet-phy";
reg = <7>;
};
};
};
/{
usb_phy0: usb_phy@0 {
compatible = "ulpi-phy";
#phy-cells = <0>;
reg = <0xe0002000 0x1000>;
view-port = <0x0170>;
drv-vbus;
};
};
&usb0 {
dr_mode = "host";
usb-phy = <&usb_phy0>;
};

Save the file and close it. Now we are ready to build the whole project.

Step 4 : Build the project

  • Run the following command to build the project with our new device-tree configuration and generate boot files
petalinux-build
  • After project is successfully built, run the following command to generate the BOOT.BIN file. (This is a single line command)
petalinux-package --boot --format BIN --fsbl ./images/linux/zynq_fsbl.elf --fpga ./images/linux/download.bit --u-boot

Note : In the above command, I have used the name ‘download.bit’ as the bit file name. Change the command according to your .bit file name.

Step 5 : Copy boot files to the SD card and boot Linux on ZYNQ

I will not explain this part again, check step 6 of my previous article if you are not familiar with this.

All Done !

If you have done all the things correctly, now you can connect a USB webcam to your development board(I use Xilinx ZC702 board).

Connect a USB cam and execute the following command on the Linux terminal of the board.

dmesg | tail

From the output, you will see UVC driver is probed and your cam is recognized as a video device. To ensure this, execute the following command and check,

ls -l /dev/video0

If this command prints any output, Congratulations, your device is recognized as a video camera from the Linux running on ZYNQ.

Please leave comments if you face any problems.

--

--