Skip to main content
Junaid
Associate II
February 13, 2020
Question

STM32F4 Discovery - DCMI does not call HAL_DCMI_FrameEventCallback Camera : ov9655 I am using CubeMX to generate the code

  • February 13, 2020
  • 16 replies
  • 4452 views

Hello There,

I am trying to connect OV9655 camera (WaveShare) module with STm32f4 discovery board. After generating files from CubeMX and importing ov9655 drivers (ov9655.h & ov9655.c) I am able to get HAL_DCMI_LineEventCallback and HAL_DCMI_VsyncEventCallback event but not able to get HAL_DCMI_FrameEventCallback.

I am using Snapshot mode

 BSP_CAMERA_Init(RESOLUTION_R320x240);

 HAL_Delay(1000);

HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)CAMERA_FRAME_BUFFER, GetSize((uint8_t *)RESOLUTION_R320x240));

Please suggest where I am making mistake. Also please let me if any further info needed.

DMA Initialization

/** 

 * Enable DMA controller clock

 */

static void MX_DMA_Init(void) 

{

 /* DMA controller clock enable */

 __HAL_RCC_DMA2_CLK_ENABLE();

 /* DMA interrupt init */

 /* DMA2_Stream1_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0);

 HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);

}

/**

 * @brief DCMI Initialization Function

 * @param None

 * @retval None

 */

static void MX_DCMI_Init(void)

{

 /* USER CODE BEGIN DCMI_Init 0 */

 /* USER CODE END DCMI_Init 0 */

 /* USER CODE BEGIN DCMI_Init 1 */

 /* USER CODE END DCMI_Init 1 */

 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_8B;

 hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;

 if (HAL_DCMI_Init(&hdcmi) != HAL_OK)

 {

  Error_Handler();

 }

This topic has been closed for replies.

16 replies

oleksandr.karbivsky
Senior II
February 13, 2020

Hi. You must initialize DMA before calling HAL_DCMI_Start_DMA. Because HAL_DCMI_FrameEventCallback rise by setting DCMI_IT_FRAME bit. (from function DCMI_DMAXferCplt, file stm32f4xx_hal_dcmi.c). Check example for STM324xG_EVAL in your local CubeMX repository.

Junaid
JunaidAuthor
Associate II
February 13, 2020

Thank you very much for your reply. I have already did so. Please check the full main function :

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

  

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 //MaxInitDMA1();

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_I2C1_Init();

 MX_USART1_UART_Init();

 MX_CRC_Init();

 MX_DCMI_Init();

 /* USER CODE BEGIN 2 */

 BSP_CAMERA_Init(RESOLUTION_R320x240);

 HAL_Delay(1000);

 HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)CAMERA_FRAME_BUFFER, GetSize((uint8_t *)RESOLUTION_R320x240));

 //HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, frame_buffer, GetSize((uint8_t *)CAMERA_R160x120));

  

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 //HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)CAMERA_FRAME_BUFFER, GetSize((uint8_t *)CAMERA_R160x120));

 }

 /* USER CODE END 3 */

}

oleksandr.karbivsky
Senior II
February 13, 2020

Did you properly initialize DMA for DCMI data fetching? Share you CubeMX file.

Junaid
JunaidAuthor
Associate II
February 13, 2020
oleksandr.karbivsky
Senior II
February 13, 2020

Configuration for DMA from STM32F4xG_Eval Example for DCMI Snapshot Mode

 /*** Configure the DMA streams ***/

 /* Configure the DMA handler for Transmission process */

 hdma.Init.Channel       = DMA_CHANNEL_1;

 hdma.Init.Direction      = DMA_PERIPH_TO_MEMORY;

 hdma.Init.PeriphInc      = DMA_PINC_DISABLE;

 hdma.Init.MemInc       = DMA_MINC_ENABLE;

 hdma.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;

 hdma.Init.MemDataAlignment  = DMA_MDATAALIGN_WORD;

 hdma.Init.Mode        = DMA_CIRCULAR;

 hdma.Init.Priority      = DMA_PRIORITY_HIGH;

 hdma.Init.FIFOMode      = DMA_FIFOMODE_DISABLE;     

 hdma.Init.FIFOThreshold    = DMA_FIFO_THRESHOLD_FULL;

 hdma.Init.MemBurst      = DMA_MBURST_SINGLE;

 hdma.Init.PeriphBurst     = DMA_PBURST_SINGLE; 

 hdma.Instance = DMA2_Stream1;

DMA Mode is CIRCULAR.

Junaid
JunaidAuthor
Associate II
February 13, 2020

Thanks. I will change the setting from Normal to Circular & test. Will revert with results. Thanks for your prompt responses.

oleksandr.karbivsky
Senior II
February 13, 2020

Refer to this document Digital camera interface (DCMI) for STM32 MCUs 

"In snapshot mode: the DMA must ensure the transfer of one frame (image) from the DCMI to the desired memory:

– If the image size in words does not exceed 65535, the stream can be configured in normal mode. For more detailed description of this mode, refer to Section 4.4.6: Normal mode for low resolution in snapshot capture"

So it must works in normal mode. Maybe problem with CAMERA_FRAME_BUFFER location. Where you place it?

Junaid
JunaidAuthor
Associate II
February 13, 2020

Memory location : 0x64000000

oleksandr.karbivsky
Senior II
February 13, 2020

This address mapped to external NOR/PSRAM. You didn`t initialize SRAM in your main.

Junaid
JunaidAuthor
Associate II
February 13, 2020

I do not have any external RAM. Would you please suggest what should be the correct Memory location ? During my experiment I also tried with 0x50050028. But with that also there was no difference. Please suggest.