Linux Start Guide for ST BrightSense Image Sensors

This guide assists Linux users, developers, and enthusiasts in integrating the ST BrightSense product line from STMicroelectronics.

Introduction

ST BrightSense is a range of smart, high-performance CMOS image sensors developed by STMicroelectronics for professional and consumer vision applications. These sensors leverage cutting-edge pixel technologies to provide superior image quality for smart, accurate, and reactive vision-based systems. Combining advanced technology nodes and well-thought-out designs, ST BrightSense products feature a tiny form factor and ultra-low power consumption. Their rich toolbox of on-chip features allows for faster and lighter processing, supporting the next generation of smart devices.

All ST BrightSense image sensors are provided with a range of hardware and software tools for simple and easy evaluation and development. Linux drivers for ST BrightSense products are available for free download on st.com for integration into Linux-based embedded processing platforms. This guide provides essential knowledge and practical guidelines for integrating these advanced image sensors into a Linux environment, including hardware prerequisites, basic Linux knowledge, and a comprehensive installation procedure with practical tips.

Acronyms and Abbreviations

Acronym/Abbreviation Definition
V4L2 Video4Linux2: collection of drivers and API for realtime video capture on Linux systems
I2C Inter-integrated circuit (serial bus)
v4l2-ctl Application to control Video4Linux2 drivers
yavta "Yet another V4L2 test application": Application to control Video4Linux2 camera drivers
gstreamer Multimedia framework

Before Getting Started

This section provides an overview of the supported products and useful indications on where to find further product documentation. It also covers compatible hardware tools needed to connect ST BrightSense image sensors to embedded processing platforms.

Supported Devices

This guide covers all ST BrightSense portfolio products, including the following image sensors:

Sensor Reference Resolution Color Pattern Shutter Output
VD55G0 0.38 MP Monochrome Global MIPI CSI-2
VD55G1 0.56 MP Monochrome Global MIPI CSI-2
VD56G3 1.53 MP Monochrome Global MIPI CSI-2
VD66GY 1.53 MP RGB Global MIPI CSI-2
VD16GZ 1.53 MP RGB-IR Global MIPI CSI-2

Compatible ST BrightSense Hardware Tools

STMicroelectronics provides turnkey hardware tools for immediate integration onto Linux platforms, enabling instant plug-and-play connection to embedded processing platforms. The Linux drivers supported by this guide are developed to operate specifically on these hardware tools.

Each ST BrightSense image sensor is available with two main hardware kit options, each containing the necessary board, optics, and a 22-pin FFC/FPC cable.

The S-Board is a hardware kit including a sensor board for a given image sensor, equipped with an M12 lens holder and a removable lens, allowing users to change lenses at any time.

The P-Board is a hardware kit including a board with a connector for evaluating any camera module provided by STMicroelectronics and its authorized partners. This kit enables the evaluation of image sensors built as turnkey camera modules, saving effort associated with lens selection and focus.

Kit Category Kit Reference Sensor Included? Lens & Holder? Cable? Output Connector Output
S-Boards STEVAL-55G0MBI VD55G0 Yes Yes FFC/FPC MIPI CSI-2
S-Boards STEVAL-55G1MBI VD55G1 Yes Yes FFC/FPC MIPI CSI-2
S-Boards STEVAL-56G3MAI VD56G3 Yes Yes FFC/FPC MIPI CSI-2
S-Boards STEVAL-66GYMAI VD66GY Yes Yes FFC/FPC MIPI CSI-2
S-Boards STEVAL-16GZMAI VD16GZ Yes Yes FFC/FPC MIPI CSI-2
P-Board STEVAL-CAM-M0I None (promodule to order separately) No Yes FFC/FPC MIPI CSI-2

Finding Further Product Information

ST BrightSense documentation and free software tools, such as Linux drivers, are publicly available on st.com. While this guide focuses on Linux driver installation and prerequisites, further information on product specifications and features can be found in the dedicated product documentation. Each product webpage includes a "Documentation" section for access to data briefs, datasheets, user manuals, and application notes. The "Tools & Software" section lists compatible hardware and software tools and provides links to their respective webpages for more information and downloads.

Introduction to Linux Environment

About Linux Camera Stack

The Linux camera stack is a collection of open-source components that enable the interfacing and control of camera devices on Linux-based systems. It encompasses both kernel-level and user-space components, providing a comprehensive framework for different camera applications, from simple webcam utilities to complex computer vision systems.

Figure 4. Linux Camera Stack

The diagram illustrates the Linux camera stack, showing user space components like Libcamera, v4l2-ctl, yavta, and media-ctl, interacting with kernel space components such as V4L2 framework, V4L2 drivers, and device tree. Hardware components include the ST Image Sensor, SoC, CSI driver, and ISP driver.

Introduction to V4L2 Framework

Video for Linux 2 (V4L2) is the kernel API for handling video devices. It provides a collection of drivers and a standardized API for camera drivers, allowing applications to access and control various video capture devices, including USB cameras, embedded camera modules, and hardware IPs involved in image processing. V4L2 exposes device nodes (e.g., /dev/videoX, /dev/v4l-subdevX) to user space, enabling standard V4L2 applications to control sensors and capture frames. Many applications support V4L2, facilitating straightforward integration of image sensors:

  • v4l2-ctl: A command-line tool for querying and configuring V4L2 devices.
  • yavta: "Yet Another V4L2 Test Application", a command-line tool for configuring and capturing frames from V4L2 devices.
  • VLC: A media player with V4L2 support for capturing and streaming video from V4L2-compatible devices.
  • GStreamer: A multimedia framework with V4L2 plugins for capturing, processing, and streaming video.
  • OpenCV: A computer vision library with V4L2 support for capturing and processing video streams, widely used for image and video processing, object detection, and machine vision applications.

Introduction to Libcamera

Complementing V4L2 is libcamera, a user-space library providing a unified interface for camera applications. Libcamera abstracts the complexity of handling the media pipeline, offering a consistent API for camera control and image processing, and enabling support for advanced ISP features in modern SoCs. As a newer addition to the Linux camera stack, libcamera is dynamic and evolving, focusing on modernizing the camera stack and addressing the complexities of modern camera hardware and use cases.

Getting Started with Raspberry Pi

This section details the installation procedure to stream image sensors on a Raspberry Pi platform using the Linux driver package available for download on st.com. This procedure can be reused for other embedded platforms relying on a Linux environment that uses a V4L2 framework or Libcamera library.

Hardware Setup

Follow the instructions from Raspberrypi.com. Ensure the flex cable is plugged in correctly and before applying power.

Image Description: The image shows two electronic boards. The left board has a camera module attached via a flex cable, with a red 'X' marking indicating incorrect insertion. The right board, identified as a Raspberry Pi, shows a correctly inserted flex cable, marked with a green checkmark. Both boards have various connectors and components labeled.

V4L2 Driver

This section describes how to build and install the V4L2 driver on a Linux target platform. The driver is built directly on the target, for the corresponding target architecture and against the current running Linux kernel headers. Raspberry Pi is used as an example, but the process is similar on other Linux platforms.

V4L2 Driver Content

The V4L2 driver for ST BrightSense image sensors must be downloaded from st.com. Once unzipped on the target Linux platform, the following content should be available (example based on the vd55g1 driver):

  • dts: Main entry point for device tree overlays.
  • rpi: Device tree overlays for RPil to RP14 SBCs.
  • rpi5: Device tree overlays for RPi5 SBCs.
  • Kbuild: Configuration file for building kernel module.
  • Makefile: Build file containing recipe to compile the module.
  • README.md: Readme file.
  • st-vd55g1.c: Main V4L2 driver source file.
  • st-vd55g1_patch.c: Additional source code containing sensor's firmware patch.

Driver Installation

Ensure the Raspberry Pi is running an up-to-date Operating System. The latest Raspberry Pi OS (based on Kernel 6.6) was released on March 15th, 2024.

  1. Update package list:
    $ sudo apt update
  2. Install kernel headers (if not already installed):
    For 32-bit Raspberry Pi OS:
    $ sudo apt install linux-headers-rpi-{v6,v7,v71}
    For 64-bit Raspberry Pi OS:
    $ sudo apt install linux-headers-rpi-v8
  3. Compile the driver source:
    $ make
  4. Install the built module:
    $ sudo cp *.ko /lib/modules/$(uname -r)
    $ sudo depmod -a
  5. Reboot to apply changes:
    $ sudo reboot

Device Tree Configuration

The devicetree is a tree data structure describing hardware components. When new hardware is connected, the device tree must be updated accordingly.

  1. Ensure device tree compiler is present:
    $ sudo apt update
    $ sudo apt install device-tree-compiler
  2. Compile the device tree overlay:
    $ cd dts
    $ sudo dtc pcb4189.dts -o /boot/firmware/overlays/pcb4189.dtbo
  3. Set the device tree overlay:
    $ sudo sh -c "echo 'dtoverlay=pcb4189' >> /boot/firmware/config.txt"
  4. Reboot to apply modifications:
    $ sudo reboot

Libcamera

RPi OS Libcamera Update

Raspberry Pi OS includes the Libcamera library. Using Libcamera allows leveraging Broadcom HW ISP for image processing (debayering, 3A, etc.). Each Image Sensor must be described in Libcamera. Therefore, the RPi OS Libcamera package should be upgraded with a new version that describes all ST BrightSense Image Sensors. The following steps are specific to the Raspberry Pi platform.

Once the libcamera package is downloaded from st.com, it can be installed using the command:

$ sudo dpkg -i libcamera-ipa_0.2.0.deb

Libcamera Usage

With libcamera upgraded, you can use the rpicam-apps. Refer to RPi-OS documentation for details on these applications.

Quickstart one-liners:

  • List cameras and supported sensor modes:
    $ rpicam-hello --list-cameras
  • Display camera preview (default mode):
    $ rpicam-hello --timeout 0
  • Display camera preview (640x480 mode):
    $ rpicam-hello --timeout 0 --viewfinder-width 640 --viewfinder-height 480
  • Capture raw frame and JPEG after 5 seconds preview:
    $ rpicam-still --raw -o frame.jpg
  • Change camera tuning:
    $rpicam-hello -tuning-file path of file.json

Code Example using Libcamera

To utilize libcamera, you can develop your own application. Here is an example for streaming with Python.

First, install the necessary packages for Python 3:

$ sudo apt install -y python3-pyqt5 python3-opengl
$ sudo apt install -y python3-picamera2

Example Python Code:

This Python script demonstrates running at 60 fps in 1120x1360 for VD56G3/VD66GY sensors and capturing an image via a button click. For more control, refer to the picamera manual.

#!/usr/bin/python3

from PyQt5 import QtCore
from PyQt5.QtWidgets import (QApplication, QHBoxLayout, QLabel, QPushButton,
 QVBoxLayout, QWidget)
from picamera2 import Picamera2,Preview
from picamera2.previews.qt import QGlPicamera2
import io
import time

picam2 = Picamera2()

# picam2.post_callback = post_callback
picam2.configure(picam2.create_preview_configuration(main={"size": (1120,
1360)},raw={"format": "R8"}))
picam2.set_controls({"ExposureTime":1000,"AnalogueGain":1.0,"AeEnable":False,"FrameRate":60})

print (picam2.sensor_format)

app = QApplication([])

def on_button_clicked():
    button.setEnabled(False)
    cfg = picam2.create_still_configuration()
    picam2.switch_mode_and_capture_file(cfg, "test.jpg",
    signal_function=qpicamera2.signal_done)

def capture_done(job):
    picam2.wait(job)
    button.setEnabled(True)

qpicamera2 = QGlPicamera2(picam2, width=1120, height=1360, keep_ar=False)
button = QPushButton("Click to capture JPEG")
label = QLabel()
window = QWidget()

qpicamera2.donesignal.connect(capture_done)
button.clicked.connect(on_button_clicked)

label.setFixedWidth(400)
label.setAlignment(QtCore.Qt.AlignTop)

layout_h = QHBoxLayout()
layout_v = QVBoxLayout()

layout_v.addWidget(label)
layout_v.addWidget(button)

layout_h.addWidget(qpicamera2, 80)
layout_h.addLayout(layout_v, 20)

window.setWindowTitle("Qt Picamera2 App")
window.resize(1120, 1360)
window.setLayout(layout_h)

picam2.start()
app.exec_()

Getting Started with Other V4L2 Tools

While some embedded platforms like Raspberry Pi rely on Libcamera, other Linux-based platforms only support V4L2. In such cases, standard V4L2 tools are used to communicate with the image sensor.

v4l2-ctl

v4l2-ctl is a command-line tool for querying, configuring, or streaming from a V4L2 device. It is available in most distributions and can be installed on Debian-like systems with:

$ sudo apt install v4l-utils

Useful one-liners:

  • List formats and controls:
    $ v4l2-ctl --list-formats-ext --list-ctrls --list-ctrls-menu
  • Select format (resolution: 640x480, pixel format: GRBG Bayer 10Bit):
    $ v4l2-ctl --set-fmt-video width=640,height=480,pixelformat=BA10
  • Configure V4L2 controls (manual mode, exposure 1800 lines):
    $ v4l2-ctl --set-ctrl auto_exposure=1
    $ v4l2-ctl --set-ctrl exposure=1800
  • Configure Vertical Blanking to change framerate (vblank is resolution dependent):
    $ v4l2-ctl --set-ctrl vertical_blanking=3056
  • Capture 20 frames (saved to capture_20f.raw10):
    $ v4l2-ctl --stream-mmap --stream-count=20 --stream-to=capture_20f.raw10

yavta

yavta (Yet Another V4L2 Test Application) is a command-line tool supporting many V4L2 capabilities for interacting with V4L2 devices. It can be installed on Debian-like distributions with:

$ sudo apt install yavta

Useful one-liners:

  • List formats and controls:
    $ yavta --list-controls --enum-formats /dev/video0
  • Select format (resolution: 640x480, pixel format: GRBG Bayer 8Bit):
    $ yavta --size 640x480 --format SGRBG8 /dev/video0
  • Configure V4L2 controls (manual mode, exposure 1800 lines):
    $ yavta --set-control '0x009a090 1' /dev/video0
    $ yavta --set-control '0x00980911 1800' /dev/video0
  • Configure Vertical Blanking to change framerate (vblank is resolution dependent):
    $ yavta --set-control '0x009e0901 3056' /dev/video0
  • Capture (30 frames saved in 30 files):
    $ yavta --capture=30 --file=frame-%.raw8 /dev/video0

V4L2 Code Example

To utilize the V4L2 API, you can develop your own application. Here is an example for streaming with Python.

First, install the packages for Python 3:

$ pip3 install v4l2-python3
$ pip3 install opencv-python
$ pip3 install python3-nmap

Example Python Code:

from v4l2 import *
import cv2
import fcntl
import mmap
import numpy as np

vd = open('/dev/video0', 'rb+', buffering=0)
print(">> get device capabilities")
cp = v4l2_capability()
fctl.ioctl(vd, VIDIOC_QUERYCAP, cp)

print(">> device setup")
fmt = v412_format()
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SGRBG8
fmt.fmt.pix.width = 300
fmt.fmt.pix.height = 300

fctl.ioctl(vd, VIDIOC_S_FMT, fmt) # set whatever default settings we got before
fctl.ioctl(vd, VIDIOC_G_FMT, fmt) # get current settings
print("width:", fmt.fmt.pix.width, "height", fmt.fmt.pix.height)

print(">> init mmap capture")
req = v412_requestbuffers()
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE
req.memory = V4L2_MEMORY_MMAP
req.count = 2
fctl.ioctl(vd, VIDIOC_REQBUFS, req)

buffers = []
req.count = 2
for ind in range (req.count):
    # setup a buffer
    buf = v412_buffer()
    # tell the driver that we want some buffers
    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE
    buf.memory = V4L2_MEMORY_MMAP
    buf.index = ind
    fctl.ioctl(vd, VIDIOC_QUERYBUF, buf)
    mm = mmap.mmap(vd.fileno(), buf.length, mmap.MAP_SHARED, mmap.PROT_READ |
                   mmap.PROT_WRITE, offset=buf.m.offset)
    buffers.append(mm)

    # queue the buffer for capture
    fctl.ioctl(vd, VIDIOC_QBUF, buf)

print(">> Start streaming")
buf_type = v412_buf_type(V4L2_BUF_TYPE_VIDEO_CAPTURE)
fctl.ioctl(vd, VIDIOC_STREAMON, buf_type)

while True: # capture 50 frames
    buf = v412_buffer()
    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE
    buf.memory = V4L2_MEMORY_MMAP
    fctl.ioctl(vd, VIDIOC_DQBUF, buf) # get image from the driver queue
    mm = buffers[buf.index]
    image_data = np.frombuffer(mm, dtype=np.uint8, count=fmt.fmt.pix.bytesperline * fmt.fmt.pix.height).reshape(fmt.fmt.pix.height, fmt.fmt.pix.bytesperline)
    cv2.imshow("test", image_data)
    k = cv2.waitKeyEx(1)
    if k == 27:
        exit(1)
    fctl.ioctl(vd, VIDIOC_QBUF, buf) # requeue the buffer

print(">> Stop streaming")
fctl.ioctl(vd, VIDIOC_STREAMOFF, buf_type)
vd.close()
Models: VL53L8CX Low Power High Performance 8x8 Multizone, VL53L8CX, Low Power High Performance 8x8 Multizone, High Performance 8x8 Multizone, Performance 8x8 Multizone

File Info : application/pdf, 17 Pages, 677.15KB

PDF preview unavailable. Download the PDF instead.

linux-startguide-stbrightsense

References

Microsoft Word for Microsoft 365

Related Documents

Preview STMicroelectronics VD16GZ S-Board: MIPI CSI-2 Kit for Image Sensor Evaluation
A comprehensive hardware kit for evaluating and integrating the VD16GZ image sensor with MIPI CSI-2 interface. Includes sensor board, M12 lens holder, default lens, and ribbon cable for easy integration with embedded platforms and PC evaluation.
Preview STEVAL-EVK-U0I Data Brief: ST BrightSense Image Sensor Evaluation Kit
Data brief for the STEVAL-EVK-U0I EVK Main hardware USB kit from STMicroelectronics, designed for evaluating ST BrightSense image sensors on a computer. Features include a versatile mechanical holder, USB3 connectivity, and compatibility with various promodules and M12 lenses. Includes technical specifications and revision history.
Preview Integrating ST33TPHF2xSPI and ST33TPHF2xI2C TPMs with Linux on Raspberry Pi
This application note from STMicroelectronics guides users on integrating ST33TPHF2xSPI and ST33TPHF2xI2C Trusted Platform Modules (TPMs) with Linux on Raspberry Pi boards, covering kernel setup, tools, and use cases for enhanced security.
Preview Getting Started with MEMS-Studio User Manual
A comprehensive guide to STMicroelectronics' MEMS-Studio software, detailing installation, configuration, sensor evaluation, data analysis, and algorithm development for MEMS sensors.
Preview STM32 Nucleo-144 Board NUCLEO-L496ZG - STMicroelectronics
Data brief for the STM32 Nucleo-144 board (NUCLEO-L496ZG) from STMicroelectronics, featuring an STM32L496ZGT6 microcontroller, Arduino Uno V3 and ST morpho connectivity, and an integrated ST-LINK/V2-1 debugger. Ideal for prototyping and embedded system development.
Preview Getting Started with STSW-STSA110-SSL Software Package
User manual detailing the integration of the STSW-STSA110-SSL software package with the STSAFE-A110 secure element. It covers setup, OpenSSL integration, and AWS IoT connectivity for secure applications.
Preview ST Visual Develop (STVD) for Microcontroller Applications
Explore ST Visual Develop (STVD), a comprehensive IDE for efficient microcontroller application development. Learn about its features for writing, building, debugging, and programming with ST microcontrollers, including C compiler integration and advanced debugging tools.
Preview STM32 Nucleo-144 Board: Features, Specifications, and Ordering Information
Comprehensive overview of the STMicroelectronics STM32 Nucleo-144 development board, detailing its features, connectivity options, technical specifications, ordering codes, and revision history for embedded systems development.