An4861 LCDTFT Display Controller LTDC On Stm32 Mcus Stmicroelectronics
An4861 LCDTFT Display Controller LTDC On Stm32 Mcus Stmicroelectronics
Application note
LCD-TFT display controller (LTDC) on STM32 MCUs
Introduction
The evolution of the mobile, industrial, and consumer applications leads to a stronger need
of graphical user interfaces (GUIs) and to an increase in the required hardware resources.
These applications require higher quality graphics, more hardware and software resources
(like memory for graphical primitives or framebuffer) and higher processing performances.
To respond to this increasing demand, microprocessor units are often used, which leads to a
higher costs and to more complex designs with longer time to market. To face these
requirements, the STM32 microcontrollers (MCUs) offer a large graphical portfolio.
Thanks to their embedded LCD-TFT display controller (LTDC), the STM32 MCUs allow
high-resolution display panels to be directly driven, without any CPU intervention. In
addition, the LTDC can access autonomously to internal memories or external memories to
fetch pixel data.
This application note describes the LCD-TFT display controller of the STM32 MCUs listed in
the table below, and demonstrates how to use and configure the LTDC peripheral. It also
highlights some hardware, software, and architectural considerations to obtain the best
graphical performances.
The STM32 products are named as follows in this application note:
• STM32F4x9
• STM32F7x6/7/8/9
• STM32H7A3/B3 and STM32H7B0
• STM32H742/43/45/47/53/55/57 and STM32H750
• STM32L4+ or STM32L4R/S and STM32L4P/Q
• STM32U59/A/F/G
Contents
9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
10 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
List of tables
List of figures
This section describes the basic terms used on the displays and graphics context in order to
provide an overview of the general display and graphics environment. This section also
summarizes the display interfaces supported by the STM32 Arm®(a)-based MCUs.
Display module
Display
controller
Frame
buffer
MSv44193V2
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
Display
controller
Frame
buffer
MSv44194V2
Display module
Frame
Parallel RGB +
buffer
control signals
Display glass
MCU
Display
controller
MSv44195V1
Figure 4. Display module without controller nor GRAM and with external framebuffer
Display module
MSv44196V1
Display technologies
There are many display technologies available on the market. The two main technologies
used are described below:
• LCD-TFT displays (liquid crystal display - thin film transistor): variant of LCD that uses
the TFT technology to improve the control of each pixel. Thanks to the TFT technology,
each pixel can be controlled by a transistor, allowing a fast response time and an
accurate color control.
• OLED displays (organic LED): pixels made of organic LEDs emitting directly the light,
offering a better contrast and an optimized consumption. The OLED technology
enables the possibility to use flexible displays, as no glass nor backlight are required.
The response time is very fast and the viewing angle is free as it does not depend on
any light polarization.
The way of driving the display module is quite similar in TFT and OLED technologies, the
main difference is in the backlight requirement, as the OLED does not require any.
Display module
Display
Parallel controller
MCU DBI
Display glass
GRAM
Frame
buffer
MSv44197V1
Display module
Display
controller
Serial
Display glass
MCU SPI DBI
GRAM
Frame
buffer
MSv44198V2
Display module
Display Parallel RGB
controller + control
signals
DPI
MCU Display glass
Frame
buffer
MSv44199V1
Display module
DSI Display
Host controller
MCU Display glass
PPI
Serial
DSI
D-PHY GRAM
controller
MSv44600V2
Motorola 6800
DBI Type A Display module
Cortex-M DMA
Display
controller
AHB
DBI Type B
MSv44647V1
DBI(2)
Display module
Cortex-M DMA
Display
controller
AHB
SPI
DBI Type C Flash RAM SPI
DBI GRAM
MSv44648V1
Display module
DPI
Cortex-M LTDC
LTDC(3)
Flash RAM FMC
MSv44649V1
DSI Host
AHB DBI
DSI
D-PHY GRAM
controller
DSI link
MSv44650V1
This section illustrates the LTDC controller benefits and summarizes the graphical portfolio
of the STM32 microcontrollers.
AN4861
The table below summarizes the STM32 MCUs embedding an LTDC and details the corresponding available graphic portfolio.
Table 3. STM32 MCUs embedding an LTDC and their available graphic portfolio
Max FMC Max
Max Max Octo- MIPI-
On chip SRAM and pixel
FLASH Quad- Octo AHB/AXI SPI JPEG DMA2D DSI Graphic
Device SRAM SDRAM clock
(bytes) SPI(1) -SPI frequency frequency codec (4) host libraries
(bytes) frequency (MHz)
(MHz)(2) (MHz) (3)
(5)
(MHz)
Display
panel
RGB
USB LCD Chrom
64 KB CCM GP GP ETH
Data RAM
Cortex-M4 DMA1 DMA2 DMA
HS TFT -
DMA DMA ART
DMA_P1
DMA_P2
I-Bus
DMA_MEM1
DMA_MEM2
D-Bus
S-Bus
ART
FLASH
APB1
9-Layer 32-bit multi-AHB Bus Matrix
peripheral
APB2
peripheral
SRAM1 (1)
SRAM2 (2)
SRAM3 (3)
AHB1
peripheral
AHB2
peripheral
FMC
Dual Quad-
SPI (4)
LTDC can access all slave memories Master Slave Bus multiplexer
MSv44601V2
1. SRAM1 size = 112 Kbytes for STM32F429/439 and 160 Kbytes for STM32F469/479.
2. SRAM2 size = 16 Kbytes for STM32F429/439 and 32 Kbytes for STM32F469/479.
3. SRAM3 size = 64 Kbytes for STM32F429/439 and 128 Kbytes for STM32F469/479.
4. Dual Quad-SPI interface is only available for STM32F469/479.
RGB
DTCM
ITCM
12 Bus Master
AHBS
DMA_MEM1
DMA_MEM2
AXIM
DMA_P1
DMA_P2
1x-64bit AHB
AHBP
AXI to Multi
- AHB ART
FLASH
BusMatrix
64-Bit
APB1
8-Layer 32-bit multi-AHB BusMatrix
Peripheral
APB2
Peripheral
SRAM1 (4)
SRAM2 (5)
AHB1
Peripheral
AHB2
Peripheral
FMC
Dual
Quad-SPI
64-bit bus
LTDC can access all slave memories Master Slave Bus multiplexer
32-bit bus MSv44602V2
The LTDC is a controller that reads the data of images in a line per line fashion. Its memory
access mode is 64/128-byte (for AHB/AXI) length, but when the end of a line is reached and
less than 64/128 bytes (for AHB/AXI) are left, the LTDC fetches the remaining data.
Layer1
AHB Interface
FIFO PFC
64x32b Blending
LCD_CLK
LCD_HSYNC
Display panel
HCLK
Layer2 LCD_VSYNC
LCD_DE
FIFO PFC Dithering
LCD_R[7:0]
64x32b
LCD_G[7:0]
LCD_B[7:0]
Configuration and
status registers
APB Interface
Synchronus
PCLK
timings generation
MSv44603V2
The LCD_CLK acts as the data valid signal for the LCD-TFT. The data is
LCD_CLK
considered by the display only on the LCD_CLK rising or falling edge.
The line synchronization signal (LCD_HSYNC) manages horizontal line scanning
LCD_HSYNC
and acts as line display strobe.
The frame synchronization signal (LCD_VSYNC) manages vertical scanning and
LCD_VSYNC
acts as a frame update strobe.
The DE signal, indicates to the LCD-TFT that the data in the RGB bus is valid and
LCD_DE
must be latched to be drawn.
The LTDC interface can be configured to output more than one color depth. It can
Pixel RGB data
use up to 24 data lines (RGB888) as display interface bus.
Other signals
It is usual that display panel interfaces include other signals that are not part of the LTDC
signals described in Table 5. These additional signals are required for a display module to
be fully functional. The LTDC controller is able to drive only signals described in Table 5.
The signals that are not part of the LTDC, may be managed using GPIOs and other
peripherals and may need specific circuits.
The display panels usually embed a backlight unit that requires an additional backlight
control circuit and a GPIO.
Some display panels need a reset signal and also a serial interface such as I2C or SPI.
These interfaces are used in general for the display initialization commands or for the touch
panel control.
The figure below shows a display panel connected to an STM32 MCU, using the LTDC
interface signals illustrated in Table 5.
HSYNC
VSYNC
LTDC
DE
STM32
PCLK
RGB
MSv44604V1
The LTDC can output data according to the following parallel formats: RGB565, RGB666,
and RGB888. So, 16-bit RGB565, 18-bit RGB888 or 24-bit RGB888 display can be
connected.
The table below summarizes the timings registers supported by the LTDC.
Figure 13. Typical LTDC display frame (active width = 480 pixels)
1 frame
LCD lines
Vertical back Vertical front
VSYNC
porch (VBP) porch (VFP)
1 line
Horizontal back Horizontal front
HSYNC LCD columns
porch (HBP) porch (HFP)
1 2 3 4 5 x x x x x 480
LCD_CLK
LCD_RGBs
LCD data
enable
MSv44605V1
HSYNC
width
Frame start Active width
VSYNC width
Total Height up to 2048: TOTALH[10:0]
VBP
Active display area
Data1, Line1
Active Height
Data(n), Line(n)
VFP
Caution: Any display resolution belonging to the maximal total area in 4096 x 2048 as described in
Figure 15 is supported by the LTDC only if the following conditions are met:
• The display panel pixel clock must not exceed the maximal LTDC pixel clock in Table 2.
• The display panel pixel clock must not exceed the maximal STM32 pixel clock
respecting the framebuffer bandwidth (see Section 4.2: Checking the display size and
color depth compatibility with the hardware configuration).
The figure below shows some custom and standard resolutions belonging to the maximal
4096 x 2048 supported by the LTDC.
QVGA 320x240
Custom 1600x272
Custom 480x272
VGA 640x480
HD 1280x720
XGA 1024x768
Total Height
up to 2048 lines
MSv44607V1
WVSTPOS[10:0]
Start position Y
MSv446
MSv44609V1
1. LTDC_LxWHPCR and LTDC_LxWVPCR are respectively LTDC layer x window horizontal and vertical
position configuration registers where “x” can refer to Layer1 or Layer2.
ARGB1555 Ax+1[0] Rx+1[4:0] Gx+1[4:3] Gx+1[2:0] Bx+1[4:0] Ax[0] Rx[4:0] Gx[4:3] Gx[2:0] Bx[4:0]
MSv44610V1
The figure below summarizes all layer color framebuffer configurable parameters.
Layer1 Layer2
framebuffer Layer1 color framebuffer framebuffer Layer2 color framebuffer
start address start address
Line length Line length
Layer1 Layer2
Pitch Pitch
Number of lines
Number of lines
Layer1 pixel . Layer2 pixel .
input format . input format .
. .
. .
MSv44611V1
Figure 20. Pixel format conversion from RGB565 input pixel format to the internal
ARGB8888 format
Input pixel format RGB565
Bit position 4 3 2 1 0 5 4 3 2 1 0 4 3 2 1 0
PFC
0 0 0 0 0 0 0 0 4 3 2 1 0 4 3 2 5 4 3 2 1 0 5 4 4 3 2 1 0 4 3 2
MSv44612V1
Note: Using two layers creates bandwidth constraints on the system. It is preferable to use only
one layer and to do the composition with the Chrom-Art Accelerator during the framebuffer
calculation (see Section 4.2.2: Checking display compatibility considering the memory
bandwidth requirements).
3.4 Interrupts
The LTDC peripheral supports two global interrupts:
• LTDC global interrupt
• LTDC global error interrupt
Each global interrupt is connected to two LTDC interrupts (logically disjointed) that can be
masked separately through a specific register. The table below summarizes all of the related
interrupts and all the particular cases when each interrupt is generated.
Run Active
Active
Sleep
Peripheral interrupts cause the device to exit Sleep mode.
Frozen
Stop
Peripheral registers content is kept.
Powered-down
Standby
The peripheral must be reinitialized after exiting Standby mode.
This section illustrates the different steps required before and during a graphical application
development using LTDC. The user must at first determine the graphical application
requirements, then check if the desired display size fits the hardware configuration.
During the graphical application compatibility check phase, the existing STM32 reference
boards described in Table 22 can be used to evaluate his hardware and software
configuration.
Framebuffer location
Depending on the required framebuffer size, the framebuffer can be located either in an
internal SRAM or in an external SRAM/SDRAM.
If the internal RAM is not enough for the framebuffer, the user must use an external
SDRAM/SRAM connected to the FMC.
Consequently, the required framebuffer size determines if the use of an external memory is
needed or not. The required framebuffer size depends on the display size and color depth.
ITCM
AHBS
12 Bus
Master
USB LCD
Cortex-M7 GP GP ETH
DMA
HS TFT
Chrom-
ART
DTCM RAM
DMA1 DMA2 DMA
L1-Cache DMA
ITCM RAM
1x AXI Layer to
DMA_MEM1
DMA_MEM2
3x-32-bit AHB
DMA_P1
DMA_P2
1x-64bit AHB
AXIM
AHBP
AXI to Multi
and
- AHB ART
FLASH
BusMatrix
64-Bit
APB1
8-Layer 32-bit multi-AHB BusMatrix
Peripheral
APB2
Peripheral
SRAM1
SRAM2
AHB1
Peripheral SDRAM
AHB2
Peripheral
FMC Framebuffer
Dual
Quad-SPI
The figure below shows a typical graphic hardware configuration where an external SDRAM
is connected to the FMC that is used for framebuffer. The SDRAM memory bandwidth
depends on the bus width and in the operating clock.
The SDRAM bus width can be 32-, 16-, or 8-bit, while the operating clock depends on the
system clock HCLK and the configured prescaler (HCLK/2 or HCLK/3).
Chrom-
Cortex-M ART LTDC
DMA2D RGB
Bus Matrix
FMC or
Flash RAM OCTOSPI Bank1
Bank2
External memory
LTDC fetching the frontbuffer from the external memory Bank1
The tables below list the maximal supported pixel clock at system level for various STM32
MCUs.
32 38 67 22 35
24 51 83 30 47
1 layer
16 76 83 45 70
8 83 83 83 83
32/32 19 33 NA 18
32/24 22 38 13 21
32/16 25 44 15 25
32/8 30 53 19 30
24/24 26 44 15 24
2 layers
24/16 31 53 18 30
24/8 38 67 23 38
16/16 39 67 22 37
16/8 51 83 31 50
8/8 78 83 46 74
1. System clock HCLK = 180 MHz, SDRAM runs at 90 MHz.
2. LTDC fetches the front buffer from the external memory. Either only one LTDC layer or two layers are used.
The LTDC layer color depth is 8, 16, 24 or 32 bpp.
3. LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to
frontbuffer.
32 42 74 25 39
24 56 83 34 52
1 layer
16 83 83 51 78
8 83 83 83 83
32/32 21 37 12 20
32/24 24 42 14 23
32/16 28 49 17 28
32/8 34 59 21 34
24/24 29 49 17 27
2 layers
24/16 34 59 20 33
24/8 42 74 26 42
16/16 43 74 25 41
16/8 57 83 34 56
8/8 83 83 51 82
1. System clock HCLK = 200 MHz, SDRAM runs at 100 MHz.
2. LTDC fetches the front buffer from the external memory. Either only one LTDC layer or two layers are used.
The LTDC layer color depth is 8, 16, 24 or 32 bpp.
3. LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to
frontbuffer.
32 49 93 29 48
24 66 124 38 64
1 layer
16 99 150 58 96
8 150 150 116 150
1. System clock HCLK = 240 MHz, SDRAM runs at 110 MHz.
2. LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24 or 32 bpp.
3. LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to
frontbuffer.
32 52 52 97 22 30 50
24 70 70 130 29 40 66
1 layer
16 105 105 140 44 60 100
8 140 140 140 89 121 140
1. System clock HCLK = 280 MHz, SDRAM/HyperRAM run at 110 MHz.
2. LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24 or 32 bpp.
3. LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to
frontbuffer.
32 11 -
24 15 10
1 layer
16 23 15
8 47 31
1. System clock HCLK = 120 MHz, SRAM is asynchronous.
2. LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24 or 32 bpp.
3. LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to
frontbuffer.
32 27 11
24 37 15
1 layer
16 55 23
8 60 46
1. System clock HCLK = 120 MHz, PSRAM runs at 60 MHz.
2. LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24 or 32 bpp.
3. LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to
frontbuffer.
Note: Decreasing the system clock (HCLK then LTDC) leads to a degradation of graphic
performances.
32 116 42
24 116 48
1 layer
16 116 71
8 116 116
1. System clock HCLK = 160 MHz, PSRAM memory runs at 160 MHz.
2. Limited by LTDC maximum output clock frequency, please refer to the relevant product datasheet.
3. LTDC fetches the front buffer from the external memory..
4. LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to
frontbuffer.
Color depth
Refresh rate Pixel clock Display
Resolution
(Hz) (MHz) standard
SDRAM 16-bit SDRAM 32-bit
320 x 240
5.6
(QVGA) Custom Up to 32 bpp
480 x 272 9.5
640 x 480 Industry
25.175 Up to 24 bpp Up to 32 bpp
(VGA) standard
800 x 600
60 40.000 Up to 16 bpp Up to 24 bpp
(SVGA) VESA
1024 x 768 guidelines(1)
65
(XGA) Up to 16 bpp
1280 x 768 68.250 CVT R.B(2)
8 bpp
1280 x 720
74.25 CEA(3)
(HD) Up to 16 bpp(4)
1920 x1080 30 74.25 CEA(3)
1. VESA (video electronics standards association) is a technical standards organization for computer display
standards providing display monitor timing (DMT) standards.
2. CVT R.B: coordinated video timings reduced blanking standard by VESA.
3. CEA = consumer electronics association.
4. Up to 8 bpp for the STM32F4x9 microcontrollers
4.2.3 Check the compatibility of the display panel interface with the LTDC
The user must choose the LCD panel depending on the application needs. The two main
factors to consider when choosing the LCD panel are the resolution and the color depth.
These two factors have a direct impact on the following parameters:
• required GPIO number
• framebuffer size and location
• pixel clock of the display
When selecting a display panel, the user must:
• Ensure that the display interface is compatible with the LTDC (parallel RGB with control
signals).
• Check if the control signals can be controlled by the LTDC (additional GPIOs are
sometimes needed).
• Ensure that the display signal levels are matching the LTDC interface signal levels
(VDD from 1.8 V to 3.6 V).
• Ensure that the display pixel clock is supported by the LTDC maximum pixel clock
defined in the relevant STM32 product datasheet.
• Verify that the display timings parameters are supported by the LTDC timings (see
Table 6: LTDC timing registers).
• Check that the display size and color depth are supported by the LTDC (refer to
Section 4.2.2: Checking display compatibility considering the memory bandwidth
requirements).
The table below summarizes the available packages and RGB interface of some STM32
MCUs embedding an LTDC.
Table 18. STM32 packages with LTDC peripheral versus RGB interface availability(1)
WLCSP143
WLCSP168
WLCSP180
UFBGA169
UFBGA176
TFBGA100
TFBGA216
LQFP100
LQFP144
LQFP176
LQFP208
Product
STM32F429/439 18 NA 18 24 24 24 24 24 18 NA NA
STM32F469/479(2) 18 NA 18 24 24 24 24 24 NA 24 NA
STM32F7x6 18 18 24 NA 24 24 24 24 24 NA NA
STM32F7x7 18 NA 24 NA 24 24 24 24 NA NA NA
(2)
STM32F7x8 NA NA NA NA NA NA NA NA NA NA 24
(2)
STM32F7x9 NA NA NA NA NA 24 24 24 NA NA 24
1. Gray cells with “NA” = the package is not available for that specific product.
Cells with “18” value = only RGB565 and RGB666 parallel outputs are supported.
Cells with “24” value = all of RGB565, RGB666, and and RGB888 outputs are supported.
2. The integrated MIPI-DSI controller allows easier PCB design with fewer pins. Refer to application note AN4860 for more
details on STM32 MIPI-DSI host.
VSYNC
Figure 24. Example of taking advantage from memory slaves split on STM32F4x9
LCD Chrom-
64 KB CCM
Data RAM
Cortex-M4 TFT
DMA
ART
DMA2D
I-Bus
D-Bus
S-Bus
ART
FLASH
SRAM1
SRAM2
SRAM3
LTDC fetching the framebuffer from SRAM2 or SRAM3 Master Slave Bus multiplexer
MSv44616V2
As a consequence, when the LTDC does not generate a burst, each access is interrupted
by a CPU or another master access (such as Chrom-Art Accelerator or Ethernet).
These interruptions highly reduce the LTDC bandwidth on a high-latency memory like the
external SDRAM that leads to an underrun.
To solve the issue described above, the user may choose a color depth that does not lead to
the described issue, or use one of the two following methods:
• Reduce the layer window and the framebuffer line widths.
• Add a number of dummy bytes at the end of every line of pixels to match the closest
frame line width multiple of 64/128 bytes (for AHB/AXI).
…. ….
Window start
Y=272
Active display area 480 x 272 X 64 bytes burst x 32 bytes burst Crossing the 1 KByte boundary
MSv44617V1
For this example, the two methods to solve the crossing 1-Kbyte boundary issue are
detailed below:
• First method
Reduce the layer window and the framebuffer line widths: use the LTDC layer
windowing feature by reducing the window size to match the closest frame line width
multiple of 64/128 bytes (for AHB/AXI).
Since the window width is reduced, the framebuffer size must also be reduced since
the extra 22 and 23 bursts for all frame lines are not fetched nor displayed by LTDC.
This method solves the 1-Kbyte boundary crossing issue with a slight window width
decrease (see Figure 26).
The code below is based on the HAL drivers and shows an example of setting the pitch
as described in Figure 26:
/* Setting the Layer1 window to 448x272 at positions X = 16 and Y = 0 */
pLayerCfg.WindowX0 = 16;
pLayerCfg.WindowX1 = 464;
pLayerCfg.WindowY0 = 0;
pLayerCfg.WindowY1 = 272;
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB888;
pLayerCfg.Alpha = 255;
pLayerCfg.Alpha0 = 0;
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR1_PAxCA;
/* Framebuffer start address: LTDC fetches the image directly from internal
flash that the real image width is 448 pixels. Only the 448 pixels width is
displayed*/
pLayerCfg.FBStartAdress = (uint32_t)&image_data_Image_RGB888_448x272;
pLayerCfg.ImageWidth = 448;
pLayerCfg.ImageHeight = 272;
pLayerCfg.Backcolor.Blue = 0;
pLayerCfg.Backcolor.Green = 0;
pLayerCfg.Backcolor.Red = 0;
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
{
Error_Handler();
}
…. ….
Window start
1 2 3 ….. 21
Y=272
• Second method
Add a number of dummy bytes at the end of every line of pixels to match the closest
frame line width multiple of 64/128 bytes (for AHB/AXI). This can be done using the
LTDC layer pitch (see Section 3.3: Two programmable LTDC layers). To do this, the
user must consider the two points below:
– The framebuffer must contain the dummy bytes (as described in Figure 27): when
writing data into the framebuffer, it can be done by programming an output offset
of the DMA2D equal to the difference between the closest burst multiple and the
actual line length data size.
– The LTDC line length must always be equal to the active data size, but, the LTDC
pitch must be programmed with the value of the closest bytes number multiple of
64/128 bytes (for AHB/AXI).
The HAL_LTDC_SetPitch function provided under the hal_ltdc driver can be used to
program the desired pitch value in number of pixels. For the previous example, the
value of the pitch to pass to this function must be equal to 512 (512 is the number of
pixels per line corresponding to a line length size of 1536 bytes that is multiple of
64/128 bytes (for AHB/AXI).
The code below is based on the HAL drivers and shows an example of setting the pitch
as described in Figure 27:
/* Setting the Layer1 window to 480x272 at positions X = 0 and Y = 0 */
pLayerCfg.WindowX0 = 0;
pLayerCfg.WindowX1 = 480;
pLayerCfg.WindowY0 = 0;
pLayerCfg.WindowY1 = 272;
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB888;
pLayerCfg.Alpha = 255;
pLayerCfg.Alpha0 = 0;
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR1_PAxCA;
/* Framebuffer start address: LTDC fetches the image directly from internal
flash that the real image width is 480 pixels but additional 32 pixels are
added to each line to get a 512 pixels pitch.
Only the 480 pixels width is displayed*/
pLayerCfg.FBStartAdress = (uint32_t)&image_data_Image_RGB888_512x272;
pLayerCfg.ImageWidth = 480;
pLayerCfg.ImageHeight = 272;
pLayerCfg.Backcolor.Blue = 0;
pLayerCfg.Backcolor.Green = 0;
pLayerCfg.Backcolor.Red = 0;
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
{
Error_Handler();
}
/* Sets the Layer1 (index 0 refers to Layer1) Pitch to 512 pixels */
HAL_LTDC_SetPitch(&hltdc, 512, 0);
Figure 27. Adding dummy bytes to make the line width multiple of 64 bytes
512 pixels
pitch Second 1 KByte Third 1 KByte
Frame line 2 1 2 ….. 8 9 .. .. 22 23 23 24
…. ….
Window start
Y=272
Active display area 480 x 272 x 32 dummy bytes X 64 dummy bytes X 64 bytes burst x 32 bytes burst
MSv44619V1
Row 1
Row 2
Row 3
Frontbuffer Backbuffer
Row ...
Row
buffers
MSv44620V1
For instance, when the SDRAM bank size is equal to 4 Mbytes, the following line code can
be used:
/* Framebuffer addresses within external SDRAM */
/* Frontbuffer in bank 1 of SDRAM memory */
uint32_t FrontBuffer = LCD_FB_START_ADRESS;
/* Backbuffer in the bank 2 of SDRAM memory */
uint32_t BackBuffer = LCD_FB_START_ADRESS + 1024 * 1024 * 4;
SDRAM RBURST
Another interesting feature allowing optimization of reading performances from the SDRAM
is the use of RBURST.
The SDRAM controller adds a cacheable read FIFO with a depth of six 32-bit lines. The
read FIFO is used when the read burst is enabled and allows the next read accesses to be
anticipated during CAS latencies.
The figure below describes the STM32F7 FMC banks and Quad-SPI MPU memory
attributes at default system memory map
NOR/RAM and
No Swap
SDRAM swapped
SWP_FMC = 00b SWP_FMC = 01b
0xDFFF FFFF
SDRAM BANK2
Reserved
256MB
0xD000 0000 Memory type:
0xCFFF FFFF Device non-cacheable
SDRAM BANK1
NOR/PSRAM
256MB
0xC000 0000
Registers Registers
0x9FFF FFFF
Quad-SPI 256MB Memory type: Quad-SPI 256MB
Normal cacheable
0x9000 0000
SDRAM BANK2
Reserved
256MB
Memory type:
Normal cacheable
SDRAM BANK1
FMC_Bank1 NOR/PSRAM
256MB
0x6000 0000
MSv44622V2
LCD_R7 R5
LCD_R6 R4
LCD_R5 R3
LCD_R4 R2
LCD_R3 R1
LCD_R2 R0
LCD_R1
LCD_R0
LCD_G7 G5
LCD_G6 G4
LCD_B7 B5
LCD_B6 B4
LCD_B5 B3
LCD_B4 B2
LCD_B3 B1
LCD_B2 B0
LCD_B1
LCD_B0
LCD_CLK CLK
LCD_DE DE
LCD_HSYNC HSYNC
LCD_VSYNC VSYNC
MSv44624V1
Note: The FIFO underrun and transfer error interrupts are enabled in the hal_ltdc driver
HAL_LTDC_Init() function
An example of enabling LTDC interrupts using STM32CubeMX is described in
Section 6.2.3: LTDC GPIOs configuration.
Table 19. LCD-TFT timings extracted from ROCKTECH RK043FN48H datasheet (1)
Item Symbol Min. Typ. Max. Unit
Pixel clock configuration with STM32CubeMX: the pixel clock is calculated with a
60 Hz refresh rate as shown below:
LCD_CLK = TOTALW x TOTALH x refresh rate
Based on Table 20, TOTALW = 531 and TOTALH = 297.
And for this example:
LCD_CLK = 531 x 297 x 60 = 9.5 MHz
Refer to the LTDC pixel clock configuration STM32CubeMX example in Section 6.2.4.
The LCD image converter is a very customizable free tool used to convert images to C files
and to generate the C file in the desired format. An example is described in Section 6.2.5:
Display an image from the internal flash.
When an application is in idle state and displays only a screen saver, it is important to drive
the STM32 product in Sleep mode to reduce the power consumption. In Sleep mode, all
peripherals can be enabled (FMC-SDRAM and LTDC for instance) while the CPU is
stopped.
External memories, such as SDRAM or Quad-SPI Flash, can be driven in low-power modes
whenever it is needed in order to avoid the waste of power.
If the application is in low-power state but requires to display graphics, the LTDC can be
kept active, and the SDRAM can be put in self-refresh mode (in order to save power). If the
application is set in power-down mode, it saves even more power.
The display can also be disabled or put in low-power mode if it is not needed when running
the application.
The figure below illustrates a graphic implementation example, with a single chip and no
external memories used.
Chrom-
Cortex-M ART LTDC
DMA2D
RGB
Bus Matrix
Flash RAM
Up to Dual FMC
Up to
512KB QSPI
2 MB
The figure below illustrates a graphic implementation example where two external
memories are connected to an STM32 MCU, one for the framebuffer and the other for
graphic primitives.
Chrom-
Cortex-M ART LTDC
DMA2D RGB
Bus Matrix
Up to 256-Mbyte 32-bit
memory-mapped Graphic primitives in the external Quad-SPI with internal Flash
1280 x 720
16 bpp UFBGA176
1024 x 768 TFBGA216/UFBGA169/
High-end 32-bit RGB888
1600 x 272 LQFP176/LQFP208
24 bpp WLCSP180/WLCSP168
800 x 600
800 x 600 16 bpp
800 x 480
Mid-end 16-bit RGB666 LQFP144/WLCSP143
640 x 480 24 bpp
400 x 400(2)
400 x 400(2)
480 x 272
Low-end 16 bpp No RGB666 LQFP100/TFBGA100
320 x 320(2)
320 x 240
1. Package availability of STM32 MCUs embedding LTDC is summarized in Table 18.
2. 400x400 and 320 x 320 are specific display resolutions commonly used for smart watches.
Chrom-
Cortex-M7 ART LTDC
L1-Cache DMA2D RGB
Flash RAM
320KB QSPI FMC
1MB
16 MB 8 MB
QSPI SDRAM MSv44628V1
1. The pink arrow shows the pixel data path to the display.
The STM32F746G-DISCO board embeds a parallel true color RGB888 LCD-TFT panel with
a 480 x 272 resolution.
For more details on the STM32F746G-DISCO board, refer to user manual Discovery kit for
STM32F7 series with STM32F746NG MCU (UM1907).
The figure below shows the ROCKTECH RK043FN48H true color panel (RGB888)
connected to the STM32F746 MCU.
Timing
signals
Backlight
control
RGB888
Touch interrupt
I2C for touch
sensor
LCD Reset
MSv44629V3
As shown in the last figure, the display module is connected to the MCU through two
different pin categories:
• LTDC interface pins:
– 24-bit RGB interface
– Timing signals: LCD_HSYNC, LCD_VSYNC, LCD_DE and LCD_CLK
• Other specific pins:
– LCD_DISP to enable/disable display standby mode
– INT interrupt line: allows the touch sensor to generate interrupts
– I2C interface to control the touch sensor
– LCD_RST reset pin: allows the LCD-TFT reset. This pin is connected to the global
MCU reset pin (NRST).
– LCD_BL_A and LCD_BL_K pins for LED backlight control: the backlight is
controlled by the STLD40DPUR circuit.
Backlight controller: the STLD40DPUR circuit described in the figure below is a boost
converter that operates from 3.0 V to 5.5 V. It can provide an output voltage as high as 37 V
and can drive up to ten white LEDs in series. Refer to the STLD40D datasheet for more
information on the backlight controller.
The high level on the LCD_BL_CTRL (PK3) signal lights the backlight on, while the low level
switches it off.
Note: It is possible to change the display brightness (dim the backlight intensity) by applying a
low-frequency (1 to 10 kHz) PWM signal to the EN pin 7 of the STLD40D circuit. This action
needs a rework since there is no timer PWM output alternate function available on the PK3
pin. The user must remove the R81 resistance and connect another GPIO pin with the PWM
output alternate function.
PK3
MSv44630V1
Based on these results, the required framebuffer size is about 128 Kbytes for 8 bpp. In that
case, the framebuffer can be located in the internal SRAM1 (240 Kbytes). This is not valid
for a double-framebuffer case as the size of 128 x 2 Kbytes exceeds the internal SRAM
size.
For the 16 bpp color depth and in a double-framebuffer configuration, the required
framebuffer size (2 x 255 Kbytes) exceeds the internal SRAM size, so using an external
SRAM or SDRAM is a must for this configuration.
For the 24 bpp color depth and in a double-framebuffer configuration, the required
framebuffer size exceeds the internal SRAM size (2 x 382.5 Kbytes), so using an external
SRAM, or SDRAM is a must for this configuration.
The next step is to check if the SDRAM 16-bit bus width can sustain the desired resolution
and color depth.
Check if a 480 x 272 resolution with 24 bpp fits the SDRAM 16-bit
configuration
At this stage, the user decided to use an external SDRAM but still has to check if the
SDRAM 16-bit bus width (actual hardware implementation in the discovery board) matches
the 480 x 272 @ 60 Hz display size and 24 bpp color depth.
In order to conclude if such hardware configuration can support the desired display size and
color depth or not, the user must first compute the pixel clock.
The computed LCD_CLK is about 9.5 MHz (for computing pixel clock refer to Section 6.2.3:
LTDC GPIOs configuration.
Then the user must check, based on the following parameters, if the computed pixel clock is
not higher than the maximum LCD_CLK indicated in Table 11:
• number of used LTDC layers: in this example, only one layer used
• system clock speed HCLK and framebuffer memory speed: HCLK @ 200 MHz and
SDRAM @ 100 MHz
• external framebuffer memory bus width 16-bit SDRAM
• number of AHB masters accessing concurrently to external SDRAM: two masters
(DMA2D and LTDC)
Referring to the pixel clock Table 11 in the “LTDC + DMA2D” column and one layer row, the
pixel clock can reach 34 MHz for a 16-bit SDRAM.
So, the 16-bit SDRAM bus width is quite enough to sustain a 480 x 272 @ 60 Hz resolution
(LCD_CLK = 9.5 MHz) with 24 bpp color depth.
MSv44631V2
If after selecting one hardware configuration (RGB888 as shown in the above figure), the
used GPIOs do not match with the display panel connection board, the user can change the
desired GPIO and configure the alternate function directly on the pin. The figure below
shows how to configure manually a PJ7 pin to LTDC_G0 alternate function.
MSv44632V2
The used pins are highlighted in green once all LTDC interface GPIOs are correctly
configured. The user must now set their speed to very high.
To set the GPIOs speed using STM32CubeMX, select the Configuration tab then click on
the LTDC button as shown in the figure below.
MSv44633V2
In the LTDC Configuration window described in the figure below, select all the LTDC pins,
then set the maximum output speed to Very High.
MSv44634V1
MSv44635V2
Then, the LDC_DISP (PI12) pin must be configured to high level: in the Configuration tab,
click on the GPIO button. In the Pin Configuration window, set the GPIO output level to high
as described in the figure below.
MSv44636V1
Due to the R85 pull-up resistance, the backlight is at its highest level by default if the
LCD_BL_CTRL (PK3) pin is kept floating. There is no need to configure this pin.
MSv44637V1
MSv44638V1
To get the system clock HCLK @ 200 MHz, set the PLLs and the prescalers in the Clock
Configuration tab as shown in the figure below.
MSv44639V2
PLLM
MSv44640V1
In order to configure the display timing, the user must go to the Configuration tab as
indicated in Figure 38, and then click on the LTDC button. In the LTDC configuration
window, the user must select the Parameter Settings tab and fill in the timing values (refer to
the figure below).
LTDC_SSCR
register
To be filled from display
datasheet
LTDC_TWCR
LTDC_SSCR
register
To be filled from display
datasheet
LTDC_TWCR
Polarity setting
Programmable
Background color in
RGB888 format
MSv44641V1
Window size
and position
Framebuffer
Pixel Input format
Blending factors
Converting the image to a header file using the LCD image converter tool
The user must generate the header file respecting the configured LTDC layer pixel input
format RGB565 (see Pixel input format and Section 4.8).
In this example, the LCD-Image-Converter-20161012 tool is used (see Section 4.8 for more
details on this tool).
To convert an image, the user must first run the LCD-Image-Converter tool. Then, in the
home page shown in the figure below, click on File->Open and select the image file to be
converted.
The used image size must be aligned with the LTDC Layer1 configuration (480 x 272). If the
used image size is not aligned with the LTDC Layer1 configuration, the user can resize the
image by going to Image->Resize or choose another image with the correct size.
For this example, the used image size is 480 x 272 and shows the STMicroelectronics logo
(see Figure 49).
The image is then displayed on the LCD-Image-Converter tool home page as described in
the figure below.
To convert the image to a header file avoiding the Red and Blue swap issue explained in
Section 4.8, the user must configure the tool to convert the image to a table of 32-bit words.
To do it, in the home page menu, click on Options->Conversion as shown in the figure
below.
In the Options window shown in the figure below, select the Image tab then select the
RGB565 color in the Preset field. Set the Block size field to 32-bit and click on OK button.
Note: The user can also convert the image to a table of bytes, but in that case he must swap the
Red and Blue colors in the Conversion window matrix tab.
To generate the header file, click on File->Convert. In the displayed window shown in the
figure below, set the file type to C/C++ headers (*.h), then save the *.h file in include \Inc
directory (same location as main.h file) by clicking on the Save button.
The generated header file must be included in the main.c file. It includes a table of 32-bit
words where each word represents two pixels.
In this header file, the user must comment the structure definition located just after the table
and keep only the table definition as shown below:
/* Converted image: image_data_STLogo definition */
const uint32_t image_data_STLogo[65280] = {0xffffffff, 0xffffffff,
........};
Setting the LTDC framebuffer Layer1 start address to the internal flash (image
address in the flash)
The generated project by STM32CubeMX must include in the main.c file the
MX_LTDC_Init() function that allows the LTDC peripheral configuration.
In order to display the image, the user must set the LTDC Layer1 framebuffer start address
to the address of the image in the internal flash.
The MX_LTDC_Init() function is presented below with the framebuffer start address
setting.
/* LTDC configuration function generated by STM32CubeMX tool */
static void MX_LTDC_Init(void)
{
LTDC_LayerCfgTypeDef pLayerCfg;
hltdc.Instance = LTDC;
/* LTDC control signals polarity setting */
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
/* Timings configuration */
hltdc.Init.HorizontalSync = 0;
hltdc.Init.VerticalSync = 9;
hltdc.Init.AccumulatedHBP = 43;
hltdc.Init.AccumulatedVBP = 21;
hltdc.Init.AccumulatedActiveW = 523;
hltdc.Init.AccumulatedActiveH = 293;
hltdc.Init.TotalWidth = 531;
hltdc.Init.TotalHeigh = 297;
/* Background color */
hltdc.Init.Backcolor.Blue = 0;
hltdc.Init.Backcolor.Green = 0;
hltdc.Init.Backcolor.Red = 0x0;
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
{
Error_Handler();
}
/* Layer1 Window size and position setting */
pLayerCfg.WindowX0 = 0;
pLayerCfg.WindowX1 = 480;
pLayerCfg.WindowY0 = 0;
pLayerCfg.WindowY1 = 272;
/* Layer1 Pixel Input Format setting */
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
0xC0200000
• Region2 256 KB
Backbuffer 256 KB • Normal memory
• Cacheable WT
• Full access
• Execute Never
SDRAM memory size (8 MB)
• Region0 8 MB
• Normal memory
• Cacheable WT
• Full access
• Enable execution
0xC0800000
MSv44686V2
0x90000000
· Region4 16 MB
· Normal memory
· Cacheable
· Read Only
QSPI memory size (16 MB) · Execute Never
0x91000000
Quad-SPI addressable
space (256 MB)
· Region3 256 MB
· Strongly Ordered
· Non-Cacheable
· No Access
· Execute Never
0x9FFFFFFF
MSv44687V1
HAL_MPU_ConfigRegion(&MPU_InitStruct);
HAL_MPU_ConfigRegion(&MPU_InitStruct);
HAL_MPU_ConfigRegion(&MPU_InitStruct);
HAL_MPU_ConfigRegion(&MPU_InitStruct);
HAL_MPU_ConfigRegion(&MPU_InitStruct);
32F429I 240 x
DPI 2.4 RGB666 Resistive 16 NA NA
DISCOVERY 320
STM32 STM32439I- 640 x
DPI 5.7 RGB666 Capacitive 256
F429/439 EVAL2 480
32 16 NA
STM32429I- 480 x
DPI 4.3 RGB888 Resistive
EVAL1 272
32F469I 800 x
MIPI-DSI 4 RGB888 Capacitive 32 NA 16
STM32 DISCOVERY 480
384
F469/479 STM32469I- 800 x
MIPI-DSI 4 RGB888 Capacitive 32 16 64
EVAL(1) 480
32F746G 480 x
DPI 4.3 RGB888 Capacitive 16 NA 16
DISCOVERY 272
STM32 640 x
DPI 5.7 RGB666 Capacitive 320
F7x6 STM32746G- 480
32 16 64
EVAL 480 x
DPI 4.3 RGB888 Resistive
272
STM32F769I- 800x4
MIPI-DSI 4 RGB888 Capacitive 32 NA 64
DISCO(2) 80
STM32 STM32F779I- 512
F7x9(1) EVAL 800x4
MIPI-DSI 4 RGB888 Capacitive 32 16 64
STM32F769I- 80
EVAL
1. An available board B-LCDAD-HDMI1 (that can be purchased separately), allows the DSI conversion into HDMI format to
connect HDMI consumer displays.
A DSI to LCD adapter board B-LCDAD-RPI1 (that can be purchased separately) provides a flexible connector from the
microcontroller motherboard to the standard display connector (TE 1-1734248).
2. Another discovery board is available STM32F769I-DISC1 but with no embedded display. The display can be purchased
separately as B-LCD40-DSI1ordering code.
The display controller embeds a very flexible interface that provides below features that
allow the STM32 MCUs to support multiple-parallel display panels (such as LCD-TFT and
OLED displays) available in the market:
• different signal polarities
• programmable timings and resolutions
The display panel pixel clock (as indicated in manufacturer datasheet) must not be higher
than the STM32 maximal pixel clock. The user must refer to the display datasheet to ensure
that the panel running clock is lower than the maximum pixel clock.
This section summarizes the most frequently asked questions regarding the LTDC usage
and configurations.
9 Conclusion
The STM32 MCUs provide a very flexible display controller, used to interface with a wide
range of displays at a lower cost and offering high performances.
Thanks to its integration in a smart architecture, the LTDC autonomously fetches the
graphical data from the framebuffer and drives them to the display without any CPU
intervention.
The LTDC can continue fetching the graphical data and driving the display while the CPU is
in Sleep mode, which is ideal for low power and mobile applications such as smart watches.
This application note described the STM32 graphical capabilities and presented some
considerations and recommendations to take fully advantage of the system smart
architecture.
10 Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgment.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. For additional information about ST trademarks, refer to www.st.com/trademarks. All other product
or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.