2019-03-04 02:00 PM
I am trying to make the LTDC controller work on my STM32F429 Discovery Board. Right now, after I run the code, I can tell the screen settings take their effects (SPI commands), but I cannot draw on the screen. The screen is getting noisy gradually.
Here are my settings:
Here is some of my code:
https://github.com/boningdong/STM32-ILI9341-DEMO/tree/RGB
static void MX_LTDC_Init(void)
{
LTDC_LayerCfgTypeDef pLayerCfg = {0};
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 = 9;
hltdc.Init.VerticalSync = 1;
hltdc.Init.AccumulatedHBP = 29;
hltdc.Init.AccumulatedVBP = 3;
hltdc.Init.AccumulatedActiveW = 269;
hltdc.Init.AccumulatedActiveH = 323;
hltdc.Init.TotalWidth = 279;
hltdc.Init.TotalHeigh = 327;
hltdc.Init.Backcolor.Blue = 5;
hltdc.Init.Backcolor.Green = 50;
hltdc.Init.Backcolor.Red = 10;
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
{
Error_Handler();
}
pLayerCfg.WindowX0 = 0;
pLayerCfg.WindowX1 = 240;
pLayerCfg.WindowY0 = 0;
pLayerCfg.WindowY1 = 320;
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_L8;
pLayerCfg.Alpha = 0x10;
pLayerCfg.Alpha0 = 0x10;
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR1_PAxCA;
pLayerCfg.FBStartAdress = 0;
pLayerCfg.ImageWidth = 240;
pLayerCfg.ImageHeight = 320;
pLayerCfg.Backcolor.Blue = 100;
pLayerCfg.Backcolor.Green = 50;
pLayerCfg.Backcolor.Red = 100;
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN LTDC_Init 2 */
/* USER CODE END LTDC_Init 2 */
}
void HAL_LTDC_MspInit(LTDC_HandleTypeDef* hltdc)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hltdc->Instance==LTDC)
{
/* USER CODE BEGIN LTDC_MspInit 0 */
/* USER CODE END LTDC_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_LTDC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**LTDC GPIO Configuration
PF10 ------> LTDC_DE
PA3 ------> LTDC_B5
PA4 ------> LTDC_VSYNC
PA6 ------> LTDC_G2
PB0 ------> LTDC_R3
PB1 ------> LTDC_R6
PE11 ------> LTDC_G3
PE12 ------> LTDC_B4
PE14 ------> LTDC_CLK
PE15 ------> LTDC_R7
PB10 ------> LTDC_G4
PB11 ------> LTDC_G5
PD10 ------> LTDC_B3
PC6 ------> LTDC_HSYNC
PC7 ------> LTDC_G6
PA11 ------> LTDC_R4
PA12 ------> LTDC_R5
PC10 ------> LTDC_R2
PD3 ------> LTDC_G7
PD6 ------> LTDC_B2
PB8 ------> LTDC_B6
PB9 ------> LTDC_B7
*/
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_11
|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
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_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_LTDC;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
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_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_3|GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* LTDC interrupt Init */
HAL_NVIC_SetPriority(LTDC_IRQn, 0, 0);
//HAL_NVIC_EnableIRQ(LTDC_IRQn);
HAL_NVIC_SetPriority(LTDC_ER_IRQn, 0, 0);
//HAL_NVIC_EnableIRQ(LTDC_ER_IRQn);
/* USER CODE BEGIN LTDC_MspInit 1 */
/* USER CODE END LTDC_MspInit 1 */
}
}
void LCD_LtdcInit() {
// Call LTDC_Init and GPIO_Init before calling this function
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*
GPIO_InitTypeDef gpioInit;
gpioInit.Mode = GPIO_MODE_OUTPUT_PP;
gpioInit.Pull = GPIO_PULLUP;
gpioInit.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpioInit.Pin = LCD_PIN_WRX;
HAL_GPIO_Init(LCD_WRX_PORT, &gpioInit);
gpioInit.Pin = LCD_PIN_RDX;
HAL_GPIO_Init(LCD_RDX_PORT, &gpioInit);
gpioInit.Pin = LCD_PIN_TE;
HAL_GPIO_Init(LCD_TE_PORT, &gpioInit);
gpioInit.Pin = LCD_PIN_DCX;
HAL_GPIO_Init(LCD_DCX_PORT, &gpioInit);*/
// Screen Parameters Set
HAL_LTDC_SetPixelFormat_NoReload(&hltdc, LTDC_PIXEL_FORMAT_L8 , LTDC_LAYER_1);
HAL_LTDC_SetAddress_NoReload(&hltdc, (uint32_t)VRAM, LTDC_LAYER_1);
HAL_LTDC_ConfigCLUT(&hltdc, LCD_CLUT, 256, LTDC_LAYER_1);
HAL_LTDC_EnableCLUT_NoReload(&hltdc, LTDC_LAYER_1);
HAL_LTDC_Reload(&hltdc, LTDC_RELOAD_VERTICAL_BLANKING);
}
void LCD_ModuleInit() {
//SOFTWARE RESET
LCD_WriteCommand(0x01);
HAL_Delay(1000);
//POWER CONTROL A
LCD_WriteCommand(0xCB);
LCD_WriteData(0x39);
LCD_WriteData(0x2C);
LCD_WriteData(0x00);
LCD_WriteData(0x34);
LCD_WriteData(0x02);
//POWER CONTROL B
LCD_WriteCommand(0xCF);
LCD_WriteData(0x00);
LCD_WriteData(0xC1);
LCD_WriteData(0x30);
//DRIVER TIMING CONTROL A
LCD_WriteCommand(0xE8);
LCD_WriteData(0x85);
LCD_WriteData(0x00);
LCD_WriteData(0x78);
//DRIVER TIMING CONTROL B
LCD_WriteCommand(0xEA);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
//POWER ON SEQUENCE CONTROL
LCD_WriteCommand(0xED);
LCD_WriteData(0x64);
LCD_WriteData(0x03);
LCD_WriteData(0x12);
LCD_WriteData(0x81);
//PUMP RATIO CONTROL
LCD_WriteCommand(0xF7);
LCD_WriteData(0x20);
//POWER CONTROL,VRH[5:0]
LCD_WriteCommand(0xC0);
LCD_WriteData(0x23);
//POWER CONTROL,SAP[2:0];BT[3:0]
LCD_WriteCommand(0xC1);
LCD_WriteData(0x10);
//VCM CONTROL
LCD_WriteCommand(0xC5);
LCD_WriteData(0x3E);
LCD_WriteData(0x28);
//VCM CONTROL 2
LCD_WriteCommand(0xC7);
LCD_WriteData(0x86);
//MEMORY ACCESS CONTROL
LCD_WriteCommand(0x36);
LCD_WriteData(0x48);
//FRAME RATIO CONTROL, STANDARD RGB COLOR
LCD_WriteCommand(0xB1);
LCD_WriteData(0x00);
LCD_WriteData(0x18);
//DISPLAY FUNCTION CONTROL
LCD_WriteCommand(0xB6);
//LCD_WriteData(0x08);
//LCD_WriteData(0x82);
//LCD_WriteData(0x27);
LCD_WriteData(0x0A);
LCD_WriteData(0xA7);
LCD_WriteData(0x27);
LCD_WriteData(0x04);
//3GAMMA FUNCTION DISABLE
LCD_WriteCommand(0xF2);
LCD_WriteData(0x00);
//GAMMA CURVE SELECTED
LCD_WriteCommand(0x26);
LCD_WriteData(0x01);
//POSITIVE GAMMA CORRECTION
LCD_WriteCommand(0xE0);
LCD_WriteData(0x0F);
LCD_WriteData(0x31);
LCD_WriteData(0x2B);
LCD_WriteData(0x0C);
LCD_WriteData(0x0E);
LCD_WriteData(0x08);
LCD_WriteData(0x4E);
LCD_WriteData(0xF1);
LCD_WriteData(0x37);
LCD_WriteData(0x07);
LCD_WriteData(0x10);
LCD_WriteData(0x03);
LCD_WriteData(0x0E);
LCD_WriteData(0x09);
LCD_WriteData(0x00);
//NEGATIVE GAMMA CORRECTION
LCD_WriteCommand(0xE1);
LCD_WriteData(0x00);
LCD_WriteData(0x0E);
LCD_WriteData(0x14);
LCD_WriteData(0x03);
LCD_WriteData(0x11);
LCD_WriteData(0x07);
LCD_WriteData(0x31);
LCD_WriteData(0xC1);
LCD_WriteData(0x48);
LCD_WriteData(0x08);
LCD_WriteData(0x0F);
LCD_WriteData(0x0C);
LCD_WriteData(0x31);
LCD_WriteData(0x36);
LCD_WriteData(0x0F);
LCD_WriteCommand(0x2c);
HAL_Delay(200);
//INTERFACE CONTROL
LCD_WriteCommand(0xF6);
LCD_WriteData(0x01);
LCD_WriteData(0x00);
LCD_WriteData(0x06);
//LCD_WriteData(0x08);
//RGB INTERFACE
LCD_WriteCommand(0xB0);
LCD_WriteData(0xC2);
//PIXEL FORMAT
LCD_WriteCommand(0x3A);
LCD_WriteData(0x55);
//EXIT SLEEP
LCD_WriteCommand(0x11);
HAL_Delay(120);
//TURN ON DISPLAY
LCD_WriteCommand(0x29);
LCD_WriteCommand(0x2c);
HAL_Delay(200);
}
2019-03-05 05:14 AM
https://s3.amazonaws.com/axxonshare/my_combo_tutorial.zip
Welcome feedback on this document and if it works for you. Good luck! :grinning_face: