DCMI configuration
The DCMI configuration allows the user to select the capture mode, the data format, the image size, and the resolution.
The DCMI configuration allows the user to select the capture mode, the data format, the image size, and the resolution.
The received data in snapshot or continuous grab mode is transferred to the memory frame buffer by the DMA. The buffer location and mode (linear or circular buffer) are controlled through the system DMA.
The DCMI allows the reception of compressed data (JPEG) or many uncompressed data formats (such as monochrome, RGB, or YCbCr). For more details, refer to Data formats and storage.
The DCMI allows the reception of a wide range of resolutions (low, medium, high) and image sizes, since the image size depends on the image resolution and data format. The DMA ensures the transfer and the placement of the received images in the memory frame buffer.
Optionally, the user can configure the byte, line, and frame select mode to modify the image resolution and size, and in some cases, the data format (see Image resizing (resolution modification)). The user can also configure and enable the crop feature to select a rectangular window from the received image (see Crop feature).
The DCMI configuration registers must be programmed correctly before enabling the ENABLE bit in DCMI_CR. The DMA controller and all DCMI configuration registers must be programmed correctly before enabling the CAPTURE bit in DCMI_CR.
The DMA configuration is a crucial step to ensure the success of the application.
As mentioned in DCMI in a smart architecture, the DMA2 ensures the transfer from the DCMI to the memory (internal SRAM or external SRAM/SDRAM) for all STM32 devices embedding the DCMI.
For the STM32H7 and SMT32L4+ devices, the DMA1 can also access the AHB2 peripherals and ensures the transfer of the received data from the DCMI to the memory frame buffer.
For the STM32U5 and STM32N647/657 devices, the GPDMA1 ensures the transfer from the DCMI to the memory.
For the STM32H5 devices, the GPDMA1 and the GPDMA2 ensure the transfer from the DCMI to the memory.
To ensure the data transfer from the DCMI data register, the DMA waits for the request to be generated from the DCMI. The relevant stream and channel must be configured. For more details, refer to DCMI channel and stream configuration.
For more details on the DMA internal FIFO, refer to FIFO and burst transfer configuration.

The user must also configure the corresponding DMA2 (or the DMA1 for the STM32H7 and STM32L4+ devices, the GPDMA1 for the STM32U5 and STM32N647/657 devices, the GPDMA1 and GPDMA2 for the STM32H5 devices) stream and channel to ensure the DMA acknowledgment each time the DCMI data register is fulfilled.
| STM32 | DMA stream | Channel |
|---|---|---|
| STM32F2 | Stream 1 and stream 7 | Channel 1 |
| STM32F4 | ||
| STM32F7 | ||
| STM32H7 | Stream 0 to stream 7 | Multiplexer 1 request 75 |
| STM32L4 | Stream 0 | Channel 6 |
| Stream 4 | Channel 5 |
| STM32 | DMA channel | Request | |
|---|---|---|---|
| STM32L4+ | STM32L4Rxxx and STM32L4Sxxx | Channel 1 to channel 7 | DMA request multiplexer 90 |
| STM32L4P5xx and STM32L4Q5xx | DMA request multiplexer 91 | ||
| STM32U5 | Channel 0 to channel 15 | GPDMA1 request 86 | |
| STM32H5 | Channel 0 to channel 7 | GPDMA1/2 request 108 | |
| STM32N647/657 | Channel 0 to channel 15 | GPDMA1 request 140 | |
See the reference manual for a step-by-step description of the stream and channel configuration procedure.
The total number of words to transfer from the DCMI to the memory is programmed in this register (see DMA configuration for DCMI-to-memory transfers).
When the DMA starts the transfer from the DCMI to the memory, the number of items decreases from the initial programmed value until the end of the transfer (reaching zero or disabling the stream by software before the number of data remaining reaches zero).
| Programmed value in the register | Peripheral size | Number of bytes |
|---|---|---|
| 65535 | Words | 262140 |
| 0 < N < 35535 | 4 * N |
To avoid data corruption, this programmed value must be a multiple of MSIZE or PSIZE.
For a better performance, it is recommended to use the FIFO. When the FIFO mode is enabled, the user can configure the MBURST bits to make the DMA perform burst transfer (up to four words) from its internal FIFO to the destination memory, which guarantees better performance.
Low-resolution images are the ones having size (in 32-bit word) less than 65535. In snapshot mode, the normal mode can be used to ensure the transfer of low-resolution frames (see Table 10 Maximum number of bytes transferred during one DMA transfer).
| Item | Max number of bytes | Bit depth (byte/pixel) | Max number of pixels | Max resolution |
|---|---|---|---|---|
| Word | 262140 | 1 | 262140 | 720x364 |
| 2 | 131070 | 480x272 |
Each time the number of data decrementing reaches the zero, the number of data words is automatically reloaded to the initial value. Each time the DMA pointer reaches the end of the frame buffer, it is reinitialized, and the DMA ensures the transfer of the next frame.
The resolutions listed in Table 11 Maximum image resolution in normal mode are also valid for the low resolution in continuous mode.

This mode is not available for STM32L4A6xx and STM32L496xx devices.
Medium resolution images are the ones with a size (in 32-bit words) between 65536 and 131070. When the double-buffer mode is enabled, the circular mode is automatically enabled.
| Item | Max number of bytes | Bit depth (byte/pixel) | programmed value in the register | Number of pixels | Max resolution |
|---|---|---|---|---|---|
| Word | 524280 | 1 | 65535 | 524280 | 960x544 |
| 0 < N < 65535 | 8 * N | ||||
| 2 | 65535 | 262140 | 720x364 | ||
| 0 < N < 65535 | 4 * N |

When the number of words in one frame (image) in snapshot or continuous mode exceeds 131070, and when the image resolution exceeds the indicated ones in Table 12 Maximum image resolution in double-buffer mode, the DMA double-buffer mode cannot ensure the transfer of the received data.
This section highlights only the DMA operation in case of high resolution. An example is developed and described using this DMA configuration in Resolution capture (YCbCr data format).
To avoid any error condition, it is advised to change the programmed address as soon as the TCIF flag is asserted. At this point, the targeted memory must have changed from memory 0 to memory 1 (or from 1 to 0), depending on the CT bit value in DMA_SxCR.
For all the other modes than the double-buffer one, the memory address registers are write-protected as soon as the stream is enabled.
DMA_SxM0AR and DMA_SxM1AR can then be used to address many buffers, ensuring the transfer of high resolution images.
To simplify the use of this specific feature, it is recommended to divide the image into equal buffers. When capturing high resolution images, the user must secure that the memory destination has a sufficient size.
Example: In case of a resolution that is 1280x1024, the image size is 655360 words (32 bits). This size must be divided into equal buffers, with a maximum size of 65535 for each of them. To be correctly received, the image must then be divided into 16 frame buffers, with each frame buffer size equal to 40960 (lower than 65535).
