V4L2 mode for Raspberry Pi

From wiki_veye
Revision as of 10:20, 7 September 2021 by Admin (talk | contribs) (→‎Confirm the piOS version of your raspberry Pi)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

查看中文

How to use VEYE and CS series camera module on Raspberry Pi(V4L2 mode)

1 Introduction

For the use of VEYE series and CS series camera modules on the raspberry Pi platform, we provide veye_raspicam software, an application layer open source software similar to the raspicam. This series of software, without driver support, has good compatibility with different versions of piOS.

However, we think that the V4L2 driver mode also has a wide range of applications. The two modes cannot be used at the same time, which is embodied in whether the driver is installed or not. It will be described in detail later.

This article describes how to call the camera modules of VEYE series and CS series through V4L2 on the raspberry Pi platform.

2 Hardware Setup

VEYE series camera module setup on rpi

CS series camera module setup on rpi

3 RaspberryPi System Setup and Configuration

RaspberryPi System Setup and Configuration

4 Driver Installation

4.1 Download the driver

git clone https://github.com/veyeimaging/raspberrypi_v4l2.git

4.2 Install the driver

cd raspberrypi_v4l2/release/

chmod +x *

sudo ./install_driver.sh [camera module]

camera module:could be veye327,csimx307,cssc132,veyecam2m.

Note: veyecam2m is a new version driver that can replace veye327 and supports all modules of the VEYE series with 200W resolution.

Note: For VEYE-MIPI-IMX327S or VEYE-MIPI-IMX462, please make sure hdver must >= 0x5.

http://wiki.veye.cc/index.php/VEYE-MIPI-IMX327S_version_log

4.3 Uninstall the driver

If you need to change to using the camera by veye_raspicam software, or if you want to change to a driver of another camera module model, you must first uninstall the current driver.

sudo ./uninstall_driver.sh [camera module]

camera module:could be veye327,csimx307,cssc132.

5 Check and Test the Camera

Check the camera probe status

  • VEYE-MIPI-327

dmesg | grep veye

You can see:

veye327 camera probed

  • CS-MIPI-IMX307

dmesg | grep 307

You can see:

camera id is cs-mipi-imx307

  • CS-MIPI-SC132

dmesg | grep 132

You can see:

camera id is cs-mipi-sc132

5.1 List the video device

ls /dev/video0

The device node exsit.

5.2 List the available video modes

v4l2-ctl --list-formats-ext

6 Gstreamer usage Demo

export DISPLAY=:0

  • install gstreamer

sudo apt-get install gstreamer1.0-tools

  • Snap a picture (VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

gst-launch-1.0 v4l2src num-buffers=1 device=/dev/video0 ! 'video/x-raw, format=(string)UYVY, width=1920,height=1080' ! jpegenc ! filesink location=test_image.jpg

  • Preview (VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! videoconvert ! autovideosink sync=false -v

  • Preview (CS-MIPI-IMX307,CS-MIPI-SC132 @720p mode)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1280, height=(int)720,framerate=(fraction)60/1" ! videoconvert ! autovideosink sync=false -v

  • Preview (CS-MIPI-IMX307,CS-MIPI-SC132 @vga mode)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)640, height=(int)480" ! videoconvert ! autovideosink sync=false -v

  • Preview (CS-MIPI-SC132 @1280*1080@45 mode)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1280, height=(int)1080,framerate=(fraction)45/1" ! videoconvert ! autovideosink sync=false -v

  • Framerate test (VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! videoconvert ! fpsdisplaysink video-sink=fakesink -v

7 Video Control Toolkits Manual

Because of the high flexibility of our camera parameters, we do not use V4L2 parameters to control, but use scripts to configure parameters.

https://github.com/veyeimaging/raspberrypi/tree/master/i2c_cmd

VEYE Series Video Control Toolkits Manual

CS Series Video Control Toolkits Manual

8 Notes for CM4

Cm4 supports the use of two cameras at the same time. Following above steps will only be able to use CAM1. To use two cameras, follow the following steps:

8.1 Upgrade dt-blob.bin

wget https://www.raspberrypi.org/documentation/hardware/computemodule/dt-blob-dualcam.bin

sudo cp dt-blob-dualcam.bin /boot/dt-blob.bin

8.2 Upgrade dual camera version dtbo file

Use csimx307,5.10.17-v7l+ kernel as an example:

sudo cp raspberrypi_v4l2/release/driver_bin/5.10.17-v7l+/csimx307-dual-cm4.dtbo /boot/overlays/csimx307.dtbo

sudo reboot

8.3 Device node description

The CM4 module uses two I2C channels to communicate with the two cameras respectively.

description i2c bus num video node
CAM0 0 video0
CAM1 10 video2

Note: If there is only one camera, video node is always video0.

8.4 Gstreamer usage Demo

export DISPLAY=:0

  • CAM0 preview(VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! videoconvert ! fpsdisplaysink videosink=autovideosink sync=false text-overlay=false -v

  • CAM1 preview(VEYE-MIPI-327,CS-MIPI-IMX307 @1080p mode)

gst-launch-1.0 v4l2src device=/dev/video2 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! videoconvert ! fpsdisplaysink videosink=autovideosink sync=false text-overlay=false -v

9 Source code cross compilation

The main resources in this section are the official piOS building method. We use the method of cross-compilation, and the 5.4.72 version of 32bitOS is taken as an example.

The following operations are done on ubuntu PC.

9.1 Build cross-compilation environment on Ubuntu 64-bitoperating system)

sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev

sudo apt install crossbuild-essential-armhf

9.2 Download the standard version of the piOS source code

9.2.1 Confirm the piOS version of your raspberry Pi
  • Release version

$ uname -a

Linux raspberrypi 5.4.72-v7l+ #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l GNU/Linux

  • Code tag

$ cp /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz ./

gunzip changelog.Debian.gz

Check the top lines and you will know the tag.

9.2.2 There are two ways to get the source code of the version you want:
  1. using git to clone the corresponding branch and checkout the corresponding tag.

git clone --branch rpi-5.4.y https://github.com/raspberrypi/linux

git checkout raspberrypi-kernel_1.20201022-1

PS: Please replace the above two commands with your own corresponding versions.

2. Manually download the version code of the corresponding tag directly from the link below.

https://github.com/raspberrypi/linux/tags

9.3 Patch our code to kernel

  • Driver source code

camera driver path is : linux/drivers/media/i2c,copy our camera module drivers to this path.

  • Modify the the Makefile and Kconfig files

Modify the Config and Makefile in the same path,add the corresponding camera driver.

  • dts file

dts file path is :linux/arch/arm/boot/dts/overlays,copy our [camera]-overlay.dts files to this path.

  • Modify dts Makefile

Modify the Makefile in the same path,add the corresponding dts compilation option.

9.4 Building

9.5 Preparing

export ARCH=arm

export CROSS_COMPILE=arm-linux-gnueabihf-

  • Raspberry Pi 1, Pi Zero, Pi Zero W, and Compute Module default build configuration

KERNEL=kernel

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig

  • Raspberry Pi 2, Pi 3, Pi 3+, and Compute Module 3 default build configuration

KERNEL=kernel7

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig

  • Raspberry Pi 4 default build configuration

KERNEL=kernel7l

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2711_defconfig

9.6 Add compilation options

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

Add the compilation options by the corresponding camera module, for 5.4 version kernel the path is driver-- > multimedia-- > i2C.

For 5.10 version kernel,the path is Device Drivers --> Multimedia Support --> Media ancillary drivers --> Camera sensor devices.

9.6.1 Build

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j4

10 References

https://www.raspberrypi.org/documentation/linux/kernel/building.md