• 0
theAsker

Program code on PetaLinux

Question

Hello!

Here is another newbie question from me!

I am having a running hardware project from Vivado, and I also debugged bare metal code with SDK. Both was running perfectly.

5afad87e1734e_Screenshotfrom2018-05-1514-49-33.png.cdf78f1b17b7b8eff313ad35024847b8.png

Now I also got a PetaLinux (v2017.4) run on my Zybo Z7-20. So far so good.

First I thought, that I could only paste the c code on PetaLinux, compile it and let it run. But of course it didn't worked because I used bare metal code.

I wrote already that I have to add drivers to the device tree.

Here are my problems/questions:

1) I wrote something the following files: system-user.dtsi, zynq-7000.dtsi, system-top.dts and system-conf.dtsi

As I wrote I am only allowed to change stuff in the system-user.dtsi file. But when I compare the driver code from your Zybo Z7-20 and the stuff I found in the internet. It looks completly different. So where and what do I have add? I wrote that I have to enable the kernel configuration (where and how)? Am I doing this with petalinux-config -c kernel, is it also possible that when I use my own hardwaretarget for PetaLinux creating , that the enabeling of the drivers happened already?

2) I want to send the voltage values over ethernet, so do I need one or two drivers (XADC-driver or XADC + ethernet-driver) for it and also a gpio driver, right? Is there code for Zybo Z7-20 somewhere existing, or where can I find some code that is fitting? I made more trys but never the petalinux-build was successfully.

Thanks again for your help and time, it is always totally helpful! A+ for your job, helping a totally newbie ;-)

greetings,

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

hello,

 

1)

- 1st question: as you already figured you can define your device tree in a single file. See system-user.dtsi as reference in the petalinux platforms from digilent. I am a beginner, too but I think it is better to place it all in one file. Once your projects are more complex you can use several files. Instead of system-user.dtsi you can use your own file. You can change this in a file located in the directory where you place these files (meta_user/user_dtb/ something like that)

- 2nd question: to change the kernel configuration use the petalinux-tools. I don't know what you want to change, though

- 3rd question: have you had a look at UG1156?

- 4th question: no, this is usually not the case. You have to configure rootfs

 

2) 

- 1st question: yes (one driver for each is highly recommended ^^)

- 2nd question: http://www.wiki.xilinx.com/Linux+Drivers

Share this post


Link to post
Share on other sites
  • 0

To expand a little further on the XADC questions, first you need to add the following to system-user.dtsi:

&xadc_wiz_0 {
	clocks = <&clkc 15>;
	xlnx,channels {
		#address-cells = <1>;
		#size-cells = <0>;
		channelJA4@7 { /* vaux6 */
			reg = <7>;
		};
		channelJA2@8 {
			reg = <8>;
		};
		channelJA1@15 {
			reg = <15>;
		};
		channelJA3@16 {
			reg = <16>;
		};
	};
};

That should get the Xilinx XADC driver properly loaded. I'm also assuming that you are using the base-linux vivado project, or that you included the XADC wizard in your own block diagram (configured in the same way as base-linux). 

You can then cat the "raw" value in the /sys/ folder for the corresponding channel in the XADC driver folder (sorry, I don't have the entire path on hand). That will display the current voltage on the command line as a value from 0-4096 (corresponding to the voltages from 0v-1v). If you are needing to read the voltage in a custom program, just open and read the same value using standard file APIs. 

For sending data like this over a network, I'd recommend using the low-level socket APIs, they are the easiest to get working for stuff like this in my experience.

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

Thanks for your answers, they are making the stuff more clear for me.

But I still have some questions about the XADC:

The driver you send is made for 4 Channels right? So in my case I only have to the register 7 (vaux6) and register 15 (vaux14). I configured the XADC to simultaneous access, but I read that this functions is not available for simultaneous access. Is there an other way to solve this problem?

Could I add a XADC module and map it, and read from some registers the voltage values from the simultaneous access? (in this case, I won't need a driver, right?)

I also have questions about the GPIO:

Is there also a drive like @sbobrowicz posted for XADC existing for GPIO? Is the reading/writing of the GPIO-ports the same than, like XADC? I found this one. Is this correct. It is looking too simple...

&axi_gpio_button {
	compatible = "generic-uio";
};

thanks a lot, and greetings,

Edited by theAsker

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

yes, you can use UIO drivers for GPIO. These are standard drivers for Linux. There's an API you can use to read and write from UIO devices. I think the petalinux platform from Digilent is using it, too. Make sure the memory address in your device tree matches your address mapping. This is probably defined in some include file, in your case. Without using includes, this will do:

&axi_gpio_button {
    compatible = "generic-uio";
    reg = <0x43c00000 0x10000>;
};

(for some reason, my syntax highlighting is not working :( )

Edited by theUltimateSource

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

Thank you for your answer! I will add this.

Can you tell me, where in /sys/bux/iio/devices/iio\:device0 I can find the external voltages I want to measure.

Because in this path I can find the following:

5afe95e0217da_Screenshotfrom2018-05-1810-58-24.png.6e468585e3d4c534b460ee4d47842551.png

My driver is looking like this:

&xadc_wiz_0 {
	clocks = <&clkc 15>;
	xlnx,channels {
		#address-cells = <1>;
		#size-cells = <0>;
		channelJA4@7 { /*Vaux6*/
			reg = <7>;
		};
		channelJA1@15 { /*Vaux14*/
			reg = <15>;
		};
	};
};

The voltage files are only counted from 0 to 7, looks a bit strange for me.

Edited by theAsker

Share this post


Link to post
Share on other sites
  • 0

I don't see the correct voltages in your snapshot... you might be looking at the driver for the XADC controller in the Zynq PS, which is not what you want. Does another device exist, perhaps /sys/bus/iio/devices/iio:device1 

Share this post


Link to post
Share on other sites
  • 0

No there isn't an other path existing. The iio:device0 is the internal XADC. But there is not another iio:device appearing. Should be a problem with the device tree I think. But I don't know what I have to add to user-system.dtsi, or somewhere else. Maybe you can help me here. I added a comment in the code below:

/include/ "system-conf.dtsi"
/ {
	chosen {
        bootargs = "console=ttyPS0,115200 earlyprintk uio_pdrv_genirq.of_id=generic-uio";
		/*do I have to add here something, and if yes what?*/
    };
};

&xadc_wiz_0 {
  clocks = <&clkc 15>;
  xlnx,channels {
    #address-cells = <1>;
    #size-cells = <0>;
    channelJA4@7 {
      reg = <7>;
    };
    channelJA1@15 {
      reg = <15>;
    };
  };
};

&axi_gpio_rgb_led {
  compatible = "generic-uio";
};

&axi_gpio_button {
  compatible = "generic-uio";
};

&axi_gpio_segment {
  compatible = "generic-uio";
};     

The Xilinx_ADC_Driver in petalinux-config > industriell I/O is also enable. And the naming of the xadc_wiz_0 should also be correct, when you compare the posts above!

Do you know what could be the problem?

Edited by theAsker

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now