In this section we will discuss how to use a new font-layout that will allow you to put almost all font data into unmapped external flash. The effect is that you can have many thousand letters in an application using only 50 kb of flash.
TouchGFX supports two different font layouts for the fonts compiled into your application. The layout used is selected in TouchGFX Designer in the configurations tab:
Mapped storage format is the default font layout and should be
used on systems where fonts are stored in memory mapped flash
(internal or e.g. external QSPI flash).
Unmapped storage format is the new font layout. It allows most
of the font data to be stored in unmapped flash. This will typically
be a SPI-flash, but can be any type of storage.
The mapped storage format keeps the font data in two tables.
The first table is an array of touchgfx::GlyphNode. These contain the properties of the individual characters: height, width, unicode, and similar.
The second table (split in multiple files for large fonts) contains the pixel-patterns for the characters.
The GlyphNodes will be used by the TouchGFX engine during text layout. The pixels will be read by the DMA2D or software routines during drawing.
On platforms using the normal LCD classes, e.g. LCD16Bpp or LCD24Bpp, these tables must be stored in internal flash or memory mapped external flash.
On platforms using a unmapped external flash, the LCD16BppSerialFlash can read the pixels-patterns from unmapped serial flash, but the GlyphNodes must be in internal flash.
The unmapped storage format splits the font data in three tables. The two tables from the mapped storage layout is reused, but a third table is added:
This third table just contains the unicodes present in the font.
When this font layout is used, the third table must be present in internal flash, but the other two tables can be moved to external flash. This is a considerable saving, as the third table uses two bytes for each character, whereas the GlyphNode table uses 14 bytes. This reduces the storage requirement in internal flash.
When the font data is placed in unmapped flash, the mcu cannot access
it directly. We therefore have to provide a flash reader object to the
The code for this is automatically generated by TouchGFXGenerator:
If you are not using the generator, you must do this manually.
Remember to implement the functions in TouchGFXDataReader so data is actually read from your flash.
Below is a screenshot of an application using the new font layout:
This application runs on a STM32G071 Nucleo board with a MB1642A display module:
In this application we have 4000 Chinese characters in size 20, 4 bits pr pixel. The application and data takes up 61Kb of 128 Kb available on the STM32G071. The font data is distributed as follows (excluding minor objects):
|GlyphNodes||External SPI flash||57.372 bytes|
|Pixel patterns||External SPI flash||3.116.296 bytes|
|Unicode list||Internal flash||8.000 bytes|
To use the unmapped font layout correctly, you must update your linker script to place the tables correctly.
In this linker script we put both the ExtFlashSection (images and font pixels) and FontFlashSection (the GlyphNodes) in the external flash. Any other read-only data is in the internal flash (ROM_region).