This section discusses how to use a serial flash (or other unmapped storage) to store images and fonts. The technique described here is especially usefull on STM32G0 and other deviced with very little RAM.
See the article Lowering Memory Usage with Partial
Framebuffer for a
introduction to partial framebuffers which are often used together
with a serial flash.
See also the article Using Non-Memory Mapped Flash for storing images for an introduction to caching bitmaps from unmapped flash to RAM.
To use a serial flash with your TouchGFX application you must change the TouchGFX Generator configuration to enable the "External Data Reader" in "Additional Features".
With this feature enabled the TouchGFX Generator changes the
configuration to use the
LCD16bppSerialFlash LCD class. It also
generates a subclass of the
This code creates an instance of the
TouchGFXDataReader class and
passes that instance to the display object, to the HAL object, and to
the ApplicationFontProvider object. These three objects will use the
dataReader object to access data in the serial flash. The data can be
both images and font data.
The system programmer must finish the implementation of the
TouchGFXDataReader class to actually read data from a flash.
The TouchGFXDataReader class implements the touchgfx::FlashDataReader interface. This interface has the following 4 methods that needs to be implemented on a specific hardware.
addressIsAddressable method is used by the
class to decide if some data can be directly read (i.e. is located in
internal RAM or internal flash) or if it should be read through the
copyData*` method is used to copy data synchronously from the
flash to RAM. This function is typically used when the data is not
further processed. E.g. when copying a solid image to a framebuffer.
startFlashLineRead method is used when multiple lines of data
are required from the flash. The
startFlashLineRead method initiates
a read of data. The method can initiate an asynchronous read and
should return immediately after starting the read. The
waitFlashReadComplete method should wait for the read to finish, and
return a pointer to a buffer holding the data.
LCD16bppSerialFlash can issue one flash read while processing the
previously read data (in some situations). This means that at least
two buffers are required in the dataReader to gain full concurrency.
The TouchGFX Generator generates the
FlashDataReader in two classes:
TouchGFXGeneratedDataReader is the superclass of the two and contains
a default implementation. If that implementation is not suitable, the
application programmer can change the implementation of the virtual
functions in the
TouchGFXGeneratedDataReader implementation calls C-functions to do
the work. These application are implemented by the system programmer.
The implementation is found in the
This implementation is specific to the protocol used by the flash and
the GPIO used for SPI and CS. All three C functions must be
implemented for the
TouchGFXGeneratedDataReader class to work.
As mentioned in the introduction the
LCD16bppSerialFlash class can
read image pixels through the dataReader object. For this to work we
must change the lnker script to put images in an address range outside
the internal flash range.
On the STM32G071 we have selected the address 0x90000000 as start address for the serial flash:
This puts the
FontFlashSection into the 0x90000000 address range.
The remaining task is to write the data to the external flash using a flasher tool.
A short description on writing flash loaders for STM32CubeProgrammer can be found in section 2.3.3 in this document:UM2237 STMCubeProgrammer User Manual
The above linker script puts the font pixel data and the font character metadata (with and height) into the external flash (both types of data are in the FontFlashSection). This data is also read through the dataReader object when drawing characters on the Screen
If you are not using the "Unmapped Storage Format" for your you must
change the linker script and the file
include/touchgfx/hal/Config.hpp to move the font character metadata
to internal flash.
See the article about Fonts in unmapped storage for more information on the font formats.