Skip to main content

3.1.1 MIPI Camera User Guide

1.Environment Setup

1.1Hardware Connection

Please connect the MIPI camera module to the MIPI CSI interface on the development board. Refer to the figure below for the specific connection method:

Also, connect the development board to a monitor using an HDMI cable for image output.

2.Device Testing

2.1 Auto-Detect Camera Type

First, confirm the MIPI CSI port number that the camera is connected to. For example, if connected to CSI1, run the following command:

cam-test /usr/share/camera_json/csi1_camera_detect.json

First, confirm the MIPI CSI port number that the camera is connected to. For example, if connected to CSI1, run the following command:

...
I: ./sensors/cam_sensors_module.c(239): "detect imx219_spm sensors in csi3: success, set 1920x1080 to 1920x1080"
I: auto_detect_camera(1430): "auto detect sensor ===================== finish "
E: update_json_file(709): "Open /usr/share/camera_json/csi3_camera_auto.json file fail"
E: update_json_file(709): "Open /usr/share/csi3_camera_auto.json file fail"
I: update_json_file(723): "save json to /tmp/csi1_camera_auto.json success"

⚠️ If you're unsure about the CSI port number, refer to the MUSE Series Development Board User Manual or test CSI1 through CSI3 ports one by one. If the camera is still not detected, it might be a hardware failure or an unsupported camera model. In the latter case, refer to the official Camera Development Guide | Bianbu Linux for adaptation instructions.

2.2 Configure Virtual Camera Model

Copy the auto-generated camera configuration file to the specified path and rename it as svivi_cam1.json:

sudo cp /tmp/csi1_camera_auto.json /root/svivi_cam1.json

Open the JSON file and add the following field at the top level to enable Virtual Camera mode:

"use_v4l": 1

2.3 Test with V4L2 Output

Use the v4l2_test_spacemit tool for image capture testing.

Download and compile:

mkdir v4l2_test_spacemit
wget https://archive.spacemit.com/ros2/code/v4l2_test_spacemit.tar.gz
tar xvzf v4l2_test_spacemit.tar.gz
gcc v4l2_capture.c v4l2_main.c v4l2_output.c v4l2_stream.c v4l2_common.c -o v4l2_test_spacemit --static

Run the capture command:

./v4l2_test_spacemit \
--device /dev/video50 \
--set-fmt-video width=1920,height=1080,pixelformat=NV12 \
--verbose \
--stream-dmabuf \
--stream-loop \
--stream-save 10 \
--stream-to=test.yuv

Sample output:

...
VIDIOC_DQBUF: ok, type:9
VIDIOC_QBUF: ok, type:9
do_handle_cap:723 [INFO]m2m capture dequeue----------------: 15
...

Use Ctrl+C to interrupt the capture.

⚠️ Notes:

  • Maximum supported resolution: 1920×1080 (1080p)
  • Supported image format: NV12
  • Memory type required: dmabuf

If the above completes successfully, the MIPI camera is functional and ready for further development.

3.Advanced Development: C++ SDK Sample

Use the SDK provided by JDK for more advanced control and image processing.

3.1 C++ Sample Code

auto camera = JdkCamera::create("/dev/video50", 1920, 1080, V4L2_PIX_FMT_NV12);
auto jdkvo = std::make_shared<JdkVo>(1920, 1080, PIXEL_FORMAT_NV12);
auto frame = camera->getFrame();
auto ret = jdkvo->sendFrame(frame);

4.Quick Integration: JDK Camera Capture SDK

4.1 Download and Install JDK SDK

wget https://archive.spacemit.com/ros2/code/jdk_sdk.tar.gz
sudo tar xvf jdk_sdk.tar.gz -C /opt/
mv /opt/jdk_sdk /opt/jdk

Directory structure:

/opt/jdk
├── include
├── jdk_examples
├── ko
├── lib
├── Makefile
└── README.md

4.2 Download and Extract jdk_cam

wget https://archive.spacemit.com/ros2/code/jdk_cam.tar
tar xvf jdk_cam.tar

Directory structure:

jdk_cam/
├── Makefile
├── src/main.cpp
└── workspace/

4.3 Build and Run

cd jdk_cam
make all
insmod /opt/jdk/ko/jdk_dma.ko
./workspace/jdk_cam /dev/video50

4.4 Startup Log Sample

start buffer preprocessing
start buffer queue
VIDIOC_STREAMON succeeded
[MPP-DEBUG] 10419:VO_CreateChannel:43 create VO Channel success!
[MPP-DEBUG] 10419:module_init:159 +++++++++++++++ module init, module type = 101
[MPP-DEBUG] 10419:check_vo_sdl2:121 yeah! have vo_sdl2---------------
[MPP-DEBUG] 10419:find_vo_sdl2_plugin:86 yeah! we have vo_sdl2_plugin plugin---------------
[MPP-DEBUG] 10419:module_init:207 ++++++++++ VO_SDL2 (/usr/lib/libvo_sdl2_plugin.so)
[MPP-DEBUG] 10419:module_init:207 ++++++++++ open (/usr/lib/libvo_sdl2_plugin.so) success !
[MPP-ERROR] 10419:al_vo_init:93 SDL could not initialize! SDL_Error: wayland not available
[MPP-ERROR] 10419:al_vo_init:128 k1 vo_sdl2 init fail
[MPP-DEBUG] 10419:VO_Init:66 init VO Channel, ret = -400
[MPP-ERROR] 10419:JdkVo:32 VO_init failed, please check!
[MPP-DEBUG] 10419:VO_Process:82 vo one packet, ret = 0
index:0,dma_fd:12 width:1920,height:1080,size:3110400

5.Output Result

Once the program runs, the image captured by the camera will be displayed on the monitor in real time, as shown below:

6. Common Issues and Recommendations

IssueDescription
Camera not detectedCheck CSI connection, try different ports, verify camera model
Config file not createdCamera not recognized or driver not supported
SDL errorMissing graphical library dependencies; does not affect capture
No image displayCheck VO init logs, verify output channel and permissions