top of page

MicroZed Chronicles: Smart Sensor IOT Board Getting USB Up and Running

The smart sensor IOT board we developed contains several interfaces that really require the use of an operating system to get them up and running. Along with the WiFi and Ethernet interfaces, there is also the USB interface. The USB interface on the smart sensor IOT board has been designed so that it can be configured to support USB-OTG or as a USB host.


In this blog, we are going to create a PetaLinux system that supports a USB host to prove that the USB and Ethernet interfaces are working correctly.


To get started, we first need to create a new Vivado project that contains the Zynq processing system configured for the custom Zynq board. Rather than having to enter this configuration from scratch, we can use the TCL script generated in my first blog that featured the smart sensor IOT board.


Once the processing system is configured, the final step in Vivado is to create the HDL wrapper and build the bitstream. Once the bitstream is available, we can export the XSA and create a new PetaLinux project.


Since the hardware was developed in Vivado 2020.2, we must use the same version of PetaLinux on our Linux development machine.


Creating a new project is pretty simple using the following command:


Petalinux-create - - type project - - template zynq - - name smart_iot


This creates a base project that is configured for the Zynq-7000 device, however, it has yet to be configured for the exact board configuration. Updating the new project to have the correct settings for the hardware occurs when we run the following command:


Petalinux-config - -get-hw-description=/<location of xsa>


This will open a configuration dialog. We don’t need to make any changes to the configuration now.

We do, however, need to make some changes in the device tree to enable the USB to operate correctly. The Zynq PS has two USB interfaces of 0 and 1. The smart sensor IOT is configured to use USB1, which is slightly different to most examples available.


The changes that need to be made are to the device tree. Most of the PetaLinux device trees are autogenerated at runtime so making changes to the wrong one will result in the changes being overwritten. The device tree file that requires editing is available under the project-spec/meta-user layer of the project and under the recipes-bsp folder. Edit the file system-user.dtsi.


In this file, we need to configure the operating mode of the USB1 and the PHY configuration. First, we define the USB PHY used, being careful to ensure the reg is set with the correct address of USB1.

Finally, we set the USB1 dr_mode to host along with defining the associated PHY. These changes are the only ones that need to be made in the device tree file.

Once this is complete, we are able to build the PetaLinux project using the command

Petalinux-build

Depending upon the speed of your system, it may take a while to generate the necessary image files. Once the image is available, we can start testing the build to ensure that we can see and work with the USB. To accelerate development, I downloaded the FPGA and kernel using a SmartLynq JTAG probe connected to my network. The commands used are:


Petalinux-boot - -jtag - - hw_server_url 192.168.1.91:3121 - - fpga

Petalinux-boot - -jtag - - hw_server_url 192.168.1.91:3121 - - kernel


Connecting to a UART terminal will then show the kernel image booting once it is downloaded by the SmartLynq.



Once the system is booted and we have logged in (root/root), plugging in a USB thumb drive will result in an output in the terminal showing the USB connection and the SDA allocation. We can then mount the USB card into the file system so that we can work with it. In the terminal window, enter the command


Mount /dev/sda<> /<directory>

df


The df command will show the free disk space on all the mounted disks. You should see the USB disk and its mount point if it was successful.

With that completed, we can issue a ls command to explore the contents of the USB drive. If we see the files, we can be assured the USB interface is working correctly.


The above image was the result I obtained when I plugged a USB thumb drive into the smart sensor IoT board.


It looks like the USB interface is working so we’ll discuss how we can work with it next along with the IoT smart sensor board in PetaLinux as we begin to create new applications to work with the sensors.

0 comments
bottom of page