A 7 series FPGA has no D-PHY receiver in its I/O. The lanes of a MIPI camera still reach it, through termination on the board and ordinary SelectIO inputs. This article follows a Digilent Pcam 5C (OV5640 sensor) from its two CSI-2 lanes to a frame in DDR on a Zybo Z7-20, using IronCapture.
The stages
| Stage | What it does |
|---|---|
| Physical receiver | Samples the two data lanes against the sensor's high-speed clock. Each lane has its own input delay, set from registers, with a 200 MHz delay reference. |
| Lane and packet logic | Aligns the two lane byte streams, checks each packet header and keeps the programmed virtual channel and data type. |
| RAW10 unpack | Turns the packed payload into 10-bit Bayer samples. |
| Image pipeline | Black level, white-balance gains, a 3 × 3 bilinear demosaic, green equalization, gamma and a highlight clamp, then conversion to YUYV. |
| DDR writer | Waits for a frame start, packs the stream into full-width beats and writes AXI4 bursts of up to 16 beats. |
A clock-crossing FIFO sits between the receiver and the image pipeline, so the sensor's clock ends at the FIFO and everything after it runs on the system clock. On the Zybo reference that clock is 100 MHz.
RAW10 and the data type
The sensor sends Bayer samples as CSI-2 data type 0x2B. RAW10 packs four 10-bit samples into five bytes, so a 1920-pixel line is 2,400 payload bytes. The packet header carries the data type, the virtual channel and the length, protected by an error-correcting code. The payload ends with a CRC. IronCapture checks all three and filters on virtual channel 0 by default.
Bring it up one stage at a time
A camera that produces no picture can be failing at any stage, and a black frame in memory says nothing about which. IronCapture keeps twelve receiver counters for that reason. They separate corrected headers, uncorrectable headers, payload CRC errors, unexpected data types, truncated lines, FIFO overflow and loss of the sensor clock.
- No packets at all points to the clock lane, the lane enables or the settle interval.
- Header errors with packets arriving point to the per-lane input delays or the bit order.
- Clean headers with CRC errors point to marginal data sampling on one lane.
- Clean packets with no frame in memory point to the writer: the destination address, or the frame start it is waiting for.
The core also has a pattern generator: static bars, scrolling bars, a moving box and a noise band. It feeds the same output as the camera, so the DDR writer, the display and the encoder can be proven with the sensor idle. Our Nexys Video streaming demo runs entirely from that generator.
What the Zybo Z7-20 measured
| Test | Result |
|---|---|
| Camera, 720p30 | 120 of 120 requested frames returned |
| Camera, 1080p30 | 300 of 300 requested frames returned, with 1080p60 HDMI scanout running and zero display underruns |
| Pattern under encoder load, 1080p | 30.0 frames/s and 124.4 MB/s over 90 seconds, with zero capture DMA errors |
The payload rate into DDR is 55.296 MB/s at 720p30 and 124.416 MB/s at 1080p30. The writer is a write-only AXI4 master at 32, 64 or 128 bits, so on a Zynq it takes one high-performance port and leaves the others for the display and the encoder.
Under Linux
The V4L2 driver exports each captured frame as a DMA-BUF. An application passes that buffer to the H.264 encoder driver without copying it, which is how the Zybo Z7-20 design captures, displays and streams at once. A second top level drops the DDR writer and gives 32-bit AXI4-Stream YUYV for designs that process the video in logic.