UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor ggillett
Visitor
445 Views
Registered: ‎08-14-2018

axi_gpio /sys drivers and yocto

Jump to solution

Hi,

 

I am using yocto to build linux images (essentially petalinux-image-minimal) the yocto setup is as described here using v2018.2 commits. I am building for the zedboard (MACHINE=zedboard-zynq7) the idea is to use the gpios via the SysFs: driver.

The test block diagram is shown below the exported HDF is imported into the Yocto project using HDF_BASE and HDF_FILE.

Screenshot from 2018-10-26 13-19-16.png

The build succeeds and the zedboard boots without problem, but I don't see any references to XGpio in dmesg.

Looking at build/tmp/work/zedboard_zynq7-xilinx-linux-gnueabi/device-tree/xilinx+gitAUTOINC+f38738e568-r0/system-top.dts I see appropriate entries for the axi_gpios with addresses that coincide with the address editor in the block design.

 

        ...
amba_pl { #address-cells = <0x1>; #size-cells = <0x1>; compatible = "simple-bus"; ranges; gpio@41200000 { #gpio-cells = <0x3>; clock-names = "s_axi_aclk"; clocks = <0x1 0xf>; compatible = "xlnx,xps-gpio-1.00.a"; gpio-controller; reg = <0x41200000 0x10000>; xlnx,all-inputs = <0x1>; xlnx,all-inputs-2 = <0x1>; xlnx,all-outputs = <0x0>; xlnx,all-outputs-2 = <0x0>; xlnx,dout-default = <0x0>; xlnx,dout-default-2 = <0x0>; xlnx,gpio-width = <0x5>; xlnx,gpio2-width = <0x8>; xlnx,interrupt-present = <0x0>; xlnx,is-dual = <0x1>; xlnx,tri-default = <0xffffffff>; xlnx,tri-default-2 = <0xffffffff>; }; gpio@41210000 { #gpio-cells = <0x3>; clock-names = "s_axi_aclk"; clocks = <0x1 0xf>; compatible = "xlnx,xps-gpio-1.00.a"; gpio-controller; reg = <0x41210000 0x10000>; xlnx,all-inputs = <0x0>; xlnx,all-inputs-2 = <0x0>; xlnx,all-outputs = <0x1>; xlnx,all-outputs-2 = <0x0>; xlnx,dout-default = <0x0>; xlnx,dout-default-2 = <0x0>; xlnx,gpio-width = <0x8>; xlnx,gpio2-width = <0x20>; xlnx,interrupt-present = <0x0>; xlnx,is-dual = <0x0>; xlnx,tri-default = <0xffffffff>; xlnx,tri-default-2 = <0xffffffff>; }; };
...

 On the board in /sys/class/gpio I see

root@zed:/sys/class/gpio# ls
export       gpiochip906  unexport

root@zed:/sys/class/gpio# cat gpiochip906/label
zynq_gpio

root@zed:/sys/class/gpio# cat gpiochip906/ngpio
118

I can export pins and set directions and read/write values. But nothing appears to be connected to the LEDs, switches or push buttons.

 

Q1 how do I find the map from exported pin to axi_gpio output? IE find which pin(s) to export that are connected to the LEDs?

 

 

I can use the same HDF in the Xilinx SDK and the following code works as expected as a helloworld stand alone.

/*****************************************************
Getting Started Guide for Zedboard

This demo displays the status of the switches on the
LEDs and prints a message to the serial communication
when a button is pressed.

Terminal Settings:
   -Baud: 115200
   -Data bits: 8
   -Parity: no
   -Stop bits: 1

7/25/16: Created by JonP
****************************************************/

#include <stdio.h>
#include "platform.h"
#include <xgpio.h>
#include "xparameters.h"
#include "sleep.h"

int main()
{
   XGpio input, output;
   int button_data = 0;
   int switch_data = 0;

   XGpio_Initialize(&input, XPAR_AXI_GPIO_0_DEVICE_ID);	//initialize input XGpio variable
   XGpio_Initialize(&output, XPAR_AXI_GPIO_1_DEVICE_ID);	//initialize output XGpio variable

   XGpio_SetDataDirection(&input, 1, 0xF);			//set first channel tristate buffer to input
   XGpio_SetDataDirection(&input, 2, 0xF);			//set second channel tristate buffer to input

   XGpio_SetDataDirection(&output, 1, 0x0);		//set first channel tristate buffer to output

   init_platform();

   while(1){
      switch_data = XGpio_DiscreteRead(&input, 2);	//get switch data

      XGpio_DiscreteWrite(&output, 1, switch_data);	//write switch data to the LEDs

      button_data = XGpio_DiscreteRead(&input, 1);	//get button data

      //print message dependent on whether one or more buttons are pressed
      if(button_data == 0b00000){} //do nothing

      else if(button_data == 0b00001)
         xil_printf("button 0 pressed\n\r");

      else if(button_data == 0b00010)
         xil_printf("button 1 pressed\n\r");

      else if(button_data == 0b00100)
         xil_printf("button 2 pressed\n\r");

      else if(button_data == 0b01000)
         xil_printf("button 3 pressed\n\r");

      else if(button_data == 0b10000)
              xil_printf("button 4 pressed\n\r");

      else
         xil_printf("multiple buttons pressed\n\r");

      usleep(200000);			//delay

   }
   cleanup_platform();
   return 0;
}

It would appear that something is not getting connected or configured in the yocto build as evidenced by the missing axi_gpio messages in dmsg. I am new to embedded linux and yocto.

 

Q2 How can I debug what is missing in the yocto image? What are my next steps? 

 

Any help, hints or pushes in the right direction greatly appreciated.

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Visitor ggillett
Visitor
336 Views
Registered: ‎08-14-2018

Re: axi_gpio /sys drivers and yocto

Jump to solution

I found the problem was that I was loading the wrong device tree blob from build/tmp/deploy/images/zedboard-zynq7/ over jtag. I was loading zynq-zed.dtb but the device tree corresponding to the custom HDF set using HDF_BASE and HDF_FILE in local.conf is in the zedboard-zynq7-system.dtb blob.

 

I now see gpiochip1003  gpiochip1011  gpiochip1019  gpiochip885 in /dev/class/gpio on the board and can read switches and light leds. 

 

I discovered this by using the device tree compiler (dtc) to decompile the .dtb files back to .dts. The dts tool gets built in

build/tmp/work/zedboard_zynq7-xilinx-linux-gnueabi/u-boot-xlnx/v2018.01-xilinx-v2018.2+gitAUTOINC+21812b5fd3-r0/build/scripts/dtc and the .dts can be recovered with

$ dtc -I dtb -O dts -o <dts_file> <dtb_file>

 

0 Kudos
3 Replies
Explorer
Explorer
384 Views
Registered: ‎10-21-2015

Re: axi_gpio /sys drivers and yocto

Jump to solution

Hi 

gpiochip906 is gpio bank for PS gpio.

Probably your compiled devicetree doesn't have pl gpio banks

The correct devicetree should add two gpio banks.

Petalinux is based on Yocto

I recommend you use petalinux because petalinux  is  easier than yocto to build xilinx boot loader, devicetree 

 

Visitor ggillett
Visitor
369 Views
Registered: ‎08-14-2018

Re: axi_gpio /sys drivers and yocto

Jump to solution

Hi hokim,

 

Thanks for the reply. So I should see more than gpiochip906 in /sys/class/gpio, that is helpful thank you.

 

I assume you mean use petalinux tools rather than yocto, I'll look at it, but I need to target non Xilinx devices in the same project so yocto is preferable to keep everything consistent. I agree it is more complicated to learn.

 

I'll continue trying to debug what is going wrong. Since the .dts appears to be fine, I'll check that that .dts is the one actually being compiled and the resulting device tree is being added to the boot image.

0 Kudos
Visitor ggillett
Visitor
337 Views
Registered: ‎08-14-2018

Re: axi_gpio /sys drivers and yocto

Jump to solution

I found the problem was that I was loading the wrong device tree blob from build/tmp/deploy/images/zedboard-zynq7/ over jtag. I was loading zynq-zed.dtb but the device tree corresponding to the custom HDF set using HDF_BASE and HDF_FILE in local.conf is in the zedboard-zynq7-system.dtb blob.

 

I now see gpiochip1003  gpiochip1011  gpiochip1019  gpiochip885 in /dev/class/gpio on the board and can read switches and light leds. 

 

I discovered this by using the device tree compiler (dtc) to decompile the .dtb files back to .dts. The dts tool gets built in

build/tmp/work/zedboard_zynq7-xilinx-linux-gnueabi/u-boot-xlnx/v2018.01-xilinx-v2018.2+gitAUTOINC+21812b5fd3-r0/build/scripts/dtc and the .dts can be recovered with

$ dtc -I dtb -O dts -o <dts_file> <dtb_file>

 

0 Kudos