MicroZed Chronicles: UIO Half One

Final week we checked out how we may use spidev and I2Cdev to work with units which use SPI or I2C interfaces. These are generally used interfaces for a variety of units (e.g., ADCs, DACs, and sensors).

After all, one of many issues we need to do with PetaLinux is figure with the customized logic features within the PL. There are two methods we may create a driver for our customized PL module. We are able to do that be both making a kernel module and working from kernel area or making a driver within the consumer area space.
Utilizing PetaLinux, we will create a kernel module and cargo it into the kernel. Nevertheless, after we work inside the kernel area, we’ve entry to all the {hardware} sources and reminiscence. If we make errors within the growth of that kernel driver, we will simply crash your complete kernel and the working system. Additionally it is way more troublesome to show the kernel module is appropriate beneath all use case circumstances and to debug points which could come up.
The second choice we’ve is to develop the motive force within the consumer area. The userspace driver doesn’t have entry to the underlaying {hardware} straight, however accesses them by way of system calls to the kernel. Most significantly, after we get it unsuitable within the consumer area, we are going to solely crash the appliance and never your complete working system. Additionally it is a lot simpler to debug functions inside the consumer area.
The most typical technique of making a driver within the consumer area is to make use of Userspace IO (UIO). UIO is a kernel driver which may be accessed from consumer area and supplies consumer area with protected entry to the gadget reminiscence and interrupts.
One of many advantages of UIO is the flexibility to deal with interrupts. In FPGA and SoC resolution embedded programs, we will ensure that the interrupt pin we’re related to is devoted to our peripheral. This makes interrupt dealing with a lot less complicated and signifies that a kernel module to assist the actual UIO occasion will not be required as a result of we’re utilizing uio_pdrv_genirq (the generic interrupt handler) which merely disables the interrupt when it happens. We are able to detect the interrupt in our consumer area utility, course of it, after which re-enable the interrupt.
For this instance, I’m going so as to add in two GPIO blocks to the design we a created final week and join them to the AXI community.

Within the gadget tree, we are going to declare the AXI_GPIO as appropriate with UIO and also will allow a brand new boot argument to assist interrupts.
/embrace/ "system-conf.dtsi"
/ {
chosen {
bootargs = "uio_pdrv_genirq.of_id=generic-uio";
};
};
&spi0 {
standing = "okay";
spidev@0 {
appropriate = "rohm,dh2228fv";
spi-max-frequency = <50000000>;
reg = <0>;
};
};
&spi1 {
standing = "okay";
spidev@0 {
appropriate = "rohm,dh2228fv";
spi-max-frequency = <50000000>;
reg = <0>;
};
};
&axi_iic_0 {
clock-frequency = <100000>;
standing = "okay";
};
&axi_iic_1 {
clock-frequency = <100000>;
standing = "okay";
};
&axi_iic_2 {
clock-frequency = <100000>;
standing = "okay";
};
&axi_gpio_0 {
appropriate = "generic-uio";
};
&axi_gpio_1 {
appropriate = "generic-uio";
};
We don’t have to make any adjustments exterior of the gadget tree and reimport the exported XSA into in our PetaLinux venture.
With the adjustments accomplished, we’re then in a position to rebuild the venture and package deal the boot.bin. To examine the adjustments we’ve made to the Vivado design and PetaLinux OS, we will copy the boot.bin and picture.ub to the SD Card and boot the ZUBoard.
As soon as the board is booted, we will log in to the ZUBoard and study the UIO units which can be found beneath /sys/class/uio utilizing the serial terminal.

Underneath this listing you will notice 5 UIO units. The primary three units relate to the AXI efficiency monitor, whereas the ultimate two relate to the AXI GPIO we simply added into the design.
Now let’s focus on tips on how to determine how every UIO occasion is allotted.
If we study every of the UIO cases, we are going to observe a number of parts together with identify, energy, and maps.
By working the command cat identify within the terminal, we shall be given the identify of the occasion the UIO represents.

We may even see the identify, deal with, offset and measurement by trying beneath the map listing.

You’ll discover that the deal with matches the one outlined inside our Vivado design.
We are able to additionally examine that the interrupts for the AXI GPIO have been detected accurately by working the command cat /proc/interrupts

Within the listing of interrupts, we are going to see two GPIO entries together with the variety of instances this has been triggered.
Utilizing devmem, we will arrange the AXI GPIO interrupt allow registers in order that we will see the interrupt being raised after we press the PL push button change.
sudo devmem 0x0a03011c 32 0x80000000
sudo devmem 0x0a030128 32 0x3
Urgent the PL button will trigger an interrupt to be raised.

We are able to additionally then use devmem to put in writing to the GPIO which controls the tri state LEDs and illuminates them.
For the primary LED which is related to the second port of the primary GPIO
sudo devmem 0x0a030008 32 0x1
This may flip the LED blue whereas the 0x2 will flip it inexperienced. The 0x4 will flip it pink and, after all, 0x7 will make the LED white.
For the second GPIO, we have to set the deal with to 0x0a040000. Once more the identical patterns can be utilized for the totally different colours.
Up to now we’ve checked out tips on how to replace the gadget tree when working with UIO, verified that the UIO instantiations are detected accurately, and have used devmem to confirm the GPIO conduct and interrupt performance.
In our subsequent weblog, we are going to study how we will create a software program utility which makes use of UIO to work together with the registers within the AXI GPIO and in addition the GPIO Interrupt.
All the information essential to recreate this, are positioned right here
https://github.com/ATaylorCEngFIET/MZ508
Workshops and Webinars
In the event you loved the weblog why not check out the free webinars, workshops and coaching programs we’ve created through the years. Highlights embrace
Embedded System E book Do you need to know extra about designing embedded programs from scratch? Try our e-book on creating embedded programs. This e-book will stroll you thru all of the phases of necessities, structure, part choice, schematics, structure, and FPGA / software program design. We designed and manufactured the board on the coronary heart of the e-book! The schematics and structure can be found in Altium here Be taught extra in regards to the board (see earlier blogs on Bring up, DDR validation, USB, Sensors) and consider the schematics here.
Sponsored by AMD