MIPI-CSI camera
1. MIPI Camera Overview1.1 Introduction to MIPI CSI2 InterfaceMIPI (Mobile Industry Processor Interface): An interface standard defined by a consortium founded in 2003 by companies including ARM, Nokia, ST, and TI. Its purpose is to standardize internal interfaces of mobile devices (e.g., camera, display, RF/baseband interfaces), thereby reducing the design complexity of mobile devices and increasing design flexibility.
Work Groups: The MIPI Alliance includes multiple work groups, each responsible for defining standards for corresponding devices. These include over a dozen groups such as the Camera Work Group, Display Work Group, and High-Speed Multi-Link Work Group.
The MIPI CSI-2 interface is the 2nd version of the CSI (Camera Serial Interface) standard specified by the Camera Work Group under the MIPI Alliance.
- Hardware Layer: Supports up to 4 virtual channels (Lanes) for data transmission. One Lane is physically implemented as a pair of differential signal lines (see the schematic below), with a maximum communication rate of 2.0 Gbps per Lane.
- Software Layer: The MIPI CSI-2 protocol stack consists mainly of the application layer, protocol layer, and physical layer. The protocol layer is further divided into: pixel/byte grouping/ungrouping layer, lower protocol layer, and channel management layer.
The EASY EAI Nano-TB development board features 2 MIPI CSI-2 interfaces, with 4 Lanes led out for each interface. Their position definitions are shown below.
The EASY EAI Nano-TB is shipped with an IMX415 monocular camera by default, along with a 40-pin FPC reverse cable with a 0.5mm pitch.
- Reverse Cable: The blue markers at both ends are on opposite sides.
- Forward Cable: The blue markers at both ends are on the same side.
- Wiring must be performed when the power is off.
- Use a reverse cable to connect the IMX415 camera to the Camera1 interface. (Note: Using the wrong cable may damage the camera or core board, so exercise extreme caution during wiring.)
- The connector latch and the blue plastic marker on the FPC cable must be on the same side, as shown in the figure below.
You can verify if the MIPI-CSI2 interface module is working properly using the dmesg command:
dmesg | grep "csi2-.phy"The normal mounting status of the camera is as follows (example output):
- A camera with sensor model
imx415is connected to the dphy0 interface, with MIPI-CSI2 address1-0036; - A camera with sensor model
imx415is connected to the dphy3 interface, with MIPI-CSI2 address4-0036.
If the target camera node does not appear, check the FPC cable connection to ensure it complies with the "1.3 Wiring Instructions".
1.5 Locate Available Device NodesOn the Rockchip platform, one MIPI-CSI interface corresponds to over 20 video nodes (generated as defined in the device tree), as shown in the figure below.
Note: CSI0 does not necessarily map to video0~24—this depends on the actual device tree configuration.
Furthermore, the nodes corresponding to MIPI-CSI cameras are fixed when modifying the kernel device tree (i.e., the number of MIPI-CSI cameras is configured in the kernel, and the video node configuration does not dynamically change based on whether the MIPI-CSI camera is connected).
Therefore, users need to find the descriptive information for these nodes. Linux's v4l2 framework unifies the descriptive information of these nodes in the /sys/class/video4linux/ directory, as shown in the figure below.
Navigate to any description (e.g., video22):
Use the cat command to view the content of the name file. Rockchip chip definition: If the name is mainpath or selfpath, then "video22" is an available node.
Execute the following command in any terminal directory to quickly scan the "name" description of all nodes:
grep "mainpath" /sys/class/video4linux/video*/nameIn this example, /dev/video22 and /dev/video23 are available nodes for MIPI-CSI0.
If you are reading this document for the first time, refer to《Getting Started Guide/Development Environment Preparation/Easy-EAI Compilation Environment Preparation and Update》,and deploy the compilation environment according to the relevant operations.
Execute the run script in the Ubuntu system on the PC to enter the EASY-EAI compilation environment:
cd ~/develop_environment
./run.shFirst, in the background terminal of the virtual machine, execute the following commands to create a directory for managing peripheral singleton source code:
cd /opt
mkdir -p EASY-EAI-Nano-TB/demoFirst, download the relevant singleton program from 【Baidu Netdisk】:
Link: https://pan.baidu.com/s/1Br608Hiff2Xs65PzWO_qWQ?pwd=1234
Extraction Code: 1234First, download the relevant singleton program from 【Baidu Netdisk】:Link: https://pan.baidu.com/s/1Br608Hiff2Xs65PzWO_qWQ?pwd=1234
For example, download the singleton program to: This PC\D:\BaiduNetdisk (no fixed rules; users can choose freely), as shown in the figure below.
Then copy the downloaded singleton program to the file system of the virtual machine, as shown in the figure below.
📷📷📷
Finally, enter the corresponding example directory and execute the compilation command:
cd EASY-EAI-Nano-TB/demo/02_camera
./build.shNotes:
- Since the dependent libraries are deployed on the board, the
/mntmount must be maintained during the cross-compilation process.
Access the background of the board via serial port debuggingor SSH debugging,and navigate to the deployment location of the example:
cd /userdataThe command to run the example is as follows:
./test-mipiCam 222.4 Execution EffectThe execution effect is as follows.
After the example runs, a photo image file will be generated in the /tmp directory. Return to the virtual machine, open a new terminal window, and copy the image back using the scp command:
Then play the photo using the mplayer command:
mplayer -demuxer rawvideo -rawvideo w=1920:h=1080:format=bgr24 photo -loop 0The default resolution of the example is 1920x1080, so fill in 1920 and 1080 for the w and h parameters. If the image is abnormal, the resolution may not match the camera in use—adjust the resolution in mipicamera_init() (e.g., 1280x720) and re-run the command.
The sample code path is: 02_camera/test-mipiCam/main.c. The logic flow of the MIPI Camera API test case code is as follows:
int main(int argc, char **argv)
{
int ret = 0;
if(1 == argc){
printf("\nerr: Missing parameter!\n");
printf("================= [usage] ==================\n");
printf("example:\n");
printf("\t%s <22/30>\n", argv[0]);
printf("--------------------------------------------\n");
return 0;
}
char *pbuf = NULL;
int skip = 0;
FILE *fp = NULL;
int cameraIndex = atoi(argv[1]); //通常是video22
ret = mipicamera_init(cameraIndex, CAMERA_WIDTH, CAMERA_HEIGHT, 0);
if (ret) {
printf("error: %s, %d\n", __func__, __LINE__);
goto exit3;
}
pbuf = (char *)malloc(IMAGE_SIZE);
if (!pbuf) {
printf("error: %s, %d\n", __func__, __LINE__);
ret = -1;
goto exit2;
}
//跳过前10帧
skip = 10;
while(skip--) {
ret = mipicamera_getframe(cameraIndex, pbuf);
if (ret) {
printf("error: %s, %d\n", __func__, __LINE__);
goto exit1;
}
}
/* tips: 可以在Ubuntu下用mplayer播放录制图像
* mplayer -demuxer rawvideo -rawvideo w=1920:h=1080:format=bgr24 photo -loop 0
*/
fp = fopen("/tmp/photo", "w");
if (!fp) {
printf("error: %s, %d\n", __func__, __LINE__);
ret = -1;
goto exit2;
}
fwrite(pbuf, 1, IMAGE_SIZE, fp);
fclose(fp);
exit1:
free(pbuf);
pbuf = NULL;
exit2:
mipicamera_exit(cameraIndex);
exit3:
return ret;
}Among them, mipicamera_init(), mipicamera_getframe(), and mipicamera_exit() are user-friendly encapsulations of v4l2 interface calls, with specific implementations in 02_camera/commonApi/mipi_camera.c.










Comments