cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4R9I-DISCO problem with ARGB8888 image

Hzhan.2
Associate II

Hello,

I am developing on STM32L4R9I-Disco, and I want to display ARGB8888 images on the round DSI display under the command of UART. For example, I send hex 'b2' to this board by uart, one image is displayed.

I have succeeded some parts, but the image is not well displayed (the attached picture).

Anyone knows what's the problem?

Thank you.

Here are some parts of the program:

#define VSYNC               1
#define VBP                 1
#define VFP                 1
#define VACT                390
#define HSYNC               1
#define HBP                 1
#define HFP                 1
#define HACT                390
 
#define LAYER_ADDRESS       GFXMMU_VIRTUAL_BUFFER0_BASE
 
static void CopyInVirtualBuffer_single(uint32_t *pSrc,
									   uint32_t *pDst,
									   uint16_t xsize,
									   uint16_t ysize);

UART part:

uint8_t Rx_data[10];
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	HAL_UART_Receive_IT(&huart2, Rx_data, 1);
	if (Rx_data[0] == 0xb2)
	{
	CopyInVirtualBuffer_single((uint32_t*) image_img_01_ARGB, (uint32_t*) LAYER_ADDRESS, 390, 390);
	pending_buffer = 1;
	HAL_DSI_Refresh(&DsiHandle);
	HAL_GPIO_TogglePin(GPIOH, GPIO_PIN_4);
	}
}

main:

int main(void)
{
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_USART2_UART_Init();
 MX_USART3_UART_Init();
 
 HAL_UART_Receive_IT(&huart2, Rx_data, 1);
 
 BSP_LED_Init(LED1);
 BSP_LED_Init(LED2);
 
 if(LCD_Config() != LCD_OK)
 {
  Error_Handler();
 }
 
 while (1)
 {
 }

some configurations:

__HAL_GFXMMU_RESET_HANDLE_STATE(&GfxmmuHandle);
  GfxmmuHandle.Instance = GFXMMU;
  GfxmmuHandle.Init.BlocksPerLine                     = GFXMMU_192BLOCKS; 
  GfxmmuHandle.Init.DefaultValue                      = 0xFFFFFFFF;
  GfxmmuHandle.Init.Buffers.Buf0Address               = (uint32_t) PhysFrameBuffer;
  GfxmmuHandle.Init.Buffers.Buf1Address               = 0; /* Not Used */
  GfxmmuHandle.Init.Buffers.Buf2Address               = 0; /* Not Used */
  GfxmmuHandle.Init.Buffers.Buf3Address               = 0; /* Not Used */
  GfxmmuHandle.Init.Interrupts.Activation             = ENABLE;  //DISABLE
  //GfxmmuHandle.Init.Interrupts.UsedInterrupts         = GFXMMU_AHB_MASTER_ERROR_IT; /* Not Used */
  if(HAL_OK != HAL_GFXMMU_Init(&GfxmmuHandle))
  {
    return(LCD_ERROR);
  }
  if(HAL_OK != HAL_GFXMMU_ConfigLut(&GfxmmuHandle, 0, 390, (uint32_t) gfxmmu_lut_config_32))
  {
    return(LCD_ERROR);
  }
  if(HAL_OK != HAL_GFXMMU_DisableLutLines(&GfxmmuHandle, 390, 634))
  {
    return(LCD_ERROR);
  }
 
 
__HAL_LTDC_RESET_HANDLE_STATE(&LtdcHandle);
  LtdcHandle.Instance = LTDC;
  LtdcHandle.Init.HSPolarity         = LTDC_HSPOLARITY_AL;
  LtdcHandle.Init.VSPolarity         = LTDC_VSPOLARITY_AL;
  LtdcHandle.Init.DEPolarity         = LTDC_DEPOLARITY_AL;
  LtdcHandle.Init.PCPolarity         = LTDC_PCPOLARITY_IPC;
  LtdcHandle.Init.HorizontalSync     = 0;   /* HSYNC width - 1 */
  LtdcHandle.Init.VerticalSync       = 0;   /* VSYNC width - 1 */
  LtdcHandle.Init.AccumulatedHBP     = 1;   /* HSYNC width + HBP - 1 */
  LtdcHandle.Init.AccumulatedVBP     = 1;   /* VSYNC width + VBP - 1 */
  LtdcHandle.Init.AccumulatedActiveW = 391; /* HSYNC width + HBP + Active width - 1 */
  LtdcHandle.Init.AccumulatedActiveH = 391; /* VSYNC width + VBP + Active height - 1 */
  LtdcHandle.Init.TotalWidth         = 392; /* HSYNC width + HBP + Active width + HFP - 1 */
  LtdcHandle.Init.TotalHeigh         = 392; /* VSYNC width + VBP + Active height + VFP - 1 */
  LtdcHandle.Init.Backcolor.Red      = 0;   /* Not used default value */
  LtdcHandle.Init.Backcolor.Green    = 0;   /* Not used default value */
  LtdcHandle.Init.Backcolor.Blue     = 0;   /* Not used default value */
  LtdcHandle.Init.Backcolor.Reserved = 0xFF;
  if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK)
  {
    return(LCD_ERROR);
  }
 
  /* LTDC layer 1 configuration */
  LayerCfg.WindowX0        = 0;
  LayerCfg.WindowX1        = 390;
  LayerCfg.WindowY0        = 0;
  LayerCfg.WindowY1        = 390;
  //LayerCfg.PixelFormat     = LTDC_PIXEL_FORMAT_RGB888;
  //LayerCfg.PixelFormat     = LTDC_PIXEL_FORMAT_ARGB1555;
  LayerCfg.PixelFormat     = LTDC_PIXEL_FORMAT_ARGB8888;
  LayerCfg.Alpha           = 0xFF; /* NU default value */
  LayerCfg.Alpha0          = 0; /* NU default value */
  LayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; /* Not Used: default value */
  LayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; /* Not Used: default value */
  LayerCfg.FBStartAdress   = LAYER_ADDRESS;
  LayerCfg.ImageWidth      = 390;
  LayerCfg.ImageHeight     = 390;
  LayerCfg.Backcolor.Red   = 0; /* Not Used: default value */
  LayerCfg.Backcolor.Green = 0; /* Not Used: default value */
  LayerCfg.Backcolor.Blue  = 0; /* Not Used: default value */
  LayerCfg.Backcolor.Reserved = 0xFF;
  if(HAL_LTDC_ConfigLayer(&LtdcHandle, &LayerCfg, 0) != HAL_OK)   //LTDC_LAYER_1 --> 0
  {
    return(LCD_ERROR);
  }
  if (HAL_LTDC_SetPitch(&LtdcHandle, 768, 0) != HAL_OK)
  {
	return(LCD_ERROR);
 }
 
static void CopyInVirtualBuffer_single(uint32_t *pSrc, uint32_t *pDst, uint16_t xsize, uint16_t ysize)
{
  uint32_t source      = (uint32_t)pSrc;
  Dma2dHandle.Instance          = DMA2D;
  /*##-1- Configure the DMA2D Mode, Color Mode and output offset #############*/
  Dma2dHandle.Init.Mode           = DMA2D_M2M;
  Dma2dHandle.Init.ColorMode      = DMA2D_OUTPUT_ARGB8888;
  Dma2dHandle.Init.OutputOffset   = 768 - xsize;  
  Dma2dHandle.Init.AlphaInverted  = DMA2D_REGULAR_ALPHA;  /* No Output Alpha Inversion */
  Dma2dHandle.Init.RedBlueSwap    = DMA2D_RB_REGULAR;     /* No Output Red & Blue swap */
  Dma2dHandle.Init.BytesSwap      = DMA2D_BYTES_REGULAR;  /* Regular output byte order */
  Dma2dHandle.Init.LineOffsetMode = DMA2D_LOM_PIXELS;     /* Pixel mode                */
 
  /*##-2- Foreground Configuration ###########################################*/
  Dma2dHandle.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888; 
  Dma2dHandle.LayerCfg[1].InputOffset    = 0;
  Dma2dHandle.LayerCfg[1].AlphaMode      = DMA2D_NO_MODIF_ALPHA;
  Dma2dHandle.LayerCfg[1].InputAlpha     = 0xFF;                /* Not used */
  Dma2dHandle.LayerCfg[1].RedBlueSwap    = DMA2D_RB_SWAP; //DMA2D_RB_REGULAR;    /* No ForeGround Red/Blue swap */ 
  Dma2dHandle.LayerCfg[1].AlphaInverted  = DMA2D_REGULAR_ALPHA; /* No ForeGround Alpha inversion */
 
  /* DMA2D Initialization */
  if(HAL_DMA2D_Init(&Dma2dHandle) == HAL_OK)
  {
    if(HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1) == HAL_OK)
    {
      if (HAL_DMA2D_Start(&Dma2dHandle, source, LAYER_ADDRESS, xsize, ysize) == HAL_OK)
      {
        /* Polling For DMA transfer */
        HAL_DMA2D_PollForTransfer(&Dma2dHandle, 10);
      }
    }
  }
}

0693W000006EF6mQAG.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
Hzhan.2
Associate II

Here is the solution: define the output of DAM2D as RGB888 or RGB565, not ARGB8888.

View solution in original post

3 REPLIES 3
MM..1
Chief III

??? how is your problem ??? why 768-xsize offset

The image is tore into 2 parts, and it is inverted (the black in the photo)

768 - xsize: I use GFXMMU, it is the same with the example DSI_CmdMode_SingleBuffer in the firmware package.

Line offset = virtual buffer line width in pixels - image width in pixels.

Hzhan.2
Associate II

Here is the solution: define the output of DAM2D as RGB888 or RGB565, not ARGB8888.