The i.MX8M Nano processor provides an Image Sensor Interface (ISI) module that interfaces a pixel link source to obtain the image data for processing in its pipeline channel.

On the ConnectCore 8M Nano Development Kit:

  • A MIPI CSI-2 connector is available.

The BSP includes support for the Omnivision ov5640 CSI camera model.

Kernel configuration

You can manage the CSI driver support and Video4Linux (V4L2) capture driver through the following kernel configuration options:

  • IMX8 Image Sensor Interface Core Driver (CONFIG_IMX8_ISI_CORE)

  • IMX8 MIPI CSI2 SAMSUNG Controller (CONFIG_IMX8_MIPI_CSI2_SAM)

  • OmniVision OV5640 sensor support (CONFIG_VIDEO_OV5640)

These options are enabled as built-in on the default ConnectCore 8M Nano kernel configuration file.

Kernel driver

The drivers for CSI capture are located at:

File Description

drivers/staging/media/imx/imx8-isi-core.c

IMX8 Image Subsystem driver

drivers/staging/media/imx/imx8-mipi-csi2-sam.c

Freescale MIPI-CSI2 receiver driver

drivers/media/i2c/ov5640.c

OV5640 MIPI Camera Subdev Driver

Device tree bindings and customization

Common bindings for video receiver and transmitter interfaces are described at Documentation/devicetree/bindings/media/video-interfaces.yaml.

The device tree must contain entries for:

  • The V4L2 capture interface

  • The camera sensor

  • The IOMUX

V4L2 capture interface (CSI)

ConnectCore 8M Nano Development Kit device tree
[...]

&isi_0 {
	status = "okay";

	cap_device {
		status = "okay";
	};
};

[...]

&cameradev {
	status = "okay";
};

[...]

&mipi_csi_1 {
	#address-cells = <1>;
	#size-cells = <0>;
	status = "okay";

	/* Camera 0  MIPI CSI-2 (CSIS0) */
	port@0 {
		reg = <0>;
		mipi_csi0_ep: endpoint {
			remote-endpoint = <&ov5640_mipi_ep>;
			data-lanes = <2>;
			csis-hs-settle = <13>;
			csis-clk-settle = <2>;
			csis-wclk;
		};
	};
};

[...]

Camera sensor (I2C2 slave)

ConnectCore 8M Nano Development Kit device tree
&i2c2 {
	[...]

	/* MIPI-CSI camera */
	ov5640_mipi: ov5640_mipi@3c {
		compatible = "ovti,ov5640";
		reg = <0x3c>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_mipi>;
		clocks = <&clk IMX8MN_CLK_CLKO1>;
		clock-names = "xclk";
		assigned-clocks = <&clk IMX8MN_CLK_CLKO1>;
		assigned-clock-parents = <&clk IMX8MN_CLK_24M>;
		assigned-clock-rates = <24000000>;
		csi_id = <0>;
		reset-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
		mclk = <24000000>;
		mclk_source = <0>;
		mipi_csi;

		port {
			ov5640_mipi_ep: endpoint {
				remote-endpoint = <&mipi_csi0_ep>;
				data-lanes = <1 2>;
				clocks-lanes = <0>;
			};
		};
	};

	[...]
};

IOMUX configuration

ConnectCore 8M Nano Development Kit device tree
&iomuxc {
	[...]

	pinctrl_mipi: mipi {
		fsl,pins = <
			/* MIPI_CSI_RESET_N */
			MX8MN_IOMUXC_GPIO1_IO12_GPIO1_IO12 0x19
		>;
	};

	[...]
};

Using the camera

Identify the camera

When the camera is connected to the ConnectCore 8M Nano Development Kit, the system identifies the camera sensor on the I2C bus and assigns a video device node /dev/videoX to it, where X is an integer number. You can determine the device index assigned to the camera on the kernel boot-up messages:

[    2.954104] mx8-img-md: Registered mxc_isi.0.capture as /dev/video0
[    2.960584] mx8-img-md: Registered sensor subdevice: ov5640 2-003c (1)
[    2.967150] mx8-img-md: created link [mxc_isi.0] => [mxc_isi.0.capture]
[    2.973807] mx8-img-md: created link [mxc-mipi-csi2.0] => [mxc_isi.0]
[    2.980319] mx8-img-md: created link [ov5640 2-003c] => [mxc-mipi-csi2.0]
The following examples assume the camera is /dev/video0.

Preview a camera image using gstreamer

Capture the camera image and preview it using gstreamer and Wayland sink:

# gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,width=320,height=240 ! waylandsink

Take a picture with the camera using gstreamer

Capture a still image with the camera and save it using gstreamer:

# gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=1 ! video/x-raw,width=320,height=240 ! jpegenc ! filesink location=sample.jpg

To show the captured image using gstreamer:

# gst-launch-1.0 filesrc location=sample.jpg ! jpegdec ! imagefreeze ! waylandsink

Record a video with the camera using gstreamer

Capture a moving image with the camera and save it using gstreamer:

# gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=90 ! video/x-raw,width=320,height=240 ! avimux ! filesink location=output.avi