Executing C code from Python on Linux (Petalinux) on ZCU102

In this simple demo, I will be showing how to configure the Petalinux to enable Python and the ctypes and cffi python packages and testing a simple demo.

Creating the Petalinux Image:

Open the project-spec\meta-user\recipes-core\images\petalinux-image.bbappend and add the Python packages below:

Next, return to the console and add the python packages to the rootfs:

Finally, to build:

Building C code shared object:

First, we need to create a shared library (.so) file. Here, I have a simple function that I used:


Compile:


Next, create the Simple Python script utilizing the ctypes to call this shared library:

Test on Hardware:

Boot the board, and setup the LAN:

ctypes:

Then run the ctypes_fib.py script:

cffi:

Next, create the Simple Python script utilizing the cffi to call this shared library:

Copy this to the board, and execute: