Capturing frames from CSI-2 camera in PYNQ-ZU

Greetings everyone,

I’m fairly new to the PYNQ framework. I have a PYNQ-ZU board which I am trying to use with a MIPI CSI-2 camera to capture some frames and get familiar with it. I saw that the base overlay of the PYNQ-ZU already supports such interface, but it seems specified that the supported camera is the PCAM 5C from Digilent. I tried using the framework to acquire a frame from my different camera (an Alvium MIPI CSI-2 from Allied Vision), but to no avail. I’m suspecting that I may need to integrate my own IP to interact with the camera since maybe the commands sent to the camera are the ones required for the PCAM and they may differ from mine but I wanted to make sure first if I was doing something wrong.

Here’s a code snippet which I used from a Jupyter notebook:

from pynq.overlays.base import BaseOverlay
from import *
import cv2
import numpy as np

base = BaseOverlay("base.bit")


framemode = VideoMode(800, 640, 8)

vdma0 = base.mipi.axi_vdma_0
vdma0.readchannel.mode = framemode

frame = vdma0.readchannel.readframe()


Now, when calling readframe() the code freezes and after stopping the execution the traceback shows the following:

KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-4-d0d4466487b0> in <module>()
----> 1 frame = vdma0.readchannel.readframe()
      2 PIL.Image.fromarray(frame)

/usr/local/lib/python3.6/dist-packages/pynq/lib/video/ in readframe(self)
    199                 loop = asyncio.get_event_loop()
    200                 loop.run_until_complete(
--> 201                     asyncio.ensure_future(self._interrupt.wait()))
    202                 pass
    203             self._mmio.write(0x34, 0x1000)

/usr/lib/python3.6/asyncio/ in run_until_complete(self, future)
    453         future.add_done_callback(_run_until_complete_cb)
    454         try:
--> 455             self.run_forever()
    456         except:
    457             if new_task and future.done() and not future.cancelled():

/usr/lib/python3.6/asyncio/ in run_forever(self)
    420             events._set_running_loop(self)
    421             while True:
--> 422                 self._run_once()
    423                 if self._stopping:
    424                     break

/usr/lib/python3.6/asyncio/ in _run_once(self)
   1394                            timeout * 1e3, dt * 1e3)
   1395         else:
-> 1396             event_list =
   1397         self._process_events(event_list)

/usr/lib/python3.6/ in select(self, timeout)
    443             ready = []
    444             try:
--> 445                 fd_event_list = self._epoll.poll(timeout, max_ev)
    446             except InterruptedError:
    447                 return ready


From what I’m understanding, I suspect that due to the fact that the configurations between the two MIPI cameras are different it may be impossible for me using this overlay to grab frames from this camera. This camera also supports the V4L2 drivers, but I don’t know whether the PYNQ image that I’m using (v2.6) supports it already and - if so - if there is any way of using it.

Thank you!

1 Like


The base overlay and the drivers are designed only for the Digilent pcam5C. If you want to use a different camera, you should configure the MIPI Rx subsystem to match your camera characteristics. You will also have to write the drivers to configure the camera to start streaming frames. For this camera we are not using v4l2 drivers, the driver is here PYNQ/pynq/lib/_pynq/_pcam5c at master · Xilinx/PYNQ · GitHub

The error you are seeing is because the camera is not streaming anything.


1 Like


thank you for your reply. Just to be perfectly clear, this would involve designing a specific IP and overlay for my camera, correct? I cannot reuse in any way the current IP by configuring it somehow?

Thank you.

1 Like


No, you can reuse the base overlay design (not the bitstream).

You would at least have to configure the MIPI CSI-2 Rx Subsystem within the MIPI hierarchy and generate the overlay again. This includes the pixel format, serial data lines, line rate and other camera characteristics. See image below

You may also need reconfigure the rest of IP in the mipi hierarchy.

The first step is to regenerate the base overlay and understand the mipi hierarchy PYNQ-ZU Base overlay | XUP PYNQ-ZU

Regarding the driver, instead of writing a C driver you can start with a python driver using python-periphery


1 Like

Great! Thank you very much for the useful input :slight_smile:

Let us know how you get on with this.

Greetings again,

I installed Vivado 2020.2 and PetaLinux (same version) and now I’m trying to regenerate the base overlay. I did the following steps:

  • cloning the PYNQ-ZU repo
  • from Vivado, I ran the script build_ip.tcl inside Pynq-ZU/base, but this initially failed since the script was not finding the ip folder.
  • after checking, I saw a script named, which apparently clones the ip folder within the main PYNQ repo.
  • I ran again the build_ip.tcl; apparently the RTL generation was successful, but when exporting the RTL into an IP I got the following error:
INFO: [HLS 200-1510] Running: export_design -format ip_catalog -description PYNQ ZU color_convert_2 -version 1.0 -display_name PYNQ ZU color_convert_2 
INFO: [IMPL 213-8] Exporting RTL as a Vivado IP.

****** Vivado v2020.2 (64-bit)
  **** SW Build 3064766 on Wed Nov 18 09:12:47 MST 2020
  **** IP Build 3064653 on Wed Nov 18 14:17:31 MST 2020
    ** Copyright 1986-2020 Xilinx, Inc. All Rights Reserved.

source run_ippack.tcl -notrace
bad lexical cast: source type value could not be interpreted as target
    while executing
"rdi::set_property core_revision 2202251425 {component component_1}"
    invoked from within
"set_property core_revision $Revision $core"
    (file "run_ippack.tcl" line 937)
INFO: [Common 17-206] Exiting Vivado at Fri Feb 25 14:25:55 2022...
ERROR: [IMPL 213-28] Failed to generate IP.
INFO: [HLS 200-111] Finished Command export_design CPU user time: 8.87 seconds. CPU system time: 0.66 seconds. Elapsed time: 17.99 seconds; current allocated memory: 183.050 MB.
command 'ap_source' returned error code
    while executing
"source ./build_hls_ip.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel \#0 [list source $arg] "

INFO: [HLS 200-112] Total CPU user time: 26.13 seconds. Total CPU system time: 1.7 seconds. Total elapsed time: 35.66 seconds; peak allocated memory: 179.219 MB.
INFO: [Common 17-206] Exiting vitis_hls at Fri Feb 25 14:26:06 2022...

I don’t know exactly what I’m supposed to do to fix it.

Thank you.

1 Like

It is Y2K22 bug