AN5020 · Application noteIntroduction to digital camera interface (DCMI) for STM32 MCUs
Download .pdfOpen in the full document

DCMI description

Hardware interface

The DCMI consists of:
  • Up to 14 data lines (D13-D0)
  • The pixel clock line DCMI_PIXCLK
  • The DCMI_HSYNC line (horizontal synchronization)
  • The DCMI_VSYNC line (vertical synchronization).

The DCMI comprises up to 17 inputs. Depending on the number of data lines enabled by the user (8, 10, 12, or 14), the number of the DCMI inputs varies (11, 13, 15, or 17 signals).

If less than 14-bit data width is used, the unused pins must not be assigned to the DCMI through GPIO alternate functions. The unused input pins can be assigned to other peripherals.

In the case of embedded synchronization, the DCMI needs only nine inputs (eight data lines and DCMI_PIXCLK) to operate properly. The eight unused pins can be used for GPIO or other functions.

Figure 16 DCMI signals shows the DCMI signals.
Figure 16. DCMI signals

If x-bit data width is chosen (x data lines are enabled, x = 8, 10, 12, or 14), x bits of image (or video) data are transferred each DCMI_PIXCLK cycle, and packed into a 32-bit register.

Figure 17 DCMI block diagram: example of 12-bit data width shows the four main DCMI components.
Figure 17. DCMI block diagram: example of 12-bit data width


  • The DCMI synchronizer ensures the control of the ordered sequencing of the data flow through the DCMI. It controls the data extractor, the FIFO, and the 32-bit register.
  • The data extractor ensures the extraction of the data received by the DCMI.
  • The 4-word FIFO is implemented to adapt the data rate transfers to the AHB. There is no overrun protection to prevent data from being overwritten if the AHB does not sustain the data transfer rate. In case of overrun or errors in the synchronization signals, the FIFO is reset, and the DCMI waits for a new start of frame.
  • A 32-bit data register where the data bits are packed for transfer through a general-purpose DMA channel. The placement of the captured data in the 32-bit register depends on the data width:
    • For an 8-bit data width, the DCMI captures the eight LSBs (the six other inputs D[13:8] are ignored). The first captured data byte is placed in the LSB position in the 32-bit word, and the fourth captured data byte is placed in the MSB position. In this case, a 32-bit data word is made up every four pixel clock cycles. For more details, see Data formats and storage.
      Figure 18. Data register filled for 8-bit data width
    • For a 10-bit data width, the DCMI captures the 10 LSBs (the four other inputs D[13:10] are ignored). The first 10 bits captured are placed as the 10 LSBs of a 16-bit word. The remaining MSBs in the 16-bit word of the DCMI_DR register (bits 10 to 15) are cleared. In this case, a 32-bit data word is made up every two pixel clock cycles.
      Figure 19. Data register filled for 10-bit data width
    • For a 12-bit data width, the DCMI captures the 12-bit LSBs (the two other inputs D[13:12] are ignored). The first 12 bits captured are placed as the 12 LSBs of a 16-bit word. The remaining MSBs in the 16-bit word of the DCMI_DR register (bits 12 to 15) are cleared. In this case, a 32-bit data word is made up every two pixel clock cycles.
      Figure 20. Data register filled for 12-bit data width
    • For a 14-bit data width, the DCMI captures all the received bits. The first 14 bits captured are placed as the 14 LSBs of a 16-bit word. The remaining MSBs in the 16-bit word of the DCMI_DR register (bits 14 and 15) are cleared. In this case, a 32-bit data word is made up every two pixel clock cycles.
      Figure 21. Data register filled for 14-bit data width

Camera module and DCMI interconnection

As mentioned in Camera module interconnect (parallel interface), the camera module is connected to the DCMI through the following signal types:
  • DCMI clock and data signals
  • I2C configuration signals
Figure 22. STM32 MCU and camera module interconnection

DCMI functional description

The following steps summarize the internal DCMI component operation, and give an example of data flow through the system bus matrix:
  1. After receiving the different signals, the synchronizer controls the data flow through the different DCMI components (data extractor, FIFO, and 32-bit data register).
  2. Being extracted by the extractor, data are packed in the 4-word FIFO, then ordered in the 32-bit register.
  3. Once the 32-bit data block is packed in the register, a DMA request is generated.
  4. The DMA transfers the data to the corresponding memory destination.
  5. Depending on the application, data stored in the memory can be processed differently.
Note:

It is assumed that all image preprocessing is performed in the camera module.

Data synchronization

The camera interface has a configurable parallel data interface from 8 to 14 data lines, together with:
  • A pixel clock line, DCMI_PIXCLK (rising/falling edge configuration)
  • A horizontal synchronization line, DCMI_HSYNC
  • A vertical synchronization line, DCMI_VSYNC, with a programmable polarity

The DCMI_PIXCLK and AHB clocks must respect the minimum ratio AHB/DCMI_PIXCLK of 2.5.

Some camera modules support the two types of synchronization, while others support either the hardware or the embedded synchronization.

Hardware (or external) synchronization

In this mode, the DCMI_VSYNC and DCMI_HSYNC signals are used for the synchronization:
  • The line synchronization is always referred to as DCMI_HSYNC (also known as LINE VALID).
  • The frame synchronization is always referred to as DCMI_VSYNC (also known as FRAME VALID).

The polarities of the DCMI_PIXCLK and the synchronization signals (DCMI_HSYNC and DCMI_VSYNC) are programmable.

Data are synchronized with DCMI_PIXCLK, and change on the rising or falling edge of the pixel clock, depending on the configured polarity.

If the DCMI_VSYNC and DCMI_HSYNC signals are programmed active level (active high or active low), the data is not valid in the parallel interface when VSYNC or HSYNC is at that level (high or low).

For example, if VSYNC is programmed active high:
  • When VSYNC is low, the data is valid.
  • When VSYNC is high, the data is not valid (vertical blanking).

The DCMI_HSYNC and DCMI_VSYNC signals act like blanking signals, since all data received during DCMI_HSYNC/DCMI_VSYNC active periods are ignored.

Figure 23 Frame structure in hardware synchronization mode shows an example of data transfer when DCMI_VSYNC and DCMI_HSYNC are active high, and when the capture edge for DCMI_PIXCLK is the rising edge.
Figure 23. Frame structure in hardware synchronization mode

Compressed data synchronization

For compressed data (JPEG), the DCMI supports only the hardware synchronization. Each JPEG stream is divided into packets, which have programmable size. The packets dispatching depends on the image content, and results in a variable blanking duration between two packets.

DCMI_HSYNC is used to signal the start/end of a packet. DCMI_VSYNC is used to signal the start/end of the stream.

If the full data stream finishes and the detection of an end-of-stream does not occur (DCMI_VSYNC does not change), the DCMI pads out the end-of-frame by inserting zeros.

Embedded (or internal) synchronization

In this case, delimiter codes are used for synchronization. These codes are embedded within the data flow to indicate the start/end of line or the start/end of frame.

Note:

These codes are supported only for 8-bit parallel data interface width. For other data widths, this mode generates unpredictable results, and must not be used.

The codes eliminate the need for DCMI_HSYNC and DCMI_VSYNC to signal the end/start of the line or the frame. When this synchronization mode is used, there are two values that must not be used for data: 0 and 255 (0x00 and 0xFF). These two values are reserved for data identification purposes. It is up to the camera module to control the data values. Image data can then have only 254 possible values (0x00 < image data value < 0xFF).

Each synchronization code consists of 4-byte sequence 0xFF 00 00 XY (as shown in Figure 24 Embedded code bytes), where all delimiter codes have the same first 3-byte sequence 0xFF 00 00. Only the final one 0xXY is programmed to indicate the corresponding event.
Figure 24. Embedded code bytes
Mode 1

This mode is ITU656 compatible (ITU656 is the digital video protocol ITU-R BT.656).

The following reference codes indicate a set of four events:
  • SAV (active line): line-start
  • EAV (active line): line-end
  • SAV (blanking): line-start during inter-frame blanking period
  • EAV (blanking): line-end during inter-frame blanking period
Figure 25 Frame structure in embedded synchronization mode 1 illustrates the frame structure using this mode.
Figure 25. Frame structure in embedded synchronization mode 1


Mode 2
The embedded synchronization codes signal another set of events:
  • Frame-start (FS)
  • Frame-end (FE)
  • Line-start (LS)
  • Line-end (LE)

A 0xFF value programmed as a frame-end (FE) means that all the unused codes (the possible values of codes other than FS, LS, LE) are interpreted as valid FE codes.

In this mode, once the camera interface has been enabled, the frame capture starts after the first occurrence of an FE code followed by an FS code.

Figure 26 Frame structure in embedded synchronization mode 2 illustrates the frame structure when using this mode.
Figure 26. Frame structure in embedded synchronization mode 2


Note:

The camera modules can have up to eight synchronization codes in interleaved mode. This mode is then not supported by the camera interface (otherwise, every other half frame is discarded). When using the embedded synchronization mode, the DCMI does not support the compressed data (JPEG) and the crop feature.

Embedded unmask codes

These codes are also used to signal start/end of a line or a frame. Thanks to these codes, instead of comparing all the received code with the programmed one to set the corresponding event, the user can select only some unmasked bits to compare with the bits of the programmed code having the same position.

The user applies a mask to the corresponding code by configuring the DCMI embedded synchronization unmask register (DCMI_ESUR). Each byte in this register is an unmask code, corresponding to an embedded synchronization code:
  • The most significant byte is the frame-end delimiter unmask (FEU): each bit set to 1 implies that this bit, in the frame-end-code, must be compared with the received data to know if it is a frame-end event or not.
  • The second byte is the line-end delimiter unmask (LEU): each bit set to 1 implies that this bit, in the line-end-code, must be compared with the received data to know if it is a line-end event or not.
  • The third byte is the line-start delimiter unmask (LSU): each bit set to 1 implies that this bit, in the line-start-code, must be compared with the received data to know if it is a line-start event or not.
  • The less significant byte is the frame-start delimiter unmask (FSU): each bit set to 1 implies that this bit, in the frame-start-code, must be compared with the received data to know if it is a frame-start event or not.

There can be different codes for each event (line-start, line-end, frame-start, or frame-end) but all of them (the different codes corresponding to one event) have the unmasked bits in the same position (same unmask code).

Example: FSC = 0xA5 and unmask code FSU = 0x10 (as shown in Figure 27 Embedded code unmasking). In this case the frame-start information is embedded in the bit number 4 of the FS code. The user must compare only the bit number 4 of the received code with the bit number 4 of the programmed code, to know if it is a frame-start event or not.
Figure 27. Embedded code unmasking
Note:

Make sure that each synchronization code has different unmask code to avoid synchronization errors.