cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX and BUG in LTDC HAL

Davydenko.Sergey
Associate II
Posted on March 28, 2015 at 16:00

if you need more than the width of the image width of the visible region it is necessary to change the HAL

DM00031020.pdf

16.7.23 LTDC Layerx Color Frame Buffer Length Register (LTDC_LxCFBLR)

(where x=1..2)

This register defines the color frame buffer line length and pitch.

Bits 31:29 Reserved, must be kept at reset valuer

Bits 28:16 CFBP[17:0]: Color Frame Buffer Pitch in bytes

These bits define the pitch which is the increment from the start of one line of pixels to the start of the next line in bytes

.

Bits 15:13 Reserved, must be kept at reset value

Bits 12:0 CFBLL[12:0]: Color Frame Buffer Line Length

These bits define the length of one line of pixels in bytes + 3.

 

The line length is computed as follows: Active high width x number of bytes per pixel + 3.

stm32f4xx_hal_ltdc.c

/**

  * @brief  Configures the LTDC peripheral 

  * @param  hltdc   :  Pointer to a LTDC_HandleTypeDef structure that contains

  *                   the configuration information for the LTDC.

  * @param  pLayerCfg: Pointer LTDC Layer Configuration structure

  * @param  LayerIdx:  LTDC Layer index.

  *                    This parameter can be one of the following values: 0 or 1

  * @retval None

  */

static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)

{

  uint32_t tmp = 0;

  uint32_t tmp1 = 0;

  uint32_t tmp2 = 0;

  /* Configures the horizontal start and stop position */

  tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16)) << 16);

  LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);

  LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16) + 1) | tmp);

  /* Configures the vertical start and stop position */

  tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16);

  LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);

  LTDC_LAYER(hltdc, LayerIdx)->WVPCR  = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1) | tmp);  

  /* Specifies the pixel format */

  LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);

  LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);

  /* Configures the default color values */

  tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8);

  tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16);

  tmp2 = (pLayerCfg->Alpha0 << 24);  

  LTDC_LAYER(hltdc, LayerIdx)->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED | LTDC_LxDCCR_DCALPHA);

  LTDC_LAYER(hltdc, LayerIdx)->DCCR = (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2); 

  /* Specifies the constant alpha value */

  LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);

  LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);

  /* Specifies the blending factors */

  LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);

  LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);

  /* Configures the color frame buffer start address */

  LTDC_LAYER(hltdc, LayerIdx)->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);

  LTDC_LAYER(hltdc, LayerIdx)->CFBAR = (pLayerCfg->FBStartAdress);

  if(pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)

  {

    tmp = 4;

  }

  else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)

  {

    tmp = 3;

  }

  else if((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \

    (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \

      (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \

        (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))

  {

    tmp = 2;

  }

  else

  {

    tmp = 1;

  }

  /* Configures the color frame buffer pitch in byte */

  LTDC_LAYER(hltdc, LayerIdx)->CFBLR  &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);

//  LTDC_LAYER(hltdc, LayerIdx)->CFBLR  = (((pLayerCfg->ImageWidth * tmp) << 16) | ((pLayerCfg->ImageWidth * tmp)  + 3));

  LTDC_LAYER(hltdc, LayerIdx)->CFBLR  = (((pLayerCfg->ImageWidth * tmp) << 16) | (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp)  + 3));

  /* Configures the frame buffer line number */

  LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  &= ~(LTDC_LxCFBLNR_CFBLNBR);

  LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  = (pLayerCfg->ImageHeight);

  /* Enable LTDC_Layer by setting LEN bit */  

  LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;

}

0 REPLIES 0