2022-06-11 11:20 AM
Hello,
I am testing the LTDC on a dev board. The strange thing is i am getting the wrong color at initialization.
Below is the code for initialzation of LTDC. I get red when i try to fill with blue, and red when i try to fill with blue. Thesre is half word swap heppening somwhere but i cant notice it.
Please advise.
=================================================================
2022-06-11 11:23 AM
Below is the initialization code :
static uint16_t frame_buffer[320 * 240];
LTDC_HandleTypeDef hltdc;
static uint16_t *ptr_ltdc_draw_buffer;
static void ltdc_low_level_init(void);
void ltdc_init(void)
{
/* Low level initialization */
ltdc_low_level_init();
/* Fill screen with Blue */
for (int i = 0; i < (320 * 240); i++)
{
frame_buffer[i] = 0x001F;
}
/* */
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_IIPC;
hltdc.Init.HorizontalSync = 3;
hltdc.Init.VerticalSync = 3;
hltdc.Init.AccumulatedHBP = 46;
hltdc.Init.AccumulatedVBP = 15;
hltdc.Init.AccumulatedActiveW = 366;
hltdc.Init.AccumulatedActiveH = 255;
hltdc.Init.TotalWidth = 374;
hltdc.Init.TotalHeigh = 257;
hltdc.Init.Backcolor.Blue = 255;
hltdc.Init.Backcolor.Green = 0;
hltdc.Init.Backcolor.Red = 0;
/* */
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
{
Error_Handler();
}
LTDC_LayerCfgTypeDef pLayerCfg = {0};
/* */
pLayerCfg.WindowX0 = 0;
pLayerCfg.WindowX1 = 320;
pLayerCfg.WindowY0 = 0;
pLayerCfg.WindowY1 = 240;
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
pLayerCfg.Alpha = 255;
pLayerCfg.Alpha0 = 225;
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
pLayerCfg.FBStartAdress = (uint32_t) ptr_ltdc_draw_buffer;
pLayerCfg.ImageWidth = 320;
pLayerCfg.ImageHeight = 240;
pLayerCfg.Backcolor.Blue = 255;
pLayerCfg.Backcolor.Green = 0;
pLayerCfg.Backcolor.Red = 0;
/* */
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief Private function template.
* @note Note 1.
* @param pram1 description of param1.
* @param pram2 description of param1.
* @retval Return description
*/
static void ltdc_low_level_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/*
* Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
PeriphClkInitStruct.PLL3.PLL3M = 6;
PeriphClkInitStruct.PLL3.PLL3N = 129;
PeriphClkInitStruct.PLL3.PLL3P = 2;
PeriphClkInitStruct.PLL3.PLL3Q = 2;
PeriphClkInitStruct.PLL3.PLL3R = 53;
PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_1;
PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3VCOWIDE;
PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* LTDC clock enable */
__HAL_RCC_LTDC_CLK_ENABLE();
/* GPIO clock enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*
LTDC GPIO Configuration :
PA1 ------> LTDC_R2
PB0 ------> LTDC_R3
PA11 ------> LTDC_R4
PA9 ------> LTDC_R5
PB1 ------> LTDC_R6
PE15 ------> LTDC_R7
PD6 ------> LTDC_B2
PA8 ------> LTDC_B3
PE12 ------> LTDC_B4
PA3 ------> LTDC_B5
PB8 ------> LTDC_B6
PB9 ------> LTDC_B7
PA6 ------> LTDC_G2
PE11 ------> LTDC_G3
PB10 ------> LTDC_G4
PB11 ------> LTDC_G5
PC7 ------> LTDC_G6
PD3 ------> LTDC_G7
PA4 ------> LTDC_VSYNC
PE13 ------> LTDC_DE
PE14 ------> LTDC_CLK
PC6 ------> LTDC_HSYNC
*/
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_6
|GPIO_PIN_9|USB_DFU_DM___LTDC_R4_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF9_LTDC;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF13_LTDC;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}
2022-06-12 01:58 AM
You miss as first use code snip
static uint16_t frame_buffer[320 * 240];
LTDC_HandleTypeDef hltdc;
static uint16_t *ptr_ltdc_draw_buffer;
static void ltdc_low_level_init(void);
void ltdc_init(void)
{
/* Low level initialization */
ltdc_low_level_init();
/* Fill screen with Blue */
for (int i = 0; i < (320 * 240); i++)
{
frame_buffer[i] = 0x001F;
}
as second your LCD need config controller registers where is set mode BGR or RGB ...
Too where you set ?
pLayerCfg.FBStartAdress = (uint32_t) ptr_ltdc_draw_buffer;
why you dont use simply frame_buffer here ...
2022-06-12 03:06 PM
thank you for replying ... i solved teh issue by swaping RGB to BGR on the TFT dispaly controler side ... using SPI comands