News:

Attention: For security reasons,please choose a user name *different* from your login name.
Also make sure to choose a secure password and change it regularly.

Main Menu

PYNQ on TE0726-03

Started by brazi_perjikolaei, February 27, 2020, 11:25:45 AM

Previous topic - Next topic

brazi_perjikolaei

Hi,

I'm trying to run PYNQ on a zynqberry. Everything works well but I cannot import pynq in the python on the device. The error is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xilinx/pynq/__init__.py", line 33, in <module>
    from .pl import PL
  File "/home/xilinx/pynq/pl.py", line 39, in <module>
    from .ps import CPU_ARCH_IS_SUPPORTED, CPU_ARCH, ZYNQ_ARCH, ZU_ARCH
  File "/home/xilinx/pynq/ps.py", line 322, in <module>
    class _ClocksUltrascale(_ClocksMeta):
  File "/home/xilinx/pynq/ps.py", line 382, in _ClocksUltrascale
    IOPLL_CTRL = Register(CRL_APB_ADDRESS + IOPLL_CTRL_OFFSET)
  File "/home/xilinx/pynq/registers.py", line 115, in __init__
    array = MMIO(address, np.dtype(register_type).itemsize).array
  File "/home/xilinx/pynq/mmio.py", line 82, in __init__
    device = Device.active_device
  File "/home/xilinx/pynq/pl_server/device.py", line 91, in active_device
    raise RuntimeError("No Devices Found")
RuntimeError: No Devices Found


I checked and fpga-manager is operating. Has anyone an idea what is the problem and how I can fix it?
P.S. I'm using Vivado2019.2 and Petalinux2019.2 for generating xsa and boot files.

That would be great if you can help me to solve this problem.

Regards,
Perjikolaei

brazi_perjikolaei

Well,

the problem is solved by adding these configs into the kernel:

CONFIG_STAGING=y
CONFIG_XILINX_APF=y
CONFIG_XILINX_DMA_APF=y
CONFIG_DMA_CMA=y
CONFIG_CMA_SIZE_MBYTES=256
CONFIG_LOCALVERSION="-xilinx-apf"


and also adding
     xlnk {
compatible = "xlnx,xlnk-1.0";
};


to the device-tree.

sebo

Hi Perjikolaei,

Do you mind sharing the PYNQ project?
Thanks.

Sébastien.

brazi_perjikolaei

Hi Sebastien,

here is my documentation:

* Needed softwares:
Vivado2019.2
Vitis2019.2
Petalinux2019.2
* Build Zynq Block in Vivado
** Download the prepared project (demo1):
https://shop.trenz-electronic.de/en/Download/?path=Trenz_Electronic/Modules_and_Module_Carriers/special/TE0726/Reference_Design/2018.3

** Update the blocks to 2019.2
Open the project in Vivado2019.2 and update the blocks from 2018.3 to 2019.2

** Wrapp the IP BLOCK
With the block design in place, create an HDL wrapper just like normal (right click on the block design in the Sources menu and select 'Create HDL Wrapper...').
The demo project folder from Trenz also contains a full constraints set that needs to be imported into the project.
*Use the 'Add Sources' option to import constraints from zynqberrydemo1.*

** Synthesis the design
At this point, you are free to add any custom RTL to the project if you so chose, but the hardware design is complete otherwise.
Run synthesis, implementation, and generate bitstream. Then export hardware (including bitstream) to use in Vitis (File > Export > Export Hardware).

* Build Project in Vitis
** Launch vitis
Create a folder in the Vivado project directory for the Vitis workspace and launch Vitis (Tools > Launch Vitis).

** New platform project
Create a new platform project from the custom XSA file exported from Vivado and build all after.
*Be sure the 'Generate boot components' options is selected*

** Create a bare metal 'hello world' application
Create a new application project targeting the custom XSA exported from Vivado and use the Hello World template.

** Run build all
Run by control+B

* Build Kernel
** Run petalinux
source the petalinux settings64.sh and create a new project by:
petalinux-create --type project --template zynq --name zynqberry-pynq

*Change directories into this project folder before running any of the project configuration commands:*
cd ./zynqberry-pynq

** Get hardware description
copy the xsa file into this folder and run:
petalinux-config --get-hw-description

** System Configuration
The System Configuration editor is where the settings can be accessed for what medium the embedded Linux image will be booting from.
Which in our case will be partially from the on-board QSPI flash and then from the SD card.

The Zynq boot image (boot.bin) and the u-boot environment will live in the on-board QSPI flash of the Zynqberry and will copy the kernel and device tree into the DDR at boot time.
The kernel will then take over and run the root file system from the SD card.
Therefore, in the setting set:

*subsystem AUTO Hardware Settings
   |___ Advanced bootable images storage settings
      |___ boot image settings
      |   |___ image storage media = primary flash
      |___ u-boot env partition settings
      |   |___ image storage media = primary flash
      |___ kernel image settings
      |   |___ image storage media = primary sd
      |___ jffs2 rootfs image settings
      |   |___ image storage media = primary flash
      |___ dtb image settings
         |___ image storage media = primary sd

*Image Packaging Configuration
   |___ Root filesystem type = EXT(SD/eMMC/QSPI/SATA/USB)
   |___ Un-select the 'Copy final images to tftpboot'

** Kernel Configuration
The kernel also must be set. Run:
petalinux-config -c kernel

*** And set these configs:

CONFIG_XILINX_GMII2RGMII=y
CONFIG_USB_USBNET=y
CONFIG_USB_NET_AX8817X=y
CONFIG_USB_NET_AX88179_178A=y
CONFIG_USB_NET_CDCETHER=y
# CONFIG_USB_NET_CDC_EEM is not set
CONFIG_USB_NET_CDC_NCM=y
# CONFIG_USB_NET_HUAWEI_CDC_NCM is not set
# CONFIG_USB_NET_CDC_MBIM is not set
# CONFIG_USB_NET_DM9601 is not set
# CONFIG_USB_NET_SR9700 is not set
# CONFIG_USB_NET_SR9800 is not set
# CONFIG_USB_NET_SMSC75XX is not set
CONFIG_USB_NET_SMSC95XX=y
# CONFIG_USB_NET_GL620A is not set
CONFIG_USB_NET_NET1080=y
# CONFIG_USB_NET_PLUSB is not set
# CONFIG_USB_NET_MCS7830 is not set
# CONFIG_USB_NET_RNDIS_HOST is not set
CONFIG_USB_NET_CDC_SUBSET_ENABLE=y
CONFIG_USB_NET_CDC_SUBSET=y
# CONFIG_USB_ALI_M5632 is not set
# CONFIG_USB_AN2720 is not set
CONFIG_USB_BELKIN=y
CONFIG_USB_ARMLINUX=y
# CONFIG_USB_EPSON2888 is not set
# CONFIG_USB_KC2190 is not set
CONFIG_USB_NET_ZAURUS=y
# CONFIG_USB_NET_CX82310_ETH is not set
# CONFIG_USB_NET_KALMIA is not set
# CONFIG_USB_NET_QMI_WWAN is not set
# CONFIG_USB_NET_INT51X1 is not set
# CONFIG_USB_SIERRA_NET is not set
# CONFIG_USB_VL600 is not set
# CONFIG_USB_NET_CH9200 is not set
CONFIG_USBIP_CORE=y
# CONFIG_USBIP_VHCI_HCD is not set
# CONFIG_USBIP_HOST is not set
# CONFIG_USBIP_VUDC is not set
# CONFIG_USBIP_DEBUG is not set
CONFIG_FB_SIMPLE=y
CONFIG_SND_SIMPLE_CARD_UTILS=y
CONFIG_SND_SIMPLE_CARD=y
# CONFIG_FRAMEBUFFER_CONSOLE is not set

CONFIG_STAGING=y
CONFIG_XILINX_APF=y
CONFIG_XILINX_DMA_APF=y
CONFIG_DMA_CMA=y
CONFIG_CMA_SIZE_MBYTES=256
CONFIG_CROSS_COMPILE="arm-xilinx-linux-gnueabi-"
CONFIG_LOCALVERSION="-xilinx-apf"
CONFIG_PRINTK_TIME=n
CONFIG_DEBUG_KERNEL=n
CONFIG_HAVE_DEBUG_KMEMLEAK=n
CONFIG_LOCKUP_DETECTOR=n
CONFIG_DEBUG_RT_MUTEXES=n
CONFIG_DEBUG_WW_MUTEX_SLOWPATH=n
CONFIG_PROVE_LOCKING=n
CONFIG_DEBUG_ATOMIC_SLEEP=n
CONFIG_PROVE_RCU=n
CONFIG_DMA_API_DEBUG=n


** Rootfs Configuration
Since we want to use a PYNQ image instead of Petalinux, there is no need to change rootfs configuration.

** Device-tree Configuration
Device-tree is located at: <petalinux-project>/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
copy the configuration below into "system-user.dtsi" file.
*** DEVICE-TREE:

/include/ "system-conf.dtsi"
/ {
};


/ {
    #address-cells = <1>;
    #size-cells = <1>;

    reserved-memory {
        #address-cells = <1>;
        #size-cells = <1>;
        ranges;
        hdmi_fb_reserved_region@1FC00000 {
            compatible = "removed-dma-pool";
            no-map;
            // 512M (M modules)
            reg = <0x1FC00000 0x400000>;
            // 128M (R modules)
            //reg = <0x7C00000 0x400000>;
        };
        camera_fb_reserved_region@1FC00000 {
            compatible = "removed-dma-pool";
            no-map;
            // 512M (M modules)
            reg = <0x1FC00000 0x400000>;
            // 128M (R modules)
            //reg = <0x7800000 0x400000>;
        };
    };



    hdmi_fb: framebuffer@0x1FC00000 {           // HDMI out
        compatible = "simple-framebuffer";
        // 512M (M modules)
        reg = <0x1FC00000 (1280 * 720 * 4)>;    // 720p
        // 128M (R modules)
        //reg = <0x7C00000 (1280 * 720 * 4)>;   // 720p
        width = <1280>;                         // 720p
        height = <720>;                         // 720p
        stride = <(1280 * 4)>;                  // 720p
        format = "a8b8g8r8";
        status = "okay";
    };

    camera_fb: framebuffer@0x1FC00000 {         // CAMERA in
        compatible = "simple-framebuffer";
        // 512M (M modules)
        reg = <0x1FC00000 (1280 * 720 * 4)>;    // 720p
        // 128M (R modules)
        //reg = <0x7800000 (1280 * 720 * 4)>;   // 720p
        width = <1280>;                         // 720p
        height = <720>;                         // 720p
        stride = <(1280 * 4)>;                  // 720p
        format = "a8b8g8r8";
    };

    vcc_3V3: fixedregulator@0 {
        compatible = "regulator-fixed";
        regulator-name = "vccaux-supply";
        regulator-min-microvolt = <3300000>;
        regulator-max-microvolt = <3300000>;
        regulator-always-on;
    };
};



&qspi {
    #address-cells = <1>;
    #size-cells = <0>;
    status = "okay";
    flash0: flash@0 {
        compatible = "jedec,spi-nor";
        reg = <0x0>;
        #address-cells = <1>;
        #size-cells = <1>;
        spi-max-frequency = <50000000>;
        partition@0x00000000 {
            label = "boot";
            reg = <0x00000000 0x00500000>;
        };
        partition@0x00500000 {
            label = "bootenv";
            reg = <0x00500000 0x00020000>;
        };
        partition@0x00520000 {
            label = "kernel";
            reg = <0x00520000 0x00a80000>;
        };
        partition@0x00fa0000 {
            label = "spare";
            reg = <0x00fa0000 0x00000000>;
        };
    };
};

&video_in_axi_vdma_0 {
   status = "disabled";
};

&video_out_axi_vdma_0 {
   status = "disabled";
};

&video_out_v_tc_0 {
    //xilinx-vtc: probe of 43c20000.v_tc failed with error -2
    status = "disabled";
};

&gpio0 {
    interrupt-controller;
    #interrupt-cells = <2>;
};

&i2c1 {
    #address-cells = <1>;
    #size-cells = <0>;

    i2cmux0: i2cmux@70  {
        compatible = "nxp,pca9544";
        #address-cells = <1>;
        #size-cells = <0>;
        reg = <0x70>;


        i2c1@0 {
            #address-cells = <1>;
            #size-cells = <0>;
            reg = <0>;

            id_eeprom@50 {
                compatible = "atmel,24c32";
                reg = <0x50>;
            };

        };
        i2c1@1 {    // Display Interface Connector
            #address-cells = <1>;
            #size-cells = <0>;
            reg = <1>;
        };
        i2c1@2 {    // HDMI Interface Connector
            #address-cells = <1>;
            #size-cells = <0>;
            reg = <2>;
        };
        i2c1@3 {    // Camera Interface Connector
            #address-cells = <1>;
            #size-cells = <0>;
            reg = <3>;
        };
    };

};

/{
    usb_phy0: usb_phy@0 {
        compatible = "ulpi-phy";
        #phy-cells = <0>;
        reg = <0xe0002000 0x1000>;
        view-port = <0x0170>;
        drv-vbus;
    };
};

&usb0 {
    usb-phy = <&usb_phy0>;
} ;


/{
    // Custom driver based on spdif-transmitter
    te_audio: dummy_codec_te {
        compatible = "te,te-audio";
        #sound-dai-cells = <0>;
    };

    // Simple Audio Card from AXI_I2S and custom XADC audio input and
    // PWM audio output cores
    sound {
        compatible = "simple-audio-card";
        simple-audio-card,name = "TE0726-PWM-Audio";
        simple-audio-card,format = "i2s";
        simple-audio-card,widgets =
            "Microphone", "In Jack",
            "Line", "Line In Jack",
            "Line", "Line Out Jack",
            "Headphone", "Out Jack";

        simple-audio-card,routing =
            "Out Jack", "te-out",
            "te-in", "In Jack";

        simple-audio-card,cpu {
            sound-dai = <&audio_axi_i2s_adi_0>;
        };
        simple-audio-card,codec {
            sound-dai = <&te_audio>;
        };
    };
};

&audio_axi_i2s_adi_0 {
    compatible = "adi,axi-i2s-1.00.a";
    reg = <0x43c00000 0x1000>;
    clocks = <&clkc 15>, <&clkc 18>; // FCLK_CLK0, FCLK_CLK3
    clock-names = "axi", "ref";
    dmas = <&dmac_s 0 &dmac_s 1>;
    dma-names = "tx", "rx";
    #sound-dai-cells = <0>;
};

&adc {
    status = "disabled";
};


/{
xlnk {
compatible = "xlnx,xlnk-1.0";
};
};



** Build the project
To build the petalinux-project run:
petalinux-build

** Packaging
As a final step, a boot image needs to be generated in PetaLinux using the petalinux-package command:
petalinux-package --boot --fsbl ../vitis_workspace/zynqberry_0/export/zynqberry_0/sw/zynqberry_0/boot/fsbl.elf --fpga ../vitis_workspace/zynqberry_0/export/zynqberry_0/hw/zsys_wrapper.bit --u-boot

* Load BOOT Image
Connect the Zynqberry board to the PC via USB cable (without SD card)

1. Open Vitis and load boot image into the Zynqberry's QSPI flash via Vitis with the Program Flash option (Xilinx > Program Flash).

*Since we're not loading a bare metal application, the Project Type is System*

+ Image File is the boot image generated by PetaLinux (located in <PetaLinux project directory>/images/linux/BOOT.BIN)

+ There is no memory offset in the flash to load the image into, so that is set to zero (0x0).

+ The Flash Type is qspi-x4-single, and it's good to check the option to verify after flash.

+ When loading files into the flash memory of a board, the FSBL is needed to boot the board to a point that the flash is powered on.
For the Zynqberry, the boot mode for normal operation is to boot from the QSPI flash, a separate FSBL is needed to tell the board to boot from JTAG for the flash operation.
FSBL file is located in <PetaLinux project directory>/images/linux/zynq_fsbl.elf

6. Launch

* PREPARE the SD Card

1. Download PYNQ-Z2 v2.5 PYNQ image from http://www.pynq.io/board.html

2. Load the image on a SD card (at least 8 GB)

3. Copy the image.ub and system.dtb files (located in <PetaLinux project directory>/images/linux/) into the BOOT partition

4. go to the rootfs partition, create eth0dhcp file in /etc/network/interfaces.d/ and copy:
*** eth0dhcp file content
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
***
5. Save the file and Unmount the SDcard

* Connetion to Zynqberry

1. Put the SD-card into the board

2. Connect the PC to the zynqberry device via ETHERNET cable

3. Power the board on (by connecting USB cable)
*Note that in a new connection, DHCP server may assign a new IP address to the board*

4. Find the IP address of the zynqberry by running: nmap 10.42.0.1/24
*NMAP must be installed before and network interface set to "shared to other computers" via nm-connection-editor*

5. Connect to the board by ssh command: ssh xilinx@<zynqberry IP address>
*password is* xilinx

6. You need to be in root to run pynq. Run sudo su (password xilinx).

7. Generate some traffics (e.g., ping google.de)

8. Run python (3 or higher) and import pynq
* References
https://www.hackster.io/news/zynqberry-update-to-vivado-vitis-2019-2-66a5f33fbab5
https://www.xilinx.com/support/documentation/sw_manuals/xilinx2015_2/sdsoc_doc/topics/introduction/task_using_petalinux_create_linux_boot_files.html
https://github.com/Xilinx/PYNQ-Networking/blob/master/README.md

sebo

Hi Perjikolaei,

This is a huge post! Many thanks for the detailed explanation. I'm still strugling with the process of compiling the framework on the zynqberry as I'd rather use the build scripts they provide on github.
I do like the simplicity of calling a make file and... boom. Done.
But for now, it doesnt't work so well. The make file compile the vivado project but get stuck afterward somewhere in the petalinux stage. I need to investigate furthermore.
When I'm done, I'll post this on githu I think.

Thanks again.

Sébastien