cancel
Showing results for 
Search instead for 
Did you mean: 

DCMI: pixel clock issues

villanueva
Associate II
Posted on February 18, 2015 at 12:59

Hi Guys

I' trying to get an image with DCMI module. So, I set up the camera sensor for a square test pattern (a grid of 16 white pixels and 16 black pixels). I get the data with the DMA and the grid obteined was 2x16pixels (2 horizontal and 16 vertical). I'm lossing pixels... I verify the output of the camera and this send 16x16. I don't know where is the problem. 36MHz pixelclock, the datasheet says 54MHz maximum. 

Could someone help me to resolve my problem?. I'm using a STM32F429IG to 1.8V. I'm using the internal cristal. HCLCK = 168MHz.

Here is my configuration code. The main code is just an infinite loop.

void OVxxxx_HW_Init(void)

{

DCMI_InitTypeDef DCMI_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

DMA_InitTypeDef  DMA_InitStructure;

DCMI_CROPInitTypeDef DCMI_CROPInitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

  /*** Configures the DCMI GPIOs to interface with the OVxxxx camera module ***/

  /* Enable DCMI GPIOs clocks */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | 

                         RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOE |

RCC_AHB1Periph_GPIOH, ENABLE);

 /**DCMI GPIO Configuration  

  PE1   ------> DCMI_D3 -

  PE0   ------> DCMI_D2 -

  PB8   ------> DCMI_D6 -

  PC12   ------> DCMI_D9 -

  PE4   ------> DCMI_D4 -

  PE6   ------> DCMI_D7 -

  PB7   ------> DCMI_VSYNC -

  PB6   ------> DCMI_D5 -

  PC10   ------> DCMI_D8 -

  PA10   ------> DCMI_D1 -

  PA9   ------> DCMI_D0 -

  PH8   ------> DCMI_HSYNC -

  PA6   ------> DCMI_PIXCK -

  */

 /* Connect DCMI pins to AF13 */

GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_DCMI);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_DCMI);

GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_DCMI);

GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_DCMI);

GPIO_PinAFConfig(GPIOE, GPIO_PinSource4, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource6, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOH, GPIO_PinSource8, GPIO_AF_DCMI);

/* DCMI GPIO configuration */

  /*  */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9 | GPIO_Pin_10; // | GPIO_Pin_4; //STM32F407: On ajoute PA4 pour HSYNC

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

/* */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

/*  */

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10 | GPIO_Pin_12;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

/*  */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_6;

  GPIO_Init(GPIOE, &GPIO_InitStructure);

//  /* HSYNC */ //STM32F429IG

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

  GPIO_Init(GPIOH, &GPIO_InitStructure);

/***************************/

 /*** Configures the DCMI to interface with the OVxxxx camera module ***/

  /* Enable DCMI clock */

  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);

  /* DCMI configuration */ 

  DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_SnapShot; 

  DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;

  DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Rising;

  DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High; 

  DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_Low; 

  DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;

  DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_10b; 

DCMI_Init(&DCMI_InitStructure);

DCMI_CROPInitStructure.DCMI_VerticalStartLine = 0; //

  DCMI_CROPInitStructure.DCMI_HorizontalOffsetCount = 0; //

  DCMI_CROPInitStructure.DCMI_VerticalLineCount = 127; //

  DCMI_CROPInitStructure.DCMI_CaptureCount = 31; //

  DCMI_CROPConfig(&DCMI_CROPInitStructure);  

DCMI_CROPCmd(ENABLE);

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  

  NVIC_Init(&NVIC_InitStructure);

//--------------------------------------------------------

  /* Configures the DMA2 to transfer Data from DCMI */

  /* Enable DMA2 clock */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);

  

  /* DMA2 Stream1 Configuration */

  DMA_DeInit(DMA2_Stream1);

  DMA_InitStructure.DMA_Channel = DMA_Channel_1;  

  DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS;

  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&y; 

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;

  DMA_InitStructure.DMA_BufferSize = 2048; 

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;  //

  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //

  DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;

  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; //

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; //

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; //

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; //

  DMA_Init(DMA2_Stream1, &DMA_InitStructure);

}

 

#dcmi #dma #stm32f429 #pixclk
5 REPLIES 5
stm322399
Senior
Posted on February 18, 2015 at 18:49

Hard to say where the problem lies. Find a list of question/recommendation that can help to nail down the problem.

* Try to insert in your infinite loop a test of DMA status to check for errors, I suspect that the FIFO overrun.

* Where is the image buffer (y) ? SRAM ? DRAM ?

* Explain how 16x16 pixels need 2048 bytes of memory to be stored. In RGB I would have bet you only need 1536 bytes (3*2*16*16)

* Try to set DMA_FIFOThreshold to DMA_FIFOThreshold_1QuarterFull

* make a test without CROP

* What are you doing with the DCMI interrupt ?

--

Laurent

villanueva
Associate II
Posted on February 19, 2015 at 11:54

Thanks for answering

* Try to insert in your infinite loop a test of DMA status to check for errors, I suspect that the FIFO overrun.

I will

* Where is the image buffer (y) ? SRAM ? DRAM ?

SRAM (0x2000005C)

* Explain how 16x16 pixels need 2048 bytes of memory to be stored. In RGB I would have bet you only need 1536 bytes (3*2*16*16)

The test is a square grid of 16 pixels on 0x03FF and 16 pixels on 0x0000

10bits is stored in 2bytes (16bits), the image crop is 32x128, the memory data size was half word.

BufferSize = row*column*bytesparpixels/4 = 2048

In code, Memory data size is word, that was by test.

* Try to set DMA_FIFOThreshold to DMA_FIFOThreshold_1QuarterFull

I did it. same result

* make a test without CROP

    It is the same result

* What are you doing with the DCMI interrupt ?

I was conting the number of lines, that was correct and I deleted these lines of code

villanueva
Associate II
Posted on February 19, 2015 at 15:05

I coded an interruption for each posible error and for FIFO Mode Transfer Error, there is an interruption each 13us.

stm322399
Senior
Posted on February 20, 2015 at 19:44

Sorry I can't get a word of your test pattern.

Let's go back to basic. Your sensor generate W pixels per row, issue HSYNC between rows. It also generates H row per frame and separate frame with VSYNC.

* How many bytes per row (between HSYNC): W (single 10-bit data per pixel) or more (eg. 3*W for 10-bit RGB) ?

* How many row (H) ?

* Can you slow down the pixel clock ?

Please forgive about crop. Keep DMA threshold at 1 quarter full.

villanueva
Associate II
Posted on February 23, 2015 at 15:34

The camera sensor is a bayer arrangement GB/RG. Each element (pixel) has 10bits. I set up the camera for sending 64*128 pixels. It means, we have rows and each row has  64 pixels. I'm cropping this image to 32*128pixels with STM32F4 (W =32, H=128).

The test patter is a 16x16pixels on 0x03FF and 16x16 on 0x0000

Slowing down the clock to 24MHz, I got a grid of 16x5, so it was better.

The solution was found with RCC configuration. The STM32 was runing a 16MHz instead of 168MHz. I fix this error and the test grid was perfect. A grid of 16x16 pixels.

Thank you Laurent