Using Video Camera OV5647

In this guide, we will step-by-step guide you to use video camera OV5647 on SP7350 platforms.

Table of Contents

1 OV5647 Specification

  • 5MP Max photograph resolution (2592 x 1944 = 5,038,848 pixels)

  • Pixel Size: 1.4 x 1.4 μm

  • Optical size: 1/4"

  • Lens: f=3.6 mm, f/2.9

  • Viewing Angle: 54° x 41°

  • Max video resolution: 1080p@30fps

  • Max frame rate: 480p@90fps

  • Maximum exposure times (seconds): 0.97

  • Selectable video resolutions: 1080p@30fps, 720p@60fps, 480p@90fps

2 Setup

2.1 Enable OV5647 in Linux Kernel Configuration

1 Enter the kernel configuration by running the following command in the top directory of project.

make kconfig

2 Selects sub-menus: Device Drivers>Multimedia support>Media ancillary drivers>Camera sensor devices

image-20240227-023120.png

3 Select “OmniVision OV5647 sensor support” and press <Y>. Then save and exit.

2.2 Modify Device-tree Source

Device-tree source files of SP7350 are located in linux/kernel/arch/arm64/boot/dts/sunplus/.

Here lists all files for SP7350 boards:

Boards

Device-tree source files

C3V-W EVB

sp7350-ev.dts

Modify device tree source file to define OV5647 source for driver

2.2.1 Using SP7350 MIPI/CSI-RX4

Open OV5647_INT macro to add OV5647 node and link mipicsirx4.

2.2.2 Using SP7350 Other MIPI/CSI-RX

Define OV5647 node in i2c node:

i2c { #address-cells = <1>; #size-cells = <0>; ov5647: ov5647@36 { compatible = "ovti,ov5647"; reg = <0x36>; clocks = <&ov5647_clk>; avdd-supply = <&ov5647_avdd_2v8>; dovdd-supply = <&ov5647_dovdd_1v8>; dvdd-supply = <&ov5647_dvdd_1v5>; port { ov5647_out: endpoint { remote-endpoint = <&csi1_ep1>; data-lanes = <1 2>; clock-noncontinuous; link-frequencies = /bits/ 64 <297000000>; }; }; }; };

port: Should contain one endpoint sub-node used to model connection to the video receiver according to the specification defined in Documentation/devicetree/bindings/media/video-interfaces.txt.

Video receiver endpoint sub-node should defined in mipicsirx node. For example:

mipicsirx: csirx@f8005480 { port@0 { reg = <0>; /* MIPI CSI-2 bus endpoint */ csi1_ep1: endpoint { remote-endpoint = <&ov5647_out>; bus-type = <4>; clock-lanes = <0>; data-lanes = <1 2>; }; };

2.3 Compile and Burn

Downloading and Compiling Code | 7. Build code

2.4 Connect Sensor Module

Using C3V-W board MIPI/CSI-RX4, as follows:

2.5 Check

After the burning is completed, start the board. The system should print the following information through the serial port.

After the system startup is completed, the video device can be viewed.

3 Test

3.1 v4l2-ctl Command

This command is used to control V4L2 devices from the command line. It allows you to query device capabilities, set device parameters, and capture video and still image.

Use v4l2-ctl --all --device /dev/video0 command getting device all information.

3.2 Capture Image

3.2.1 Config Video Device

Use v4l2-ctl -d /dev/video0 --set-ctrl params=value setting device controls.

Enable auto_exposure:

Enable gain_automatic

Enable white_balance_automatic

3.2.2 Capture

Use v4l2-ctl --list-formats-ext --device /dev/video0 querying device video format.

Use v4l2-ctl --stream capture image.

  • --set-fmt-video=width=1920,height=1080,pixelformat=pGAA set image format

  • --stream-count <count> stream <count> buffers. The default is to keep streaming forever. This count does not include the number of initial skipped buffers as is passed by --stream-skip.

  • --stream-skip <count> skip the first <count> buffers. The default is 0.

  • --stream-to <file> stream to this file. The default is to discard the data. If <file> is '-', then the data is written to stdout and the --silent option is turned on automatically.

  • --stream-mmap <count> capture video using mmap() [VIDIOC_(D)QBUF] count: the number of buffers to allocate. The default is 3.

After executing the capture command, the stream data is written to /home/root/ov5647.raw.

3.3 Display Image Raw Data

3.3.1 Download and Install Raw Image Viewer

Download raw image viewer from PixelViewer | Carina Studio. And PixelViewer is an open source project based cross-platform image which viewer supports reading raw Luminance/YUV/RGB/ARGB/Bayer pixels data from file and rendering it.

3.3.2 Use PixelViewer to Open Image

Config render params by 3.2.2 v4l2-ctl capture command