cancel
Showing results for 
Search instead for 
Did you mean: 

STM32h743 and OV7670 with DCMI

MRoso.1
Associate II

Hi,

I know there are plenty of similar topics on here but most are unresolved and when they are resolved the OP never posts about it.

So I am creating code through STM32CubeIDE for DCMI with DMA (with help from here).

I'm using the NUCLEO board.

The OV7670 is properly connected to the controller and is outputting correct HREF, VSYNC and PCLK signals for QVGA and RG565. I've previously used this camera without DCMI and a different controller successfully so I am familiar with its signals.

D0-D7 are checked with an oscilloscope and are outputting data.

HAL_DCMI_Start_DMA returns no errors and the DMA1_Stream0_IRQHandler is firing regularly.

Whenever I disconnect either of the signal pins, HAL_DCMI_Start_DMA returns error.

The problem is that my buffer is never written and keeps the value 0 at all times.

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 */
  char hak[10];
  uint32_t Im_size = 0;
  uint8_t FRAME_BUFFER[320 * 240 * 2];
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ETH_Init();
  MX_USB_OTG_FS_PCD_Init();
  MX_DCMI_Init();
  MX_DMA_Init();
  MX_USART3_UART_Init();
 
  MX_TIM3_Init();
  MX_I2C2_Init();
  /* USER CODE BEGIN 2 */
  	HAL_Delay(1000);
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
    HAL_Delay(300);
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_RESET);
    HAL_Delay(100);
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_SET);
    HAL_Delay(300);
 
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
    HAL_Delay(500);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);
 
    HAL_Delay(500);
 
    if (OV_Config()) {
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
		HAL_Delay(1000);
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
		sprintf(hak, "ERROR\n");
		HAL_UART_Transmit(&huart3, (const uint8_t *)hak, strlen(hak), 10);
    }
    else {
		sprintf(hak, "OK\n");
		HAL_UART_Transmit(&huart3, (const uint8_t *)hak, strlen(hak), 10);
    }
    Im_size = 38400;
  	HAL_Delay(1000);
  	FRAME_BUFFER [0] = 0xFF;
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  sprintf(hak, "%d\n",   HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, FRAME_BUFFER, Im_size));
	  HAL_UART_Transmit(&huart3, (const uint8_t *)hak, strlen(hak), 10);
	  for (int i=0;i<10;i++) {
		  sprintf(hak, "%d\n", FRAME_BUFFER[i]);
		  HAL_UART_Transmit(&huart3, (const uint8_t *)hak, strlen(hak), 10);
	  }
	  HAL_Delay(2000);
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

I even switched places between MX_DCMI_Init(); and MX_DMA_Init(); as someone else had suggested but that did nothing.

Thanks

4 REPLIES 4
Imen.D
ST Employee

Hello @MRoso.1​ ,

Maybe the problem is related to : memory layout and internal data cache (D-Cache) of the Cortex-M7 core. So, Try disable D-Cache and I advise you to follow this FAQ: DMA is not working on STM32H7 devices

When your question is answered, please close this topic by choosing Select as Best.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hello @Imen DAHMEN​ ,

How do I do that?

Do I follow this from the article: GCC (Atollic TrueStudio/System Workbench for STM32/Eclipse) ?

I am using STM32IDE

thanks

Hi @MRoso.1​ ,

It maybe the issue is due to DMA_init order: MX_DMA_Init shall always be called before any other peripheral initialization.

MX_DMA_Init order in the main.c file generated by STM32CubeMX, How to fix?

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
MRoso.1
Associate II

Hi, @Imen DAHMEN​ 

I made the necessary changes in the STM32H743ZITX_RAM.ld file and the DCcache option in STM32CubeIDE was already disabled.

/* Initialized data sections goes into RAM, load LMA copy after code */
  .data :
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */
 
    . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
  } >RAM_D1 AT> FLASH
 
  /* Uninitialized data section */
  . = ALIGN(4);
  .bss :
  {
    /* This is used by the startup in order to initialize the .bss section */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)
 
    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
  } >RAM_D1
 
  /* User_heap_stack section, used to check that there is enough RAM left */
  ._user_heap_stack :
  {
    . = ALIGN(8);
    PROVIDE ( end = . );
    PROVIDE ( _end = . );
    . = . + _Min_Heap_Size;
    . = . + _Min_Stack_Size;
    . = ALIGN(8);
  } >RAM_D1

0693W00000NsTNsQAN.png 

I also changed the order of these:

 MX_DMA_Init();

 MX_DCMI_Init();

I still have the same issue however of the buffer not being updated.

I am doing all this with STM32CubeIDE

thanks