en.radzio.dxp.pl

LCD TFT Display Controller (LTDC)
The LCD TFT display controller provides a parallel digital RGB (Red, Green, Blue) and signals for horizontal, vertical synchronisation, Pixel Clock and Data Enable as output to interface directly to a variety of LCD and TFT panels.

LCD display configuration

TFT LCD timings

For 640x480 display resolution all timings are qual to standard VGA timigs. If you are using other display resolution change this definitions.

#define LCD_WIDTH  640
#define LCD_HEIGHT 480

#define HFP   16
#define HSYNC 96
#define HBP   48

#define VFP   10
#define VSYNC 2
#define VBP   33

Calcutations of Active and Total sizes for LTDC_AWCR and LTDC_TWCR registers

#define ACTIVE_W (HSYNC + LCD_WIDTH + HBP - 1)
#define ACTIVE_H (VSYNC + LCD_HEIGHT + VBP - 1)

#define TOTAL_WIDTH  (HSYNC + HBP + LCD_WIDTH + HFP - 1)
#define TOTAL_HEIGHT (VSYNC + VBP + LCD_HEIGHT + VFP - 1)

GPIO pins configuration
GPIO configuration is done similiar way as in example for SDRAM. But unfortuneatly TFT controller pins are shared in two alternate functions group (9 and 14), so there is third table with AF initialization values.

static const GPIO_TypeDef * const GPIOInitTable[] = {
  GPIOC, GPIOB, GPIOA, GPIOA, GPIOB, GPIOG,
  GPIOA, GPIOG, GPIOB, GPIOB, GPIOC, GPIOD,
  GPIOD, GPIOG, GPIOG, GPIOA, GPIOB, GPIOB,
  GPIOA, GPIOC, GPIOF, GPIOG,
  0};

static uint8_t const PINInitTable[] = {
  10, 0, 11, 12, 1, 6,
  6, 10, 10, 11, 7, 3,
  6, 11, 12, 3, 8, 9,
  4, 6, 10, 7,
  0};

static uint8_t const AFInitTable[] = {
  14, 9, 14, 14, 9, 14,
  14, 9, 14, 14, 14, 14,
  14, 14, 9, 14, 14, 14,
  14, 14, 14, 14,
  0};

TFT LCD controller initialization routine

void TFTLCD_Init(void)
{
  uint8_t i = 0;
  /* GPIO pin configuration */
  while(GPIOInitTable[i] != 0){
    gpio_conf(GPIOInitTable[i], PINInitTable[i], MODE_AF, TYPE_PUSHPULL, SPEED_100MHz, PULLUP_NONE,     AFInitTable[i]);
    i++;
  }
  /* PLL */
  RCC->PLLSAICFGR = (200 << 6) | (7 << 24) | (4 << 28);
  /* Enable SAI PLL */
  RCC->CR |= RCC_CR_PLLSAION;
  /* wait for SAI PLL ready */
  while((RCC->CR & RCC_CR_PLLSAIRDY) == 0);
  /* enable clock for LTDC */
  RCC->APB2ENR |= RCC_APB2ENR_LTDCEN;
  /* Synchronization Size Configuration */
  LTDC->SSCR = ((HSYNC - 1) << 16) | (VSYNC - 1);
  /* Back Porch Configuration */
  LTDC->BPCR = ((HBP - 1) << 16) | (VBP - 1);
  /* Active Width Configuration */
  LTDC->AWCR = (ACTIVE_W << 16) | (ACTIVE_H);
  /* Total Width Configuration */
  LTDC->TWCR = (TOTAL_WIDTH << 16) | (TOTAL_HEIGHT);
  /* Window Horizontal Position Configuration */
  LTDC_Layer1->WHPCR = HBP | ((HBP + LCD_WIDTH - 1) << 16);
  /* Window Vertical Position Configuration */
  LTDC_Layer1->WVPCR = VBP | ((VBP + LCD_HEIGHT - 1) << 16);
  /* Pixel Format Configuration */
  LTDC_Layer1->PFCR = 2;
  /* Color Frame Buffer Address */
  LTDC_Layer1->CFBAR = SDRAM_BASE;
  /* Color Frame Buffer Length */
  LTDC_Layer1->CFBLR = ((LCD_WIDTH * PIXELWIDHT) << 16) | ((LCD_WIDTH * PIXELWIDHT) + 3);
  /* Enable Layer */
  LTDC_Layer1->CR = LTDC_LxCR_LEN;
  /* Immediate Reload */
  LTDC->SRCR = LTDC_SRCR_IMR;
  /* Enable LTDC */
  LTDC->GCR = LTDC_GCR_LTDCEN;
}

Download source file :
  tftlcd.c

Example 1.
After SDRAM and TFT conroller are configured we are ready to display something on display. At this moment easiest way to display antything on LCD is use random content that SDRAM holds after power-up. Go to sdram.c file and comment following lines:

// Clear SDRAM
//for(ptr = SDRAM_BASE; ptr < (SDRAM_BASE + SDRAM_SIZE); ptr += 4)
// *((uint32_t *)ptr) = 0x00000000;

SDRAM content will be not initialized and memory will be hold (almost) random values.

//================================================================================================
// STM32F429 TFT LCD and SDRAM example 1
// Author : Radoslaw Kwiecien
// e-mail : radek@dxp.pl
// http://en.radzio.dxp.pl/stm32f429idiscovery/
//================================================================================================

#include "stm32f4xx.h"
//================================================================================================
//
//================================================================================================

void SDRAM_Init(void);
void TFTLCD_Init(void);
//================================================================================================
// main function
//================================================================================================
int main(void)
{
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN |
                  RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOEEN | RCC_AHB1ENR_GPIOFEN |
                  RCC_AHB1ENR_GPIOGEN;

  SDRAM_Init();
  TFTLCD_Init();
  while(1);
}
//================================================================================================
// End of file
//================================================================================================

Result of execution Example 1 (image on your display can be different) :

STM32F429 TFT LCD

Download source files
   Example 1

 

 
(c) Radosław Kwiecień