AN6211 · Application noteIntroduction to digital camera interface pixel pipeline for STM32 MCUs
Download .pdfOpen in the full document

DCMIPP examples based on STM32CubeMX

DCMIPP examples based on STM32CubeMX

This section provides detailed examples of typical DCMIPP configuration, focusing on capturing and displaying RGB data. It demonstrates how to configure the camera in continuous mode with a resolution of 480 x 272, using the STM32H7S78-DK board from STMicroelectronics connected to the 5-megapixel OV5640 camera sensor.

The DCMIPP Pipe0 is configured for RGB565, with swap cycles enabled, framerate set to DCMIPP_FRAME_RATE_ALL, and hardware synchronization enabled. All frames are stored in the camera framebuffer, and the LTDC is configured to continuously display these captured frames from the camera framebuffer.

As illustrated in Figure 43 Data path in capture and display application, the application consists of two main steps:
  1. DCMIPP dumps to a single RGB buffer. It has a single pipe (Pipe0) active, where all the AXI capabilities are focused on the single active pipe, which gets all the FIFO space. With this setting, a camera dump of 200 Mpixel/s peak on 32 bpp (800 MB/s bandwidth) benefits from 5 Kbytes FIFO.
  2. Import data from the external memory to be displayed on the LCD-TFT, only for RGB data format. For YCbCr or JPEG data format, the user must convert the received data to RGB to be displayed.
Figure 43. Data path in capture and display application

Hardware description

The example uses the STM32H7S78-DK board from STMicroelectronics, connecting to the 5 megapixel OV5640 camera sensor, as illustrated in Figure 44 Camera connector on STM32H7S78-DK.

The camera module with a resolution of 480x272 is connected to the STM32H7S78-DK board through the following signals.

The configuration of this example can be done by following the steps described in Configuration of common examples.

This camera module is interfaced with the DCMIPP:

  • Control signals: DCMIPP_PIXCLK, DCMIPP_VSYNC, DCMIPP_HSYNC
  • Image data signals: DCMIPP_D[0..7]
Figure 44. Camera connector on STM32H7S78-DK

For more details on the STM32H7S78-DK board, refer to the document AN6211_general-information.html#AN6211general_information__ref_8 available on the STMicroelectronics website.

Configuration of common examples

When starting with STM32CubeMX, the first step is to configure the project location and the corresponding toolchain or IDE (menu Project/Settings).

STM32CubeMX - Configuration of DCMIPP GPIOs
DCMIPP GPIOs can be configured following these steps:
  1. Select the DCMIPP and choose “Slave 8 bits External Synchro” in the pinout and configuration multimedia tab to configure the DCMIPP in parallel slave 8-bit external synchronization. After this step, nine pins must be highlighted in green (D[0..7] , DCMIPP_VSYNC, DCMIPP_HSYNC and DCMIPP_PIXCLK).
    Figure 45. STM32CubeMX - DCMIPP synchronization mode selection


  2. Select the "Configuration tab" to configure the GPIOs mode.
  3. When the DCMIPP configuration window appears, select the GPIO Settings tab.
    Figure 46. STM32CubeMX - GPIO settings selection


  4. Select all the DCMIPP pins.
    Figure 47. STM32CubeMX - DCMIPP pin selection


  5. Set the GPIO pull-up/pull-down.
    Figure 48. STM32CubeMX - GPIO no pull-up and no pull-down selection


STM32CubeMX - Configuration of DCMIPP control signals and capture mode
  1. Click on Parameter Settings tab in DCMIPP Configuration window
    Figure 49. STM32CubeMX - DCMIPP control signals and capture mode
  2. Set the different parameters, including frame rate, pipe number, data format, synchronization configuration, and pixel clock polarities, according to the camera module configuration.
Note:

The vertical synchronization polarity must be active high, and the horizontal synchronization polarity must be active low. They must not be inverted for this configuration of the camera module.

STM32CubeMX - Enable DCMIPP interrupts
  1. Select NVIC Settings tab in DCMIPP Configuration window and check the DCMIPP global interrupt.
Figure 50. STM32CubeMX - Configuration of DCMIPP interrupts
STM32CubeMX - System clock configuration
In this example the system clock is configured as follows:
  • Use of internal HSI clock, where the main PLL is used as system source clock
  • HCLK at 300 MHz, so the Cortex-M7 running at 600 MHz
  1. Select the Clock Configuration tab.
    Figure 51. STM32CubeMX - HSI configuration
  2. Set the PLLs and the prescalers in the Clock Configuration tab, to get the system clock HCLK at 300 MHz.
Figure 52. STM32CubeMX - HCLK configuration


Adding files to the project
Generate the code and open the generated project using the preferred toolchain. Then follow these steps:
  • Copy ov5640.c from the Components folder to the Src folder.
  • Copy ov5640_reg.c from the Components folder to the Src folder.
  • Copy ov5640.h from the Components folder to the Inc folder.
Modifications in main.h file

Update main.h by inserting some instructions to include the needed files in the adequate space This task provides the project modification and regeneration without losing the user code:

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "camera.h"
#include "ov5640.h"
#include "string.h"
#include "stm32h7s78_discovery.h"
#include "stm32h7s78_discovery_bus.h"
/* USER CODE END Includes */

Some variable declarations must then be inserted in the adequate space:

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
#define FRAME_BUFFER_SIZE   (480*272*2 / 4)
#define CAMERA_OV5640_ADDRESS 0x78
/* USER CODE END EC */
Modifications in main.c file

Update main.c by inserting some instructions to include the needed variables:

/* USER CODE BEGIN PV */
static CAMERA_Drv_t *Camera_Drv = NULL;
uint32_t CAMERA_FRAME_BUFFER[FRAME_BUFFER_SIZE] __attribute__((aligned(16)));
uint32_t xpos = (800 - 480)/2;
uint32_t ypos = (480 - 272) /2;
uint32_t ImageWidth = 480;
uint32_t ImageHeight = 272;
/* USER CODE END PV */

The function prototypes must also be inserted in the adequate space:

/* USER CODE BEGIN PFP */
static uint32_t OV5640_Config(uint32_t Resolution, uint32_t PixelFormat);
/* USER CODE END PFP */
Update main() function by inserting some functions in the adequate space:
  • OV5640_Config allows the configuration of the camera module, the DCMI registers, and the DCMI parameters.
  • HAL_DCMIPP_PIPE_Start enables DCMIPP capture on Pipe0 by specifying the destination address and the continuous mode.
/* USER CODE BEGIN 2 */
/* Configure OV5640 camera Module */
if(OV5640_Config(OV5640_R480x272, OV5640_RGB565) != OV5640_OK)
{
/* Camera Module Config KO */
Error_Handler();
}
/* Start Camera w/ continuous Mode */
if(HAL_DCMIPP_PIPE_Start(&phdcmipp, DCMIPP_PIPE0, (uint32_t)CAMERA_FRAME_BUFFER , DCMIPP_MODE_CONTINUOUS) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END 2 */

Insert the implementation of the new functions (called in the main() function), out of the main function, in the adequate space:

static uint32_t OV5640_Config(uint32_t Resolution, uint32_t PixelFormat)
{
OV5640_IO_t IOCtx;
uint32_t id;
uint32_t ret = OV5640_OK;
static OV5640_Object_t OV5640Obj;

/* Configure the Camera driver */
IOCtx.Address = CAMERA_OV5640_ADDRESS;
IOCtx.Init = BSP_I2C1_Init;
IOCtx.DeInit = BSP_I2C1_DeInit;
IOCtx.ReadReg = BSP_I2C1_ReadReg16;
IOCtx.WriteReg = BSP_I2C1_WriteReg16;
IOCtx.GetTick = BSP_GetTick;

/* Register Bus IO */
If(OV5640_RegisterBusIO (&OV5640Obj, &IOCtx) != OV5640_OK)
{
ret = OV5640_ERROR;
}

/* Read ID */
if(OV5640_ReadID(&OV5640Obj, &id) != OV5640_OK)
{
ret = OV5640_ERROR;
}
if(id == OV5640_ID)
{

/* Initialize the camera Module */
Camera_Drv = (CAMERA_Drv_t *) &OV5640_CAMERA_Driver;

OV5640_DeInit(&OV5640Obj);
if(Camera_Drv->Init(&OV5640Obj, Resolution, PixelFormat) != OV5640_OK)
{
ret = OV5640_ERROR;
}
else if(Camera_Drv->MirrorFlipConfig(&OV5640Obj, OV5640_MIRROR_FLIP_NONE) != OV5640_OK)
{
ret = OV5640_ERROR;
}
}
return ret;
}
void HAL_DCMIPP_PIPE_FrameEventCallback(DCMIPP_HandleTypeDef *pHdcmipp, uint32_t Pipe)
{

/* Assert display enable LCD_DISP_EN pin */
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_15, GPIO_PIN_SET);
if(Pipe == DCMIPP_PIPE0)
{
BSP_LED_Toggle(LD1);
}
}
/* USER CODE END 4 */

At this stage, the user can build, debug, and run the project.

Note:

For LTDC configuration, the user can configure LTDC according to document AN6211_general-information.html#AN6211general_information__ref_9.

RGB data capture and display

To simplify this example, data are captured and displayed in RGB565 format (2 bpp). The image resolution is 480 x 272. The framebuffer is placed in the external flash. Camera and LCD data are in the same framebuffer. The LCD displays then directly the data captured through the DCMIPP without any processing. The camera module is configured to output RGB565 data, 480 x 272.

The configuration of this example can be done by following the steps described in Configuration of common examples.