Using Camera in Linux Print


The i.MX 8M provides two Camera Serial Interface 2 (MIPI CSI2) interfaces, 4 lanes each. The i.MX 8M MIPI-CSI1 and MIPI-CSI2 ports are available on the J8 and J9 connectors on the IMXB-SOM-BSB carrier board, respectively. These connectors have identical pin-out, described by the following table:

J8 Function J9 Function
A1 GND A1 GND
A2 CSI_P1_CKN A2 CSI_P2_CKN
A3 CSI_P1_CKP A3 CSI_P2_CKP
A4 GND A4 GND
A5 1V8_P A5 1V8_P
A6 1V8_P A6 1V8_P
A7 GND A7 GND
A8 VSYS A8 VSYS
A9 VSYS A9 VSYS
A10 NC A10 NC
A11 CSI_P1_PWDN_1V8 A11 CSI_P2_PWDN_1V8
A12 GND A12 GND
A13 3V3_P A13 3V3_P
A14 3V3_P A14 3V3_P
A15 GND A15 GND
A16 5V_P A16 5V_P
A17 5V_P A17 5V_P
A18 GND A18 GND
B1 GND B1 GND
B2 CSI_P1_DN0 B2 CSI_P2_DN0
B3 CSI_P1_DP0 B3 CSI_P2_DP0
B4 GND B4 GND
B5 CSI_P1_DN1 B5 CSI_P2_DN1
B6 CSI_P1_DP1 B6 CSI_P2_DP2
B7 GND B7 GND
B8 CSI_P1_CLK_1V8 B8 CSI_P2_CLK_1V8
B9 CSI_P1_nRST_1V8 B9 CSI_P2_nRST_1V8
B10 CSI_I2C_SDA B10 CSI_I2C_SDA
B11 CSI_I2C_SCL B11 CSI_I2C_SCL
B12 GND B12 GND
B13 CSI_P1_DN2 B13 CSI_P2_DN2
B14 CSI_P1_DP2 B14 CSI_P2_DP2
B15 GND B15 GND
B16 CSI_P1_DN3 B16 CSI_P2_DN3
B17 CSI_P1_DP3 B17 CSI_P2_DP3
B18 GND B18 GND

The i.MX 8M MIPI CSI2 interface is comprised of the MIPI CSI Host Controller and the CSI2 bridge. Key parameters of both blocks are specified by the following child nodes in the root node of the arch/arm64/boot/dts/freescale/fsl-imx8mq.dtsi file:

/ { ... csi1_bridge: csi1_bridge@30a90000 { compatible = "fsl,imx8mq-csi", "fsl,imx6s-csi"; ... status = "disabled"; } csi2_bridge: csi2_bridge@30b80000 { compatible = "fsl,imx8mq-csi", "fsl,imx6s-csi"; ... status = "disabled"; } mipi_csi_1: mipi_csi1@30a70000 { compatible = "fsl,mxc-mipi-csi2_yav"; ... status = "disabled"; } mipi_csi_2: mipi_csi1@30b60000 { compatible = "fsl,mxc-mipi-csi2_yav"; ... status = "disabled"; } ... }

Emcraft has validated both MIPI CSI interfaces on the IMX8M-SOM-BSB board using the following camera board:

Linux support for the MINISASTOCSI is configured by the
meta-emcraft/recipes-kernel/linux/linux-imx/imx8m-som.dts file. Specifically, the
meta-emcraft/recipes-kernel/linux/linux-imx/imx8m-som.dts file defines the sensor endpoint configuration and instantiates an OV5640 camera instance on I2C1:

&i2c1 { ov5640_mipi: ov5640_mipi@3c { compatible = "ovti,ov5640_mipi"; ... port { ov5640_mipi1_ep: endpoint { remote-endpoint = <&mipi1_sensor_ep>; }; }; }; ov5640_mipi2: ov5640_mipi2@3c { compatible = "ovti,ov5640_mipi"; ... port { ov5640_mipi2_ep: endpoint { remote-endpoint = <&mipi2_sensor_ep>; }; }; }; ... } ... &csi1_bridge { fsl,mipi-mode; fsl,two-8bit-sensor-mode; status = "okay"; port { csi1_ep: endpoint { remote-endpoint = <&csi1_mipi_ep>; }; }; }; &csi2_bridge { fsl,mipi-mode; fsl,two-8bit-sensor-mode; status = "okay"; port { csi2_ep: endpoint { remote-endpoint = <&csi2_mipi_ep>; }; }; }; &mipi_csi_1 { #address-cells = <1>; #size-cells = <0>; status = "okay"; port { mipi1_sensor_ep: endpoint1 { remote-endpoint = <&ov5640_mipi1_ep>; data-lanes = <1 2>; }; csi1_mipi_ep: endpoint2 { remote-endpoint = <&csi1_ep>; }; }; }; &mipi_csi_2 { #address-cells = <1>; #size-cells = <0>; status = "okay"; port { mipi2_sensor_ep: endpoint1 { remote-endpoint = <&ov5640_mipi2_ep>; data-lanes = <1 2>; }; csi2_mipi_ep: endpoint2 { remote-endpoint = <&csi2_ep>; }; }; };

Note that the two MIPI CSI2 connectors share the same I2C bus - I2C1. As a result, connecting two MINISASTOCSI boards to the IMX8M-SOM-BSB at the same time will cause a conflict on the I2C bus, since the two MINISASTOCSI boards will have identical I2C addresses. To allow serving two MINISASTOCSI boards at the same time, the CSI-2 (J9) connector needs to be physically re-routed to a separate I2C bus (refer to Routing the Second CSI connector (J9) to a Separate I2C Bus below for the corresponding hardware re-work description).

For purposes of switching the location of the MINISASTOCSI board between the two MIPI CSI2 interfaces, the
meta-emcraft/recipes-kernel/linux/linux-imx/imx8m-som.dts file provides a special macro. In order to switch the location of the MINISASTOCSI board from the CSI1 interface (J8 connector) to the CSI2 interface (J9 connector), the following definition needs to be added to the beginning of the
meta-emcraft/recipes-kernel/linux/linux-imx/imx8m-som.dts file:

#define CSI2_CAM_ENABLE

Here is a photo of the MINISASTOCSI camera board connected to the J8 MIPI CSI2 connector of Emcraft i.MX 8M kit:

The following Linux user space commands can be used to capture a 1080p video stream from the MIPISASTOCSI camera board on the MIPI-CSI1 interface and show it on the connected display:

# gst-launch-1.0 v4l2src io-mode=3 device=/dev/video0 ! video/x-raw,width=1920, height=1080 ! kmssink

Routing the Second CSI connector (J9) to a Separate I2C Bus

  1. Cut the wires as shown in the picture. Be careful, the prepreg layer is thin and could be easily damaged. This theĀ CAD image and this is the PWB image.
  2. Solder two hook-up wires to the J9 contacts as shown in the picture.
  3. Connect those wires to the Q12 and Q11 transistors - the SCL wire to the SCL pad, and the SDA wire to the SDA pad, as shown in the CAD picture and the PWB picture.

Using Two MINISASTOCSI Boards at the Same Time

With the above hardware changes having been completed, download the mipi_csi2_separate_i2c_bus-ga.diff patch and apply it to the meta-emcraft/recipes-kernel/linux/linux-imx/imx8m-som.dts file:

$ cd meta-emcraft $ patch -p1 < /tmp/mipi_csi2_separate_i2c_bus-ga.diff patching file recipes-kernel/linux/linux-imx/imx8m-som.dts

Re-build the kernel and the DTS, as described in Building Linux Kernel, and boot Linux on the target.

The following Linux user space commands can be used to capture a 1080p video stream from the two MIPISASTOCSI camera boards and show it on the connected display:

  • Access camera connected to the CSI-1 connector (J8):

# gst-launch-1.0 v4l2src io-mode=3 device=/dev/video0 ! video/x-raw,width=1920, height=1080 ! kmssink

  • Access camera connected to the CSI-2 connector (J9):

# gst-launch-1.0 v4l2src io-mode=3 device=/dev/video1 ! video/x-raw,width=1920, height=1080 ! kmssink

Emcraft BSP is closely based on the NXP Linux L4.9.51 8MQuad GA release. Please refer to the NXP i.MX Linux User's Guide for this release, available in the documentation bundle here.
In the Section 7 of this document, there are a lot of examples of the video conversion, rotation, coding etc. using Gstreamer and its various plugins. See also Section 7.1 of the Release notes document for the Gstreamer plugins available specifically for i.MX8MQ in this software release.