This article gives information about the Linux® V4L2 camera framework.
1. Framework purpose[edit source]
The V4L2 Linux kernel framework[1] allows to control both an external camera sensor and the camera interface in order to capture raw frames in various pixel formats or encoded stream data such as JPEG.
This could be typically used, with the help of other Linux multimedia frameworks and applications, to take snapshot, to make preview, to make a video recording or even remotely stream images from the camera sensor.
2. System overview[edit source]
2.1. Component description[edit source]
- media-ctl (User space)
A V4L2 utility relying on Media Controller Linux kernel interface[2] aiming to configure and link each sub devices composing the camera subsystem in order to configure it.
- Application (User space)
Any application relying on V4L2 Linux kernel interface[3] or libv4l abstraction layer. GStreamer framework provides such application.
- V4L2 utilities (User space)
A set of tools to test, configure and use the whole camera subsystem, including the external camera sensor and the camera interface. V4l2-ctl is one of the most usefull utility.
- V4L2 libraries (libv4l) (User space)
A set of libraries on top of the V4L2 Linux kernel interface[3] which abstract the kernel interface in order to simplify, keep compatibility or add some hooks between V4L-based applications and the V4L2 kernel interface.
- V4L2 core (Kernel space)
This layer represents the standard Linux kernel V4L2 Framework.
- stm32-dcmipp (Kernel space)
This V4L2 DCMIPP Linux device driver handles the DCMIPP hardware block.
- Camera sensor X driver (Kernel space)
This V4L2 Linux device driver handles the camera sensor X external peripheral, handles some GPIOs lines and potentially power supplies to power-up/down the camera sensor. The communication with camera sensor is done through the i2c bus.
- DCMIPP (Hardware)
The Digital Camera Memory Interface Pixel Processor hardware block.
- Camera sensor X (Hardware)
The camera sensor external peripheral.
2.2. APIs description[edit source]
The V4L2 userland API is documented in the Linux Media subsystem documentation[3]
The V4L2 kernel framework internal API is documented in the V4L2 Kernel Support section of the Linux Kernel documentation[4]
The Media Controller API is documented in the Linux Media subsystem documentation[2]
3. Configuration[edit source]
3.1. Kernel configuration[edit source]
The STM32 camera interface and OV5640 camera sensor are enabled by default in STMicroelectronics deliveries.
Nevertheless this is not the case when using upstream kernel version. In this case, the DCMI V4L2 driver can be enabled using Linux kernel menuconfig tool:
[*] Device Drivers --->
[*] Multimedia support --->
[*] V4L platform devices --->
[*] STM32 Digital Camera Memory Interface Pixel Processor (DCMIPP) support
The external camera sensor connected to the camera interface must also be enabled, here is an example with the OV5640 Omnivision camera sensor located on the MB1723 camera daughter board[5] connected to the CN1 camera connector[6] of the STM32MP13 discovery board[7]:
[*] Device Drivers --->
[*] Multimedia support --->
I2C Encoders, decoders, sensors and other helper chips --->
[*] OmniVision OV5640 sensor support
DCMIPP hardware block interconnects with the camera sensor connected on CN1 through the MIPID02 CSI-2 to parallel bridge soldered on STM32MP13 discovery board. Hence MIPID02 driver must be enabled too:
[*] Device Drivers --->
[*] Multimedia support --->
Media ancillary drivers --->
Miscellaneous helper chips --->
[*] STMicroelectronics MIPID02 CSI-2 to PARALLEL bridge
3.2. Device tree configuration[edit source]
Refer to DCMIPP device tree configuration article for a complete view of DCMIPP & sensor configuration thanks to Linux kernel device tree mechanism.
4. How to use the framework[edit source]
The use cases described here are enabled using media-ctl, V4l2-ctl, gst-launch or gst-play command line utilities.
4.1. Get the topology of camera subsystem[edit source]
media-ctl --print-topology media-ctl --print-dot > graph.dot dot -Tpng -Nfontname=Roboto -Nfontsize=10 -Efontname=Roboto -Efontsize=10 graph.dot > graph.png
4.2. List the video devices and their capabilities[edit source]
List all the available video devices using --list-devices option:
v4l2-ctl --list-devices
STM32 Camera Memory Interface (platform:dcmi): /dev/video0
If several devices are available, use -d option after any V4l2-ctl commands to target a specific device. If -d option is not specified, /dev/video0 is targeted by default.
In order to have information on a specific device, use -D option:
v4l2-ctl -d /dev/video0 -D
Driver Info (not using libv4l2): Driver name : stm32-dcmi Card type : STM32 Camera Memory Interface Bus info : platform:dcmi Driver version: X.Y.Z Capabilities : 0x85200001 Video Capture Read/Write Streaming Extended Pix Format Device Capabilities Device Caps : 0x05200001 Video Capture Read/Write Streaming Extended Pix Format
4.1. Controlling camera[edit source]
Use V4l2-ctl with -L option to get the list of supported controls:
v4l2-ctl -L
User Controls contrast (int) : min=0 max=255 step=1 default=0 value=0 flags=slider saturation (int) : min=0 max=255 step=1 default=64 value=64 flags=slider hue (int) : min=0 max=359 step=1 default=0 value=0 flags=slider white_balance_automatic (bool) : default=1 value=1 flags=update red_balance (int) : min=0 max=4095 step=1 default=0 value=128 flags=inactive, slider blue_balance (int) : min=0 max=4095 step=1 default=0 value=128 flags=inactive, slider exposure (int) : min=0 max=65535 step=1 default=0 value=885 flags=inactive, volatile gain_automatic (bool) : default=1 value=1 flags=update gain (int) : min=0 max=1023 step=1 default=0 value=32 flags=inactive, volatile horizontal_flip (bool) : default=0 value=0 vertical_flip (bool) : default=0 value=0 Camera Controls auto_exposure (menu) : min=0 max=1 default=0 value=0 flags=update 0: Auto Mode 1: Manual Mode Image Processing Controls test_pattern (menu) : min=0 max=1 default=0 value=0 0: Disabled 1: Color bars
The control value can be changed thanks to --set-ctrl option, for example:
v4l2-ctl --set-ctrl test_pattern=1
The control value can be changed dynamically. In the following example, the color bar is enabled/disabled while preview is running:
- Start preview in background
gst-launch-1.0 v4l2src ! "video/x-raw, width=1280, Height=720, framerate=(fraction)15/1" ! queue ! autovideosink -e &
- Then alternate the color bar activation or not
v4l2-ctl --set-ctrl test_pattern=1;sleep 1;v4l2-ctl --set-ctrl test_pattern=0;sleep 1;v4l2-ctl --set-ctrl test_pattern=1;sleep 1;v4l2-ctl --set-ctrl test_pattern=0;killall gst-launch-1.0
- Horizontal/vertical flip can also be changed while preview is running:
v4l2-ctl --set-ctrl horizontal_flip=1;sleep 2;v4l2-ctl --set-ctrl horizontal_flip=0;sleep 2;v4l2-ctl --set-ctrl vertical_flip=1;sleep 2;v4l2-ctl --set-ctrl vertical_flip=0;killall gst-launch-1.0
4.2. Get each subdevice capabilities[edit source]
Use --list-subdev-mbus-codes option on each subdevice to get the supported pixel format, resolution and framerate:
v4l2-ctl -d /dev/v4l-subdevX --list-subdev-mbus-codes
echo "" > media_formats.txt echo "["`cat /sys/class/video4linux/v4l-subdev3/name`"]" >> media_formats.txt v4l2-ctl -d /dev/v4l-subdev3 --list-subdev-mbus-codes >> media_formats.txt echo "["`cat /sys/class/video4linux/v4l-subdev2/name`"]" >> media_formats.txt v4l2-ctl -d /dev/v4l-subdev2 --list-subdev-mbus-codes >> media_formats.txt echo "["`cat /sys/class/video4linux/v4l-subdev0/name`"]" >> media_formats.txt v4l2-ctl -d /dev/v4l-subdev0 --list-subdev-mbus-codes >> media_formats.txt echo "["`cat /sys/class/video4linux/v4l-subdev1/name`"]" >> media_formats.txt v4l2-ctl -d /dev/v4l-subdev1 --list-subdev-mbus-codes >> media_formats.txt echo "["`cat /sys/class/video4linux/video0/name`"]" >> media_formats.txt v4l2-ctl -d /dev/video0 --list-formats-ext >> media_formats.txt cat media_formats.txt
[ov5640 1-003c] ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x4001: MEDIA_BUS_FMT_JPEG_1X8 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x200f: MEDIA_BUS_FMT_UYVY8_1X16 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x2011: MEDIA_BUS_FMT_YUYV8_1X16 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x1007: MEDIA_BUS_FMT_RGB565_2X8_BE 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 [st-mipid02 1-0014] ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 0x3007: MEDIA_BUS_FMT_SBGGR10_1X10 0x300e: MEDIA_BUS_FMT_SGBRG10_1X10 0x300a: MEDIA_BUS_FMT_SGRBG10_1X10 0x300f: MEDIA_BUS_FMT_SRGGB10_1X10 0x3008: MEDIA_BUS_FMT_SBGGR12_1X12 0x3010: MEDIA_BUS_FMT_SGBRG12_1X12 0x3011: MEDIA_BUS_FMT_SGRBG12_1X12 0x3012: MEDIA_BUS_FMT_SRGGB12_1X12 0x200f: MEDIA_BUS_FMT_UYVY8_1X16 0x1013: MEDIA_BUS_FMT_BGR888_1X24 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x1007: MEDIA_BUS_FMT_RGB565_2X8_BE 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x4001: MEDIA_BUS_FMT_JPEG_1X8 [dcmipp_parallel] ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x1007: MEDIA_BUS_FMT_RGB565_2X8_BE 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x2009: MEDIA_BUS_FMT_YVYU8_2X8 0x2007: MEDIA_BUS_FMT_VYUY8_2X8 0x2001: MEDIA_BUS_FMT_Y8_1X8 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 0x4001: MEDIA_BUS_FMT_JPEG_1X8 [dcmipp_dump_postproc] ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x2009: MEDIA_BUS_FMT_YVYU8_2X8 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x2007: MEDIA_BUS_FMT_VYUY8_2X8 0x2001: MEDIA_BUS_FMT_Y8_1X8 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 0x4001: MEDIA_BUS_FMT_JPEG_1X8 [dcmipp_dump_capture] ioctl: VIDIOC_ENUM_FMT Type: Video Capture [0]: 'RGBP' (16-bit RGB 5-6-5) Size: Continuous 16x16 - 4096x2160 [1]: 'YUYV' (YUYV 4:2:2) Size: Continuous 16x16 - 4096x2160 [2]: 'YVYU' (YVYU 4:2:2) Size: Continuous 16x16 - 4096x2160 [3]: 'UYVY' (UYVY 4:2:2) Size: Continuous 16x16 - 4096x2160 [4]: 'VYUY' (VYUY 4:2:2) Size: Continuous 16x16 - 4096x2160 [5]: 'GREY' (8-bit Greyscale) Size: Continuous 16x16 - 4096x2160 [6]: 'BA81' (8-bit Bayer BGBG/GRGR) Size: Continuous 16x16 - 4096x2160 [7]: 'GBRG' (8-bit Bayer GBGB/RGRG) Size: Continuous 16x16 - 4096x2160 [8]: 'GRBG' (8-bit Bayer GRGR/BGBG) Size: Continuous 16x16 - 4096x2160 [9]: 'RGGB' (8-bit Bayer RGRG/GBGB) Size: Continuous 16x16 - 4096x2160 [10]: 'JPEG' (JFIF JPEG, compressed) Size: Continuous 16x16 - 4096x2160
4.3. Set the pixel format, resolution and framerate[edit source]
Use --list-formats-ext option to get the supported pixel format, resolution and framerate:
v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT Index : 0 Type : Video Capture Pixel Format: 'JPEG' (compressed) Name : JFIF JPEG Size: Discrete 176x144 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 320x240 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 640x480 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 720x480 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 720x576 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1024x768 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1280x720 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1920x1080 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 2592x1944 Interval: Discrete 0.067s (15.000 fps) Index : 1 Type : Video Capture Pixel Format: 'UYVY' Name : UYVY 4:2:2 Size: Discrete 176x144 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 320x240 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 640x480 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 720x480 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 720x576 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1024x768 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1280x720 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1920x1080 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 2592x1944 Interval: Discrete 0.067s (15.000 fps) Index : 2 Type : Video Capture Pixel Format: 'YUYV' Name : YUYV 4:2:2 Size: Discrete 176x144 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 320x240 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 640x480 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 720x480 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 720x576 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1024x768 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1280x720 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1920x1080 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 2592x1944 Interval: Discrete 0.067s (15.000 fps) Index : 3 Type : Video Capture Pixel Format: 'RGBP' Name : 16-bit RGB 5-6-5 Size: Discrete 176x144 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 320x240 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 640x480 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 720x480 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 720x576 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1024x768 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1280x720 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 1920x1080 Interval: Discrete 0.067s (15.000 fps) Interval: Discrete 0.033s (30.000 fps) Size: Discrete 2592x1944 Interval: Discrete 0.067s (15.000 fps)
In order to change the camera configuration, select first the framerate using --set-parm option:
v4l2-ctl --set-parm=30
Then select the wanted resolution and/or pixel format using --set-fmt-video option:
v4l2-ctl --set-fmt-video=width=320,height=240,pixelformat=RGBP
4.4. Set the framerate[edit source]
- With V4l2-ctl, use --set-parm option giving the framerate numerator only, the denominator is fixed to 1 (only integer framerate values are allowed):
v4l2-ctl --set-parm=<framerate numerator>
Take 100 VGA pictures at 30fps:
v4l2-ctl --set-parm=30;v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=JPEG --stream-mmap --stream-count=100 --stream-to=pics@30fps.jpeg
Replay at 30fps using gst-play:
gst-play-1.0 pics@30fps.jpeg --videosink="videorate ! video/x-raw, framerate=(fraction)30/1 ! autovideosink"
Take 100 VGA pictures at 15fps:
v4l2-ctl --set-parm=15;v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=JPEG --stream-mmap --stream-count=100 --stream-to=pics@15fps.jpeg
Replay at 15fps using gst-play:
gst-play-1.0 pics@15fps.jpeg --videosink="videorate ! video/x-raw, framerate=(fraction)15/1 ! autovideosink"
- With GStreamer, using framerate caps:
gst-launch-1.0 v4l2src ! "video/x-raw, ... framerate=(fraction)<numerator>/<denominator>" ! ...
Preview VGA@30fps
gst-launch-1.0 v4l2src ! "video/x-raw, width=640, Height=480, framerate=(fraction)30/1" ! queue ! autovideosink -e
Preview VGA@15fps
gst-launch-1.0 v4l2src ! "video/x-raw, width=640, Height=480, framerate=(fraction)15/1" ! queue ! autovideosink -e
4.5. Grab a raw frame[edit source]
Capture a QVGA RGB565 raw frame on disk:
v4l2-ctl --set-fmt-video=width=320,height=240,pixelformat=RGBP --stream-mmap --stream-count=1 --stream-to=grab-320x240-rgb565.raw
In order to display it, this raw frame must be converted first to JPEG:
gst-launch-1.0 filesrc location= grab-320x240-rgb565.raw blocksize=153600 ! "video/x-raw, format=(string)RGB16, width=(int)320, height=(int)240, framerate=(fraction)30/1" ! videoconvert ! jpegenc ! filesink location=grab-320x240-rgb565.jpeg
Then weston-image utility can be used to display this JPEG file:
weston-image grab-320x240-rgb565.jpeg
4.6. Fullscreen preview[edit source]
gst-launch-1.0 v4l2src ! "video/x-raw, width=1280, Height=720, framerate=(fraction)15/1" ! queue ! autovideosink -e
4.7. Take a picture[edit source]
Capture a 5Mp JPEG:
v4l2-ctl --set-parm=15; v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=JPEG --stream-mmap --stream-count=1 --stream-skip=3 --stream-to=pic-5Mp.jpeg; v4l2-ctl --set-parm=30
Then display it:
weston-image pic-5Mp.jpeg
You can check the picture resolution using gst-typefind:
gst-typefind-1.0 pic-5Mp.jpeg
pic-5Mp.jpeg - image/jpeg, width=(int)2592, height=(int)1944, sof-marker=(int)0
4.8. Pictures streaming over network[edit source]
Refer to How to stream camera over network article to get some examples on how to stream camera content over network.
5. How to trace and debug[edit source]
5.1. How to monitor[edit source]
5.1.1. Check of devicetree configuration[edit source]
Here are some commands to verify that DCMI is enabled, check which camera sensor is used and log other details about devicetree settings:
rm devicetree.txt echo "[devicetree]" >> devicetree.txt echo "|-[dcmi]" >> devicetree.txt find /proc/device-tree/soc | grep dcmi | sed 's/\/proc\/device-tree\/soc\//| |-/' >> devicetree.txt echo "|" >> devicetree.txt echo "|-[camera:" | tr -d "\n" >> devicetree.txt cat /proc/device-tree/soc/i2c*/camera*/compatible >> devicetree.txt echo "]" >> devicetree.txt find /proc/device-tree/soc | grep camera | sed 's/\/proc\/device-tree\/soc\// |-/' >> devicetree.txt echo "" >> devicetree.txt cat devicetree.txt
[devicetree] |-[dcmi] | |-dcmi@4c006000 | |-dcmi@4c006000/compatible | |-dcmi@4c006000/clocks | |-dcmi@4c006000/resets | |-dcmi@4c006000/pinctrl-1 | |-dcmi@4c006000/port | |-dcmi@4c006000/port/endpoint | |-dcmi@4c006000/port/endpoint/hsync-active | |-dcmi@4c006000/port/endpoint/vsync-active | |-dcmi@4c006000/port/endpoint/remote-endpoint | |-dcmi@4c006000/port/endpoint/bus-width | |-dcmi@4c006000/port/endpoint/pclk-sample | |-dcmi@4c006000/port/endpoint/phandle | |-dcmi@4c006000/port/endpoint/linux,phandle | |-dcmi@4c006000/port/endpoint/name | |-dcmi@4c006000/port/name | |-dcmi@4c006000/clock-names | |-dcmi@4c006000/status | |-dcmi@4c006000/interrupts | |-dcmi@4c006000/dma-names | |-dcmi@4c006000/phandle | |-dcmi@4c006000/reg | |-dcmi@4c006000/pinctrl-0 | |-dcmi@4c006000/dmas | |-dcmi@4c006000/linux,phandle | |-dcmi@4c006000/name | |-dcmi@4c006000/pinctrl-names | |-pin-controller/dcmi-sleep@0 | |-pin-controller/dcmi-sleep@0/pins | |-pin-controller/dcmi-sleep@0/pins/pinmux | |-pin-controller/dcmi-sleep@0/pins/name | |-pin-controller/dcmi-sleep@0/phandle | |-pin-controller/dcmi-sleep@0/linux,phandle | |-pin-controller/dcmi-sleep@0/name | |-pin-controller/dcmi@0 | |-pin-controller/dcmi@0/pins | |-pin-controller/dcmi@0/pins/pinmux | |-pin-controller/dcmi@0/pins/bias-disable | |-pin-controller/dcmi@0/pins/name | |-pin-controller/dcmi@0/phandle | |-pin-controller/dcmi@0/linux,phandle | |-pin-controller/dcmi@0/name | |-[camera:ovti,ov5640] |-i2c@40013000/camera@3c |-i2c@40013000/camera@3c/compatible |-i2c@40013000/camera@3c/powerdown-gpios |-i2c@40013000/camera@3c/DOVDD-supply |-i2c@40013000/camera@3c/clocks |-i2c@40013000/camera@3c/rotation |-i2c@40013000/camera@3c/port |-i2c@40013000/camera@3c/port/endpoint |-i2c@40013000/camera@3c/port/endpoint/hsync-active |-i2c@40013000/camera@3c/port/endpoint/vsync-active |-i2c@40013000/camera@3c/port/endpoint/remote-endpoint |-i2c@40013000/camera@3c/port/endpoint/bus-width |-i2c@40013000/camera@3c/port/endpoint/pclk-sample |-i2c@40013000/camera@3c/port/endpoint/phandle |-i2c@40013000/camera@3c/port/endpoint/data-shift |-i2c@40013000/camera@3c/port/endpoint/linux,phandle |-i2c@40013000/camera@3c/port/endpoint/name |-i2c@40013000/camera@3c/port/name |-i2c@40013000/camera@3c/clock-names |-i2c@40013000/camera@3c/status |-i2c@40013000/camera@3c/reset-gpios |-i2c@40013000/camera@3c/phandle |-i2c@40013000/camera@3c/reg |-i2c@40013000/camera@3c/linux,phandle |-i2c@40013000/camera@3c/name
5.2. How to trace[edit source]
5.2.1. V4L2 userland API tracing[edit source]
Tracing of V4L2 userland API[3] can be enabled using command:
echo 0x3 > /sys/devices/platform/soc/*.dcmi/video4linux/video*/dev_debug
Traces are output in kernel log buffer:
dmesg
[10130.641469] video0: VIDIOC_TRY_FMT: type=vid-cap, width=640, height=480, pixelformat=YUYV, field=none, bytesperline= 1280, sizeimage=614400, colorspace=8, flags=0x0, ycbcr_enc=1, quantization=1, xfer_func=2 [10130.641550] video0: VIDIOC_S_FMT: type=vid-cap, width=640, height=480, pixelformat=YUYV, field=none, bytesperline=12 80, sizeimage=614400, colorspace=8, flags=0x0, ycbcr_enc=1, quantization=1, xfer_func=2 [10130.641597] video0: VIDIOC_G_PARM: type=vid-cap, capability=0x1000, capturemode=0x0, timeperframe=1/30, extendedmode =0, readbuffers=2 [10130.641638] video0: VIDIOC_G_PARM: type=vid-cap, capability=0x1000, capturemode=0x0, timeperframe=1/30, extendedmode =0, readbuffers=2 [10130.641681] video0: VIDIOC_S_PARM: type=vid-cap, capability=0x1000, capturemode=0x0, timeperframe=1/30, extendedmode =0, readbuffers=2 [10130.641740] video0: VIDIOC_G_CTRL: error -22: id=0x980927, value=0 [10130.642770] video0: VIDIOC_REQBUFS: count=0, type=vid-cap, memory=mmap [10130.642819] video0: VIDIOC_CREATE_BUFS: index=0, count=0, memory=mmap, type=vid-cap, width=640, height=480, pixelfor mat=YUYV, field=none, bytesperline=1280, sizeimage=614400, colorspace=8, flags=0x0, ycbcr_enc=1, quantization=1, xfer_f unc=2 [10130.658541] video0: VIDIOC_G_CTRL: error -22: id=0x980927, value=0 [10130.662770] video0: VIDIOC_REQBUFS: count=3, type=vid-cap, memory=mmap [10130.662852] video0: VIDIOC_QUERYBUF: 00:00:00.00000000 index=0, type=vid-cap, flags=0x00002000, field=any, sequence= 0, memory=mmap, bytesused=0, offset/userptr=0x0, length=614400 [10130.662892] timecode=00:00:00 type=0, flags=0x00000000, frames=0, userbits=0x00000000 [10130.662917] video0: VIDIOC_QUERYBUF: 00:00:00.00000000 index=1, type=vid-cap, flags=0x00002000, field=any, sequence= 0, memory=mmap, bytesused=0, offset/userptr=0x96000, length=614400 [10130.662952] timecode=00:00:00 type=0, flags=0x00000000, frames=0, userbits=0x00000000 [10130.662967] video0: VIDIOC_QUERYBUF: 00:00:00.00000000 index=2, type=vid-cap, flags=0x00002000, field=any, sequence= 0, memory=mmap, bytesused=0, offset/userptr=0x12c000, length=614400 [10130.663002] timecode=00:00:00 type=0, flags=0x00000000, frames=0, userbits=0x00000000 [10130.666880] video0: VIDIOC_STREAMON: type=vid-cap [10130.857484] video0: VIDIOC_CREATE_BUFS: index=3, count=1, memory=mmap, type=vid-cap, width=640, height=480, pixelfor mat=YUYV, field=none, bytesperline=1280, sizeimage=614400, colorspace=8, flags=0x0, ycbcr_enc=1, quantization=1, xfer_f unc=2 [10130.857585] video0: VIDIOC_QUERYBUF: 00:00:00.00000000 index=3, type=vid-cap, flags=0x00002000, field=any, sequence= 0, memory=mmap, bytesused=0, offset/userptr=0x1c2000, length=614400 [10130.857627] timecode=00:00:00 type=0, flags=0x00000000, frames=0, userbits=0x00000000 [10131.022069] video0: VIDIOC_STREAMOFF: type=vid-cap
5.2.2. V4L2 core framework tracing[edit source]
Tracing of the V4L2 core framework[4] can be enabled using commands:
echo 0x3 > /sys/module/videobuf2_core/parameters/debug echo 0x3 > /sys/module/videobuf2_v4l2/parameters/debug
Traces are output in kernel log buffer:
dmesg
[11875.487933] vb2-core: __setup_offsets: buffer 0, plane 0 offset 0x00000000 [11875.501731] vb2-core: __setup_offsets: buffer 1, plane 0 offset 0x001fb000 [11875.514901] vb2-core: __setup_offsets: buffer 2, plane 0 offset 0x003f6000 [11875.532298] vb2-core: __setup_offsets: buffer 3, plane 0 offset 0x005f1000 [11875.540019] vb2-core: __vb2_queue_alloc: allocated 4 buffers, 1 plane(s) each [11875.563689] vb2_dc_mmap: mapped dma addr 0xf1900000 at 0xb4f05000, size 2076672 [11875.571174] vb2-core: vb2_mmap: buffer 0, plane 0 successfully mapped [11875.589656] vb2-core: vb2_core_qbuf: qbuf of buffer 0 succeeded [11875.595684] vb2_dc_mmap: mapped dma addr 0xf1b00000 at 0xb4d0a000, size 2076672 [11875.603062] vb2-core: vb2_mmap: buffer 1, plane 0 successfully mapped [11875.609668] vb2-core: vb2_core_qbuf: qbuf of buffer 1 succeeded [11875.615642] vb2_dc_mmap: mapped dma addr 0xf1d00000 at 0xb4b0f000, size 2076672 [11875.623016] vb2-core: vb2_mmap: buffer 2, plane 0 successfully mapped [11875.629628] vb2-core: vb2_core_qbuf: qbuf of buffer 2 succeeded [11875.635617] vb2_dc_mmap: mapped dma addr 0xf1f00000 at 0xb4914000, size 2076672 [11875.642952] vb2-core: vb2_mmap: buffer 3, plane 0 successfully mapped [11875.649715] vb2-core: vb2_core_qbuf: qbuf of buffer 3 succeeded [11875.734058] vb2-core: vb2_core_streamon: successful [11875.961291] vb2-core: vb2_buffer_done: done processing on buffer 0, state: 6 [11875.967036] vb2-core: vb2_core_dqbuf: returning done buffer [11875.972437] vb2-core: vb2_core_dqbuf: dqbuf of buffer 0, with state 0 [11876.094639] vb2-core: vb2_buffer_done: done processing on buffer 1, state: 6 [11876.100367] vb2-core: vb2_core_dqbuf: returning done buffer [11876.105788] vb2-core: vb2_core_dqbuf: dqbuf of buffer 1, with state 0
5.2.3. DCMI V4L2 kernel driver tracing[edit source]
DCMI dynamic debug traces[8] can be enabled using command:
echo "module stm32_dcmi +p" > /sys/kernel/debug/dynamic_debug/control
Here is an example with a 5Mp jpeg capture:
gst-launch-1.0 v4l2src ! image/jpeg, width=2592, height=1944 ! fakesink dmesg
[12706.715949] stm32-dcmi 4c006000.dcmi: Sensor format set to 0x4001 2592x1944 [12706.721548] stm32-dcmi 4c006000.dcmi: Buffer format set to JPEG 2592x1944 [12707.365947] stm32-dcmi 4c006000.dcmi: Sensor format set to 0x4001 2592x1944 [12707.371551] stm32-dcmi 4c006000.dcmi: Buffer format set to JPEG 2592x1944 [12707.437537] stm32-dcmi 4c006000.dcmi: Sensor format set to 0x4001 2592x1944 [12707.443042] stm32-dcmi 4c006000.dcmi: Buffer format set to JPEG 2592x1944 [12707.459767] stm32-dcmi 4c006000.dcmi: Setup queue, count=4, size=5038848 [12707.518914] stm32-dcmi 4c006000.dcmi: buffer[0] phy=0xf1900000 size=5038848 [12707.526068] stm32-dcmi 4c006000.dcmi: buffer[1] phy=0xf1e00000 size=5038848 [12707.533299] stm32-dcmi 4c006000.dcmi: buffer[2] phy=0xf2300000 size=5038848 [12707.541456] stm32-dcmi 4c006000.dcmi: buffer[3] phy=0xf2800000 size=5038848 [12707.551443] stm32-dcmi 4c006000.dcmi: Start streaming, starting capture [12707.820885] stm32-dcmi 4c006000.dcmi: buffer[0] done seq=0, bytesused=499936 [12708.087436] stm32-dcmi 4c006000.dcmi: buffer[1] done seq=1, bytesused=447472 [12708.306415] stm32-dcmi 4c006000.dcmi: Stop streaming, errors=0 (overrun=0), buffers=2 [12708.319095] stm32-dcmi 4c006000.dcmi: Start streaming, starting capture [12708.333571] stm32-dcmi 4c006000.dcmi: Stop streaming, errors=0 (overrun=0), buffers=0
5.3. How to debug[edit source]
5.3.1. Errors[edit source]
Errors are unconditionnaly traced in kernel log:
dmesg [ 87.233672] stm32-dcmi 4c006000.dcmi: Some errors found while streaming: errors=1 (overrun=1), buffers=24
5.3.2. Memory tracking[edit source]
Frames require large chunks of contiguous memory, they are allocated by V4L2 framework through DMA backend. Those allocations can be traced using:
echo "module dma_contiguous +p" > /sys/kernel/debug/dynamic_debug/control echo "module videobuf2_dma_contig +p" > /sys/kernel/debug/dynamic_debug/control
Here is the trace after a VGA preview
[11311.617688] vb2_dc_mmap: mapped dma addr 0xf1900000 at 0xb3b6a000, size 614400 [11311.617986] vb2_dc_mmap: mapped dma addr 0xf1a00000 at 0xb3ad4000, size 614400 [11311.618071] vb2_dc_mmap: mapped dma addr 0xf1b00000 at 0xb3a3e000, size 614400 [11311.764146] vb2_dc_mmap: mapped dma addr 0xf1c00000 at 0xb307c000, size 614400
4 frames of VGA YUV422 frames: 640x480x2=614400 bytes
6. Source code location[edit source]
6.1. User space[edit source]
6.2. Kernel space[edit source]
7. References[edit source]
- ↑ Information about V4L2 Linux kernel framework on wikipedia.
- ↑ 2.0 2.1 Linux Media Infrastructure userspace API » Part IV - Media Controller API
- ↑ 3.0 3.1 3.2 3.3 Linux Media Infrastructure userspace API » Part I - Video for Linux API
- ↑ 4.0 4.1 Media subsystem kernel internal API » 1. Video4Linux devices
- ↑ MB1723 camera daughter board
- ↑ STM32MP135F-DK Discovery board CN1 Camera sensor connector
- ↑ STM32MP13 discovery board
- ↑ How to use the kernel dynamic debug