Showing results for 
Show  only  | Search instead for 
Did you mean: 
Registered: ‎03-15-2019

Writing on LEDs on ZedBoard through a C application with PetaLinux and custom PL

I have successfully run a very simple program with custom PL (with a custom IP core) and its C code on ZedBoard in standalone. Now I want to run the exact same program with PetaLinux, but I have no idea how to do that. I have watched these video tutorials. I have been able to build the PetaLinux image and create BOOT.BIN and boot the board with SD card. But I don't know how to build drivers or module to interact with my custom IP, and how to write the C code (user application) for PetaLinux.

Here is more details. I have created the attached diagram in IP integrator of Vivado 2018.3. It has a custom-made IP, named My_PWM_Core_0, which is connected to 4 LEDs and its input comes from AXI interconnect. The CPU constantly sends a PWM signal to the IP, and as a result, the LEDs brighness constantly changes. According to the Address Editor, the offset address of the My_PWM_Core_0 in memory is 0x43C0_0000, and its High Address is 0x43C0_FFFF. I generated the bitstream, exported the hardware to SDK, and created the following standalone application:

#include "xparameters.h"
#include "xil_io.h"
#define MY_PWM 0x43C00000 //This value is found in the Address editor tab in Vivado (next to Diagram tab)

int main(){
    int num=0;
    int i;

        if(num == 1024)
             num = 0;

        Xil_Out32(MY_PWM, num);
        Xil_Out32((MY_PWM+4), num);
        Xil_Out32((MY_PWM+8), num);
        Xil_Out32((MY_PWM+12), num);

        for(i=0;i<300000; i++);

I downloaded the .bit file generated by Vivado, and the .elf file generated by SDK on ZedBoard, and it works the way it should.


Now I want to do the exact same thing, but on PetaLinux instead of standalone. I used PetaLinux SDK and the generated hardware platform (.hdf) file to create the Linux Kernel image, FSBL and U-Boot. On the device tree, the

Next, I used the FSBL, the .bit file and U-Boot to generate BOOT.BIN. I transferred the BOOT.BIN and image.ub to the SD card, and Linux successfully boots. However, the LEDs are turned off and I need to write a Linux application to send the PWM signal to the IP. On the device tree of the petalinux, this is how pl.dtsi looks like:

/ {
	amba_pl: amba_pl {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "simple-bus";
		ranges ;
		My_PWM_Core_0: My_PWM_Core@43c00000 {
			clock-names = "s00_axi_aclk";
			clocks = <&clkc 15>;
			compatible = "xlnx,My-PWM-Core-1.0";
			reg = <0x43c00000 0x10000>;
			xlnx,s00-axi-addr-width = <0x4>;
			xlnx,s00-axi-data-width = <0x20>;

Also, when the zedbord is on, I can find the same device tree under /proc/device-tree/amba_pl/My_PWM_Core@43c00000/ . In this directory, I can see clock-names, clocks, compatible, name, reg, xlnx,s00-axi-addr-width and xlnx,s00-axi-data-width. I'm not sure, if I want to output something on PWM through my C application, do I need to write on one of these files? Or do I need to make a device driver, like a Linux GPIO driver?

I have asked this question before in these forums, but didn't get any helpful reply.




Tags (1)
0 Kudos
0 Replies