world leader in high performance signal processing
Trace: » v4l2_blackfin_capture

v4l2 Blackfin Capture Driver

The Blackfin Capture Driver is a v4l2 driver supporting several CMOS Camera and Video Decoders on multiple platforms.





Configure Kernel

You typically need to enable i2c support and the CMOS Camera or Video Decoder driver. The driver utilizes at least two buffers to store captured frames. All buffers are located in uncached memory area.

  • Config DMA region size:
    The size is dependent on image resolution, bytes per pixel and requested numbers of buffer
    Blackfin Processor Options  --->
        Uncached DMA region (Enable 4M DMA region)  ---> 
  • I2C support:
    Device Drivers  --->
        <M> I2C support  --->
                I2C Hardware Bus support  --->
                    <M> Blackfin TWI I2C support
                    (100) Blackfin TWI I2C clock (kHz)
    For BF561
                I2C Hardware Bus support  --->
                    <M> GPIO-based bitbanging I2C
  • Enable v4l2 and capture driver:
    Device Drivers  --->
        <M> Multimedia support  --->
            [*]   Cameras/video grabbers support
            [*]   Media Controller API (EXPERIMENTAL)
            [*]   V4L platform devices  --->
                  <M>   Blackfin Video Capture Driver
            Encoders, decoders, sensors and other helper chips  --->
                  <M> Analog Devices ADV7183 decoder
                  <M> Analog Devices ADV7842 decoder
                  <M> ST VS6624 sensor support
                  <M> Aptina MT9M114 sensor support

Configure Userspace Application

  • In buildroot, enable V4L2 video test application to capture video file in BF609-EZKIT with ADV7842.
    Package Selection for the target  --->
        Miscellaneous  --->
            [*] V4L2 video test program

User application Interface

User space application should access the camera driver only via video4linux2 APIs.

  • The document of V4L2 can be found here.
  • An simple example can be found here.

Example usage

VS6624 Example

To setup a streaming video web camera to a specific IP address, you can use ffmpeg directly to perform this operation. You don't need to setup any additional software on the Blackfin Side. You can use broadcast addresses as well as direct udp IP connections. On the far side we use vlc to display the MPEG2 stream.


modprobe i2c-bfin-twi
modprobe vs6624
modprobe bfin_video_capture

ffmpeg -f video4linux2 -s 320x240 -pix_fmt uyvy422 -r 25 -i /dev/video0 
-qscale 6 -vcodec mpeg2video -f mpeg2video udp://$PCIP:1234


VLC->Media->Open Network Stream->udp://@$PCIP:1234

When using VS6624 on BF609-ezkit, you need the expansion adapter card: In this use case the 609 board boot mode should switch to Parallel Flash boot, due to hardware PIN conflict with SPI boot at this moment, this restriction will be removed soon after upgrading the expansion card hardware.

Set SW1 on the expansion card to 1 ON 2 OFF for VS6624 test.

ADV7183 Example

  1. Setup the bf561-ezkit or bf533-ezkit
  2. Enable ffmpeg

For the bf561-ezkit use the default configuration.

Connect a Composite Video Source to AVIN5


modprobe i2c-gpio
modprobe adv7183
modprobe bfin_video_capture

ffmpeg -f video4linux2 -s ntsc -pix_fmt uyvy422 -r 5 -i /dev/video0 
-f mjpeg udp://$PCIP:1234


VLC->Media->Open Network Stream->udp://@$PCIP:1234

ADV7842 Example

  • Put 720p output to ADV7842 HDMI port A, and use v4l2_video_capture to capture video file on BF609-EZKIT.
  • If you use the Linux source code after the 2014R1 release for Blackfin from the ADI GIT repository, you should config the soft switch gpios for the EI3 video encoder extender first. If you use the 2014R1 and older Linux releases for Blackfin, the driver takes care of this already.
    echo 150 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio150/direction
    echo 0 > /sys/class/gpio/gpio150/value
    echo 152 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio152/direction
    echo 0 > /sys/class/gpio/gpio152/value
  • Generated yuv file can be played by raw sequence file player, for example pYUV. Or it can be as the input of ADV7511. PYUV must be config as shown below:
    Resolution -> HD720
    Color space -> YCbCr
    Subsampling -> 4:2:2
    Ordering -> UYVY
    And select Interleaved option at the same time.
  • Bellow is the example:
    Linux version 3.3.0-ADI-2012R1-pre-dirty (test@linux87-bf609-std) (gcc version 4.3.5 (ADI-2012R1-RC2) ) #4 Thu Jul 19 00:19:39 CST 2012
    register early platform devices
    bootconsole [early_shadow0] enabled
    ERROR: Not running on ADSP-BF609: unknown CPUID 0x0000 Rev 0.0
    bootconsole [early_BFuart0] enabled
    early printk enabled on early_BFuart0
    Board Memory: 128MB
    Kernel Managed Memory: 128MB
    Memory map:
      fixedcode = 0x00000400-0x00000490
      text      = 0x00001000-0x001c9f50
      rodata    = 0x001c9f74-0x00267bac
      bss       = 0x00268000-0x0027b0e4
      data      = 0x0027b0e4-0x002a6000
        stack   = 0x002a4000-0x002a6000
      init      = 0x002a6000-0x0061f000
      available = 0x0061f000-0x06000000
      DMA Zone  = 0x06000000-0x08000000
    Hardware Trace active and enabled
    Blackfin support (C) 2004-2010 Analog Devices, Inc.
    Compiled for ADSP-BF609 Rev 0.0
    Blackfin Linux support by
    Processor Speed: 500 MHz core clock, 125 MHz SCLk, 125 MHz SCLK0, 125 MHz SCLK1 and 250 MHz DCLK
    NOMPU: setting up cplb tables
    Instruction Cache Enabled for CPU0
      External memory: cacheable in instruction cache
      L2 SRAM        : uncacheable in instruction cache
    Data Cache Enabled for CPU0
      External memory: cacheable (write-back) in data cache
      L2 SRAM        : uncacheable in data cache
    Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 24384
    Kernel command line: root=/dev/mtdblock0 rw ip= earlyprintk=serial,uart0,57600 console=ttyBF0,57600 ip=
    PID hash table entries: 512 (order: -1, 2048 bytes)
    Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
    Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
    Memory available: 91124k/131072k RAM, (3556k init code, 1827k kernel code, 881k data, 32768k dma, 916k reserved)
    Configuring Blackfin Priority Driven Interrupts
    Console: colour dummy device 80x25~Mconsole [ttyBF0] enabled, bootconsole disabled
    console [ttyBF0] enabled, bootconsole disabled
    Calibrating delay loop... 995.32 BogoMIPS (lpj=1990656)
    pid_max: default: 32768 minimum: 301
    Mount-cache hash table entries: 512
    Blackfin Scratchpad data SRAM: 4 KB
    Blackfin L1 Data A SRAM: 16 KB (9 KB free)
    Blackfin L1 Data B SRAM: 16 KB (16 KB free)
    Blackfin L1 Instruction SRAM: 64 KB (50 KB free)
    Blackfin L2 SRAM: 256 KB (256 KB free)
    NET: Registered protocol family 16
    gpiochip_add: registered GPIOs 0 to 111 on device: BFIN-GPIO
    Blackfin DMA Controller
    ezkit_init(): registering device resources
    ezkit_init(): request emac pins failed
    bio: create slab <bio-0> at 0
    SCSI subsystem initialized
    bfin-spi bfin-spi.0: bfin-spi probe success
    bfin-spi bfin-spi.1: bfin-spi probe success
    usbcore: registered new interface driver usbfs
    usbcore: registered new interface driver hub
    usbcore: registered new device driver usb
    i2c-bfin-twi i2c-bfin-twi.0: Blackfin on-chip I2C TWI Contoller, regs_base@ffc01e00
    i2c-bfin-twi i2c-bfin-twi.1: Blackfin on-chip I2C TWI Contoller, regs_base@ffc01f00
    NET: Registered protocol family 23
    Switching to clocksource bfin_cs_cycles
    musb-hdrc: version 6.0, ?dma?, otg (peripheral+host)
    NET: Registered protocol family 2
    IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
    TCP established hash table entries: 4096 (order: 3, 32768 bytes)
    TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
    TCP: Hash tables configured (established 4096 bind 4096)
    TCP reno registered
    UDP hash table entries: 256 (order: 0, 4096 bytes)
    UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
    NET: Registered protocol family 1
    msgmni has been set to 177
    io scheduler noop registered (default)
    bfin-uart: Blackfin serial driver
    bfin-uart.0: ttyBF0 at MMIO 0xffc02000 (irq = 96) is a BFIN-UART
    physmap platform flash device: 01000000 at b0000000
    physmap-flash.0: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x000089 Chip ID 0x008821
    Intel/Sharp Extended Query Table at 0x010A
    Intel/Sharp Extended Query Table at 0x010A
    Intel/Sharp Extended Query Table at 0x010A
    Intel/Sharp Extended Query Table at 0x010A
    Intel/Sharp Extended Query Table at 0x010A
    Using buffer write method
    Using auto-unlock on power-up/resume
    cfi_cmdset_0001: Erase suspend on write enabled
    Creating 3 MTD partitions on "physmap-flash.0":
    0x000000000000-0x000000080000 : "bootloader(nor)"
    0x000000080000-0x000000480000 : "linux kernel(nor)"
    0x000000480000-0x000001000000 : "file system(nor)"
    m25p80 spi0.4: unrecognized JEDEC id ffffff
    CAN device driver interface
    bfin_can bfin_can.0: bfin_can device registered(&reg_base=ffc00a00, rx_irq=55, tx_irq=56, err_irq=57, sclk=125000000)
     No HW DMA feature register supported
     Enhanced/Alternate descriptors
    Initializing USB Mass Storage driver...
    usbcore: registered new interface driver usb-storage
    USB Mass Storage support registered.
    input: bfin-rotary as /devices/platform/bfin-rotary/input/input0
    i2c /dev entries driver
    Linux media interface: v0.10
    lirc_dev: IR Remote Control driver registered, major 252
    IR NEC protocol handler initialized
    IR RC5(x) protocol handler initialized
    IR RC6 protocol handler initialized
    IR JVC protocol handler initialized
    IR Sony protocol handler initialized
    IR RC5 (streamzap) protocol handler initialized
    IR SANYO protocol handler initialized
    IR MCE Keyboard/mouse protocol handler initialized
    IR LIRC bridge handler initialized
    Linux video capture interface: v2.00
    ppi probe success
    bfin_capture bfin_capture.0: v4l2 device registered
    bfin_capture bfin_capture.0: video device registered as: video0
    adv7842 0-0020: error reading 20, ff
    adv7842 0-0020: select_input: SDP todo
    adv7842 0-0020: R 0, G 0, B 0
    adv7842 0-0020: Y 10, U 80, V 80
    adv7842 0-0020: adv7842 found @ 0x40 (i2c-bfin-twi)
    bfin_capture bfin_capture.0: v4l2 sub device registered
    adv7842 0-0020: select_input: SDP todo
    bfin-wdt: initialized: timeout=20 sec (nowayout=0)
    Blackfin hardware CRC crypto driver
    dma_alloc_init: dma_page @ 0x04afe000 - 8192 pages at 0x06000000
    bfin-hmac-crc bfin-hmac-crc.0: initialized
    usbcore: registered new interface driver usbhid
    usbhid: USB HID core driver
    TCP cubic registered
    NET: Registered protocol family 17
    can: controller area network core (rev 20090105 abi 8)
    NET: Registered protocol family 29
    eth0: device MAC address 00:e0:22:fe:88:1d
    stmmac: probed
    eth0: PHY ID 20005c90 at 1 IRQ 0 (stmmac-0:01) active
     No MAC Management Counters available
    IP-Config: Complete:
         device=eth0, addr=, mask=, gw=,
         host=bf609-ezkit, domain=, nis-domain=(none),
         bootserver=, rootserver=, rootpath=
    Freeing unused kernel memory: 3556k freed
    BusyBox v1.17.4 (2012-07-17 15:53:29 CST) hush - the humble shell
    root:/> echo 150 > /sys/class/gpio/export
    root:/> echo out > /sys/class/gpio/gpio150/direction
    root:/> echo 0 > /sys/class/gpio/gpio150/value
    root:/> echo 152 > /sys/class/gpio/export
    root:/> echo out > /sys/class/gpio/gpio152/direction
    root:/> echo 0 > /sys/class/gpio/gpio152/value
    root:/> v4l2_video_capture -I 4 -F /adv7842.yuv
    enum inputs
    input[0]: Composite
    input[1]: S-Video
    input[2]: Component
    input[3]: VGA
    input[4]: HDMI
    adv7842 0-0020: select_input: HDMI todo
    set input to 4: support dv_timings
    dv_timings: progressive,width=1280,height=720
    enum formats
    format[0]: YCbCr 4:2:2 Interleaved UYVY
    format[1]: YCbCr 4:2:2 Interleaved UYVY
    negotiated formats: 1280x720
    field order: progressive
    size = 1843200
    bytesperline = 2560
    pixelformat: UYVY
    frame rate setting is not supported
    request 3 buffers
    bufffer[0]: offset = 0, lengeth = 1843200
    bufffer[1]: offset = 1843200, lengeth = 1843200
    bufffer[2]: offset = 3686400, lengeth = 1843200
    stream on success
    open image file '/adv7842.yuv' success
    processing frame 0
    1 frames captured