cancel
Showing results for 
Search instead for 
Did you mean: 

I couldn't get the tw9990 camera to work properly in the stm32h7s78dk kit.

hamzatamer
Associate II

I want to display the image captured from the TW9990 camera sensor on the LCD screen using the STM32H7S78-DK kit. Since the data from the camera sensor is in YUV422 format, I am converting it to RGB565 format for the LCD. However, I am uncertain if my DCMIPP_Init settings are correctly configured for the TW9990 camera. Specifically, as the datasheet does not specify the polarity settings, I am unsure about this part. My current settings are as follows. Could you help me verify and correct them if needed?

 

static void MX_DCMIPP_Init(void)
{

  /* USER CODE BEGIN DCMIPP_Init 0 */

  /* USER CODE END DCMIPP_Init 0 */

  DCMIPP_ParallelConfTypeDef ParallelConfig = {0};
  DCMIPP_PipeConfTypeDef PipeConfig = {0};

  /* USER CODE BEGIN DCMIPP_Init 1 */

  /* USER CODE END DCMIPP_Init 1 */

  /** Pipe 0 Config
  */
  phdcmipp.Instance = DCMIPP;
  if (HAL_DCMIPP_Init(&phdcmipp) != HAL_OK)
  {
    Error_Handler();
  }
  ParallelConfig.PCKPolarity = DCMIPP_PCKPOLARITY_FALLING ;	//not sure ask
  ParallelConfig.HSPolarity = DCMIPP_HSPOLARITY_LOW ;
  ParallelConfig.VSPolarity = DCMIPP_VSPOLARITY_LOW ;
  ParallelConfig.ExtendedDataMode = DCMIPP_INTERFACE_8BITS;
  ParallelConfig.Format = DCMIPP_FORMAT_YUV422;
  ParallelConfig.SwapBits = DCMIPP_SWAPBITS_DISABLE;
  ParallelConfig.SwapCycles = DCMIPP_SWAPCYCLES_ENABLE;
  ParallelConfig.SynchroMode = DCMIPP_SYNCHRO_HARDWARE;
  HAL_DCMIPP_PARALLEL_SetConfig(&phdcmipp, &ParallelConfig);
  PipeConfig.FrameRate = DCMIPP_FRAME_RATE_ALL;
  if (HAL_DCMIPP_PIPE_SetConfig(&phdcmipp, DCMIPP_PIPE0, &PipeConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN DCMIPP_Init 2 */

  /* USER CODE END DCMIPP_Init 2 */

}

 

 My LTDC settings are as follows

 

static void MX_LTDC_Init(void)
{

  /* USER CODE BEGIN LTDC_Init 0 */

  /* USER CODE END LTDC_Init 0 */

  LTDC_LayerCfgTypeDef pLayerCfg = {0};

  /* USER CODE BEGIN LTDC_Init 1 */

  /* USER CODE END LTDC_Init 1 */
  hltdc.Instance = LTDC;
  hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
  hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
  hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
  hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
  hltdc.Init.HorizontalSync = 3;
  hltdc.Init.VerticalSync = 3;
  hltdc.Init.AccumulatedHBP = 11;
  hltdc.Init.AccumulatedVBP = 11;
  hltdc.Init.AccumulatedActiveW = 811;
  hltdc.Init.AccumulatedActiveH = 491;
  hltdc.Init.TotalWidth = 819;
  hltdc.Init.TotalHeigh = 499;
  hltdc.Init.Backcolor.Blue = 0;
  hltdc.Init.Backcolor.Green = 0;
  hltdc.Init.Backcolor.Red = 0;
  if (HAL_LTDC_Init(&hltdc) != HAL_OK)
  {
    Error_Handler();
  }
  pLayerCfg.WindowX0 = xpos;
  pLayerCfg.WindowX1 = xpos + ImageWidth;
  pLayerCfg.WindowY0 = ypos;
  pLayerCfg.WindowY1 = ypos + ImageHeight;
  pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
  pLayerCfg.Alpha = 255;
  pLayerCfg.Alpha0 = 0;
  pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
  pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
  pLayerCfg.FBStartAdress = (uint32_t)LCD_FRAME_BUFFER;	//TODO
  pLayerCfg.ImageWidth = ImageWidth;
  pLayerCfg.ImageHeight = ImageHeight;
  pLayerCfg.Backcolor.Blue = 0;
  pLayerCfg.Backcolor.Green = 0;
  pLayerCfg.Backcolor.Red = 0;
  if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN LTDC_Init 2 */

  /* USER CODE END LTDC_Init 2 */

}

 


DMA2D_config are as follows

 

static void DMA2D_Config(uint16_t xsize, uint32_t ysize)
{

/* Configure the DMA2D Mode, Color Mode and output offset */
  hlcd_dma2d.Instance = DMA2D;
  /* Configure the DMA2D Mode, Color Mode and output offset */
  hlcd_dma2d.Init.Mode         = DMA2D_M2M_PFC;
  hlcd_dma2d.Init.ColorMode    = DMA2D_OUTPUT_RGB565;
  hlcd_dma2d.Init.OutputOffset = LcdResX - xsize;

  /* DMA2D Callbacks Configuration */
  hlcd_dma2d.XferCpltCallback  = DMA2D_TransferCompleteCallback;

  /* Foreground Configuration */
  hlcd_dma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
  hlcd_dma2d.LayerCfg[1].InputAlpha = 0;
  hlcd_dma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_YCBCR;
  hlcd_dma2d.LayerCfg[1].InputOffset = 0;
  //todo
  hlcd_dma2d.LayerCfg[1].AlphaInverted = DMA2D_REGULAR_ALPHA;
  hlcd_dma2d.LayerCfg[1].RedBlueSwap = DMA2D_RB_REGULAR;
  hlcd_dma2d.LayerCfg[1].ChromaSubSampling = DMA2D_CSS_422;

  hlcd_dma2d.Instance = DMA2D;
  HAL_DMA2D_DeInit(&hlcd_dma2d);

  /* DMA2D Initialization */
  if(HAL_DMA2D_Init(&hlcd_dma2d) == HAL_OK)
  {
    if(HAL_DMA2D_ConfigLayer(&hlcd_dma2d, 1) != HAL_OK)
    {
      Error_Handler();
    }
  }
  else
  {
    Error_Handler();
  }
}

 


I change the format with dma2d as follows, this code is available among the sample codes of the STM32H747 kit but not in the STM32H7S78-DK examples

 

static void DMA2D_ConvertFrameToRGB565(void *pSrc, void *pDst, uint32_t xsize, uint32_t ysize)
{
  uint32_t xPos, yPos, destination;

  /* Calculate the destination transfer address */
  xPos = (LcdResX  - xsize)/2;
  yPos = (LcdResY  - ysize)/2;

  destination = (uint32_t)pDst + (yPos * LcdResX + xPos) * 2 /*RGB565_BYTE_PER_PIXEL*/;

  dma2d_pending_copy = 1;
  /* Starts the DMA2D transfer */

  if(HAL_DMA2D_Start_IT(&hlcd_dma2d, (uint32_t)pSrc, destination, xsize, ysize) != HAL_OK)
  {
    Error_Handler();
  }

}

 

 

When I start the camera with these settings, the camera works but I can't see anything meaningful on the screen. There are pixels like noise. What can I do?

0 = CCIR601 compatible YCrCb 4:2:2 format with separate syncs and flags.
1 = ITU-R-656 compatible data sequence format.
I selected the output format as CCIR601 in the TW9990 initialization process, is this correct?

0 REPLIES 0