cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F767 DCMI DMA image data mis-aligned

HWang.9
Associate

Hi,

I am working on a project using STM32F767 to collect image data from a MT9p031 sensor. The camera runs in snapshot mode, image data is stored in external SDRAM (bank2, address from 0xd0000000). After image is collected I send the image data through USB VCP to PC.

When I test the image data with sensor's internal test pattern, I see the collected image is in a strange misaligned way. the image seems scrolled over both horizontally and vertically.

I am using stm32CubeMX to generate MCU config.

The image size I am testing with is quite big so DMA is working in double buffer mode. in cubeMX the DCMI DMA fifo is enabled. below is DCMI init config:

  hdcmi.Instance = DCMI;
  hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
  hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;
  hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;
  hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;
  hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
  hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_12B;
  hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
  hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL;
  hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD;
  hdcmi.Init.LineSelectMode = DCMI_LSM_ALL;
  hdcmi.Init.LineSelectStart = DCMI_OELS_ODD;
 
    /* DCMI DMA Init */
    /* DCMI Init */
    hdma_dcmi.Instance = DMA2_Stream1;
    hdma_dcmi.Init.Channel = DMA_CHANNEL_1;
    hdma_dcmi.Init.Direction = DMA_PERIPH_TO_MEMORY;
    hdma_dcmi.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_dcmi.Init.MemInc = DMA_MINC_ENABLE;
    hdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    hdma_dcmi.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    hdma_dcmi.Init.Mode = DMA_NORMAL;
    hdma_dcmi.Init.Priority = DMA_PRIORITY_HIGH;
    hdma_dcmi.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
    hdma_dcmi.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
    hdma_dcmi.Init.MemBurst = DMA_MBURST_INC4;
    hdma_dcmi.Init.PeriphBurst = DMA_PBURST_SINGLE;

and I am using HAL functions to start DMA like below:

void IMAGE_Capture(uint16_t *addr)
{
	uint32_t wd_size = IMAGE_Get_WordSize(image_roi_width, image_roi_height);
	HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)addr, wd_size);
	CAMERA_Shoot(image_exp_time_100us);
 
	while(!DCMICompleteFlg){}
	DCMICompleteFlg = 0;
}

After quite many different tests it seems to me that DMA is not storing the DCMI received data in right address. the circulation scheme has got some order incorrectly. But I do not have to much idea on further debugging / correct this issue.

Could anyone suggest me what the problem is? Thank a lot

hw

2 REPLIES 2
JFerr.4
Associate

Hi,

I'm also working on a project with the MT9P031 sensor but with an STM32H743.

It seems that the configuration of the DMA and DCMI is appropriate. What you said about the image moving both horizontally and vertically might be that the width and height are not writing it well.

One of the problems I had was that the STM32s are little-endian, when I sent a 16 bit message over the I2C bus, it sent the bytes in the opposite order. To fix this I use the CMSIS __REV16 function. Have you checked it?

Regards.

qbaj
Associate II

Do you have align for buffer to use DMA?

ALIGN_32BYTES(uint8_t dcmi_capture_buffer[DCMI_CAPTURE_BUFFER_SIZE]) __attribute__((section(".SDRAM")));