AN4861 · Application noteIntroduction to LCD-TFT display controller (LTDC) on STM32 MCUs
Download .pdfOpen in the full document

Creating a graphical application with LTDC

Creating a graphical application with LTDC

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 AN4861_Reference-boards-with-LCD-TFT-panel.html#id_61973__table_wcq_hcr_31c can be used to evaluate his hardware and software configuration.

Determining graphical application requirements

Determining the graphical application needs is a crucial step to start from. Some of the most important parameters to be defined before starting the creation of the graphical application are display resolution, color depth, as well as the nature of the data to display (static images, text, or animation).

Once the basic parameters mentioned above are defined, the user must determine the graphical hardware architecture of the application, as well as the required hardware resources. The best-fitting STM32 package (see Table 21 STM32 packages with LTDC peripheral versus RGB interface availability) must be selected, according to the following parameters:

  • If an external memory is needed for the framebuffer.
  • The external framebuffer memory bus width
  • The LTDC interface: RGB565, RGB666, or RGB888 depending on the display module
  • If an external memory is needed to store graphic primitives (serial NOR flash, parallel NOR flash).

Checking the display size and color depth compatibility with the hardware configuration

When starting a graphic application development using an STM32 microcontroller, the user has often a defined desired display size and color depth. A key question that the user must answer before continuing the development is if such display size and color depth match a specific hardware configuration.

The following steps are needed in order to answer this question:

  1. Determine the required framebuffer size and its location.
  2. Check the compatibility of the display versus the framebuffer memory bandwidth requirements.
  3. Check the compatibility of the display panel interface with the LTDC.

Framebuffer memory size requirements and location

Determining the framebuffer memory size and its location is a key parameter for the display compatibility check.

The memory space required in the RAM to support the framebuffer must be contiguous and with a minimum size equal to:

Framebuffer size = number of pixels x bits per pixel

As shown in the formula above, the required framebuffer size depends on the display resolution and on its color depth.

It is not necessary that the framebuffer color depth (bpp) is the same than the display color depth. For instance, an RGB888 display can be driven using an RGB565 framebuffer.

Note:

The required framebuffer size is doubled for double-framebuffer configuration. It is common to use a double-buffer configuration where one graphic buffer is used to store the current image, while the second buffer is used to prepare the next image.

Table 9 Framebuffer size for different screen resolutions shows the framebuffer size needed for standard screen resolutions with different pixel formats.

Table 9. Framebuffer size for different screen resolutions
Screen resolutionNumber of pixelsFramebuffer size (Kbyte)1
8 bpp16 bpp24 bpp32 bpp
QVGA (320 x 240)7680075150225300
Custom (480 x 272)2130560128255383510
HVGA(480 x 320) 153600150300450600
VGA (640 x 480) 3072003006009001200
WVGA(800 x 480)38400037575011251500
SVGA (800 x 600)48000046993814071875
XGA (1024 x 768)786432768153623043072
HD (1280 x 720)921600900180027003600

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 either an external parallel SDRAM/SRAM/PSRAM connected to FMC or external serial SRAM/PSRAM connected to XSPI.

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.

Locating the framebuffer in the Internal SRAM

Depending on the framebuffer size, the framebuffer can be placed either in the internal SRAM or the external RAM.

Using an internal SRAM as a framebuffer allows the maximum performances and avoids any bandwidth limitation issues for the LTDC.

Using the internal SRAM instead of an external RAM has many advantages:

  • higher throughput (0 wait state access)
  • reduced number of required pins and PCB design complexity
  • reduced BOM, hence cost, since no external memory is needed

The only limitation when using the internal SRAM is its limited size (hundreds of Kbytes). When the framebuffer size exceeds the available memory, an external RAM (driven by the FMC or XSPI interface) must be used. However, when dealing with external memories, the user must be careful to avoid bandwidth limitation. For more detailed information, refer to Graphic performance optimization.

Note:

The color look-up table CLUT can be used to decrease the required framebuffer size. (For more details, refer to the STM32 MCU reference manual).

1 The required framebuffer size is doubled for double-framebuffer configuration.
2 An example of a custom 480 x 272 display is the ROCKTECH embedded on the STM32F746 discovery kit (32F746GDISCOVERY).

Checking display compatibility considering the memory bandwidth requirements

This section explains how to check a display compatibility considering the framebuffer memory bandwidth. Some important bandwidth aspects are described and this section explains how to determine the required bandwidth for the pixel clock and the LTDC. Finally, a simple method to conclude whether a desired display size is compatible with a specific hardware configuration; is detailed.

Framebuffer memory bandwidth aspects

Once the framebuffer location is fixed (either in internal or external memory), the user must check if its bandwidth can sustain the hardware configuration.

To check if the memory bandwidth can sustain the LTDC required bandwidth, the user must consider any other concurrent accesses to the memory.

In general, a small size framebuffer located in the internal RAM does not require a high bandwidth. This is because a small size framebuffer means low pixel clock, hence low LTDC required bandwidth.

A more complex use case to analyze is when the framebuffer is located in an external memory.

Framebuffer memory bus concurrency
  • LTDC, DMA2D, and CPU masters.

    In a typical graphic application where an external RAM is used as framebuffer, two or three main AHB masters concurrently use the same memory.

    The DMA2D (or the CPU) updates the next image to be displayed while the LTDC fetches and displays the actual image. The memory bus load depends mainly on the LTDC required bandwidth.

  • Other AHB/AXI masters.

    It is common that an external RAM is shared by other masters and not only by those used for graphics. This concurrency leads to heavy bus load and may impact the graphic performances.

Figure 22 AHB masters concurrent access to SDRAM shows all the AHB masters with concurrent access to the SDRAM.

Figure 22. AHB masters concurrent access to SDRAM


External SDRAM/SRAM memory bus width

When locating the framebuffer in an external SDRAM/SRAM, the user must consider that the external memory running frequency is around half or third of the system frequency. That is the reason why the memory bandwidth must be considered as the bottleneck of the whole graphic system.

One of the needed parameters for checking the display compatibility is the memory bus width. For SDRAM, an 8-bit, 16-bit, or 32-bit configuration can be used.

As previously stated, the most complex to analyze is the use case when the framebuffer is placed in an external memory:

The masters concurrent access on the same external memory leads to more latency and impacts its throughput.

Determining pixel clock and LTDC required bandwidth

Pixel clock computation

The pixel clock is a key parameter for checking display size compatibility with a specific hardware configuration.

To get the typical pixel clock of the display, refer to the display datasheet. The computed pixel clock need to respect the display specifications.

The pixel clock for a specific refresh rate is calculated with the following formula:
LCD_CLK (MHz) = total screen size x refresh rate
Where total screen size = total width x total height.

LTDC required bandwidth

The LTDC required bandwidth depends mainly on three factors:
  • Number of used LTDC layers.
  • LTDC layer color depth.
  • Pixel clock (depends on the resolution of the display panel and on the refresh rate).
The maximum required bandwidth can be calculated as described below:
  • If only one LTDC layer is used:
    LTDC required bandwidth = LCD_CLK x BppL1

  • If two LTDC layers are used:
    LTDC required bandwidth = LCD_CLK x (BppL1 + BppL2)

Where BppL1 and BppL2 are respectively the color depth for LTDC Layer1 and Layer2. The LTDC required bandwidth must not exceed the memory available bandwidth, otherwise, display problems may occur and the FIFO underrun flag may be set (if the FIFO underrun interrupt was enabled). Note: If the memory used to store the framebuffer is also used for other application purposes, it may impact the graphical performances of the system.

Check if the used display resolution fits the hardware configuration

The general method for checking whether a display size with a particular color depth is compatible with memory bandwidth includes the following steps:

  1. Compute the pixel clock according to the display size or extract it from the display datasheet.
  2. Check if the display pixel clock does not exceed the maximum system-supported pixel clock described in Table 10 STM32F4x9 maximal supported pixel clock to Table 17 STM32L4P/Q maximal supported pixel clock. The following parameters must be used to extract from Table 10 STM32F4x9 maximal supported pixel clock or Table 17 STM32L4P/Q maximal supported pixel clock the maximum-supported pixel clock corresponding to the used hardware configuration:
    • Number of used LTDC layers.
    • Used system clock speed HCLK/ACLK and framebuffer memory speed.
    • External framebuffer memory bus width.
    • Number of AHB/AXI masters accessing concurrently to external framebuffer memory.
  3. The user must perform some tests to confirm the hardware compatibility with the desired display size and color depth. To do it, the user must monitor the LTDC FIFO underrun interrupt flag in the LTDC_ISR register.

    If the FIFO underrun interrupt flag is always reset, then the user confirms that the desired display size is compatible with the hardware configuration.

    If the FIFO underrun flag is set, the user must check the following points:

    1. Verify if the correct maximum pixel clock is extracted, from Table 10 STM32F4x9 maximal supported pixel clock or Table 17 STM32L4P/Q maximal supported pixel clock, corresponding to the right hardware (mistake example: 16-bit SDRAM but extracted pixel clock corresponding to a 32-bit SDRAM).
    2. The color framebuffer line width is not 64/128 bytes (for AHB/AXI) aligned (see Optimizing the LTDC framebuffer fetching from external memories (SDRAM or SRAM)).
    3. For the STM32F7 and STM32H7 devices, the MPU is not correctly configured to avoid Cortex®-M7 speculative read accesses to the external memory (see Special recommendations for Cortex M7 (STM32F7/H7) and Cortex M55 (STM32N6)).
    4. If the FIFO underrun is still set because there are more than two master concurrent accesses to the external memory, the user must relax the memory bandwidth using the below recommendations:
      • Use only one LTDC layer.
      • Use the largest possible memory bus width (32-bit instead of 16- or 8-bit SDRAM/SRAM).
      • Update the framebuffer content during the blanking period when the LTDC is not fetching.
      • Use the highest possible system clock HCLK/ACLK and the highest memory speed.
      • Decrease the images color depth (bpp).

        For more details on memory bandwidth optimization, see Graphic performance optimization.

Note:

To evaluate the STM32 graphical capability in a specific hardware configuration, the user can use the STM32 boards described in AN4861_Reference-boards-with-LCD-TFT-panel.html#id_61973__table_wcq_hcr_31c.

Figure 23 Typical graphic hardware configuration with external SDRAM 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-bit, 16-bit, or 8-bit, while the operating clock depends on the system clock HCLK and the configured prescaler (HCLK/2 or HCLK/3).

Figure 23. Typical graphic hardware configuration with external SDRAM


Table 10 STM32F4x9 maximal supported pixel clock to Table 20 Example of supported display resolutions in specific STM32 hardware configurations list the maximal supported pixel clock at system level for various STM32 MCUs.

Table 10. STM32F4x9 maximal supported pixel clock
Used LTDC layersColor depth (bpp)Maximum pixel clock (MHz)1
LTDC2LTDC + DMA2D3
FMC
SDRAM 16-bit SDRAM 32-bit SDRAM 16-bit SDRAM 32-bit
1 layer3238672235
2451833047
1676834570
883838383
2 layers32/321933NA18
32/2422381321
32/1625441525
32/830531930
24/2426441524
24/1631531830
24/838672338
16/1639672237
16/851833150
8/878834674
Table 11. STM32F7x6/7/8/9 maximal supported pixel clock
Used LTDC layersColor depth (bpp)Maximum pixel clock (MHz)4
LTDC5LTDC + DMA2D6
fmc
SDRAM 16-bit SDRAM 32-bit SDRAM 16-bit SDRAM 32-bit
1 layer3242742539
2456833452
1683835178
883838383
2 layers32/3221371220
32/2424421423
32/1628491728
32/834592134
24/2429491727
24/1634592033
24/842742642
16/1643742541
16/857833456
8/883835182
Table 12. STM32H5Ex/H5Fx maximal supported pixel clock
Used LTDC layersColor depthMaximum pixel clock7
Only LTDC8LTDC + DMA2D9
OCTOSPI
8‑bit PSRAM DDR
1 layer325824
247832
169048
89090
Table 13. STM32H742/43/45/47/53/55/57 and STM32H750 maximal supported pixel clock
Used LTDC layersColor depth (bpp)Maximum pixel clock10
LTDC11LTDC + DMA2D12
FMC
SDRAM 16-bitSDRAM 32-bitSDRAM 16-bitSDRAM 32-bit
1 layer3249932948
24661243864
16991505896
8150150116150
Table 14. STM32H7R7/7S7 maximal supported pixel clock
Used LTDC layersColor depth (bpp) Maximum pixel clock13
LTDC14LTDC + DMA2D15
XSPIFMCXSPIFMC
8‑bit PSRAM DDR16‑bit PSRAM DDRSDRAM 16‑bitSDRAM 32‑bit 8‑bit PSRAM DDR16‑bit PSRAM DDRSDRAM 16‑bitSDRAM 32‑bit
1 layer328888468434382850
249090609046503666
169090909068745490
89090909090909090
Table 15. STM32H7A3/B3 and STM32H7B0 maximal supported pixel clock
Used LTDC layersColor depth (bpp) Maximum pixel clock16
LTDC17LTDC + DMA2D18
OCTOSPIFMCOCTOSPIFMC
HyperRAM™ 8-bit DDRSDRAM 16‑bitSDRAM 32‑bitHyperRAM™ 8-bit DDRSDRAM 16‑bitSDRAM 32‑bit
1 layer32525297223050
247070130294066
161051051404460100
814014014089121140
Table 16. STM32L4+ maximal supported pixel clock
Used LTDC layersColor depth (bpp)Maximum pixel clock19
LTDCX20LTDC + DMA2D21
FSMC
SRAM 16-bit
1 layer3211-
241510
162315
84731
Table 17. STM32L4P/Q maximal supported pixel clock
Used LTDC layersColor depth (bpp)Maximum pixel clock22
LTDC23LTDC + DMA2D24
OCTOSPI
8-bit PSRAM DDR
1 layer322711
243715
165523
86046
Note:

Decreasing the system clock (HCLK then LTDC) leads to a degradation of graphic performances

Table 18. STM32U59/A/F/G maximal supported pixel clock
Used LTDC layersColor depth (bpp)Maximum pixel clock2526
LTDC27LTDC + DMA2D28
Hexadeca-SPI
16-bit PSRAM DDR
1 layer3211642
2411648
1611671
8116116
Table 19. STM32N6xx maximal supported pixel clock
Used LTDC layersColor depth (bpp) Maximum pixel clock29
LTDC30
XSPI
8‑bit PSRAM DDR16‑bit PSRAM DDR
1 layer328888
248888
168888
88888
Note:

For STM32N6xx devices, the AXI QOS is set to maximum for LTDC. As a consequence, the maximal supported pixel clock is the same for both LTDC and LTDC+DMA2D tests. The values are limited by the LTDC Kernel clock at 88 MHz.

Example of supported display resolutions for STM32F4x9 and STM32F7x6/7/8/9

Table 20 Example of supported display resolutions in specific STM32 hardware configurations lists an example of some standard and custom display sizes supported by the STM32F4x9 and STM32F7x6/7/8/9, in the following conditions:

  • For STM32F4x9, the system clock HCLK runs @ 180 MHz and the SDRAM @ 90 MHz.
  • For STM32F7x6/7/8/9, the system clock HCLK runs @ 200 MHz and the SDRAM @ 100 MHz.
  • Only one LTDC layer is used.
  • Two AHB masters concurrent access to the SDRAM (LTDC + DMA2D).
Table 20. Example of supported display resolutions in specific STM32 hardware configurations
Display characteristicsSTM32 LTDC configuration
ResolutionRefresh rate (Hz)Pixel clock (MHz)Display standardColor depth
SDRAM 16-bitSDRAM 32-bit
320 x 240 (QVGA)605.6CustomUp to 32 bpp
480 x 2729.5
640 x 480 (VGA)25.175Industry standardUp to 24 bppUp to 32 bpp
800 x 600 (SVGA)40.000VESA guidelines31Up to 16 bppUp to 24 bpp
1024 x 768 (XGA)658 bppUp to 16 bpp
1280 x 76868.250CVT R.B32
1280 x 720 (HD)74.25CEA33Up to 16 bpp34
1920 x108030
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.
4 System clock HCLK = 200 MHz, SDRAM runs at 100 MHz.
5 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.
6 LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to frontbuffer.
7 HCLK = 250 MHz, PSRAM CLK = 125 MHz.
8 LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24, or 32 bpp.
9 LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to frontbuffer.
10 ACLK = 240 MHz, SDRAM runs at 110 MHz.
11 LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24, or 32 bpp.
12 LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to frontbuffer.
13 ACLK = 300 MHz, PSRAM runs at 200MHz, SDRAM runs at 100 MHz
14 LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24, or 32 bpp.
15 When the LTDC and DMA2D have the same read QoS priority (default configuration for H7RS), the LTDC fetches the front buffer from the external memory while the DMA2D prepares the back buffer.
16 ACLK = 280 MHz, SDRAM/HyperRAM run at 110 MHz.
17 LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24, or 32 bpp.
18 LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to frontbuffer.
19 System clock HCLK = 120 MHz, SRAM is asynchronous.
20 LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24, or 32 bpp.
21 LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to frontbuffer.
22 System clock HCLK = 120 MHz, PSRAM runs at 60 MHz.
23 LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24, or 32 bpp.
24 LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to frontbuffer.
25 System clock HCLK = 160 MHz, PSRAM memory runs at 160 MHz.
26 Limited by LTDC maximum output clock frequency, refer to the relevant product datasheet.
27 LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24, or 32 bpp.
28 LTDC fetches the front buffer from the external memory while the DMA2D transfers data from backbuffer to frontbuffer.
29 ACLK = 400 MHz, PSRAM runs at 200 MHz
30 LTDC fetches the front buffer from the external memory. The LTDC layer color depth is 8, 16, 24, or 32 bpp.
31 VESA (video electronics standards association) is a technical standards organization for computer display standards providing display monitor timing (DMT) standards.
32 CVT R.B: coordinated video timings reduced blanking standard by VESA.
33 CEA = consumer electronics association.
34 Up to 8 bpp for the STM32F4x9 microcontrollers.

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 Checking display compatibility considering the memory bandwidth requirements).