メイン・コンテンツまでスキップ

Selecting External Flash Asset Banks

TouchGFX applications can use images, fonts, and text stored in memory-mapped external flash. When an application is linked, these assets have addresses in a fixed flash bank. If the assets are programmed into a different bank at runtime, the application can apply an address offset so TouchGFX reads the assets from that bank instead.

This can be useful for over-the-air (OTA) updates. For example, an application can always be linked with assets at the start of external flash, while the OTA update system stores a new asset set in a second bank. At startup, the bootloader or application selects which bank to use and provides the corresponding offset to TouchGFX.

Configure the asset offset​

Include ExternalFlash.h and call its functions during initialization, before TouchGFX accesses the assets. The offsets are in bytes. Use an offset of zero for the first bank, or the distance between banks for another bank. For example, if the second bank starts 8 MiB after the first, its offset is 0x00800000:

#include <touchgfx/hal/ExternalFlash.h>

void MX_TouchGFX_Init(void)
{
uint32_t assetOffset = 0x00800000UL; /* Select this from the active bank at startup. */

touchgfx_setTextFlashOffset(assetOffset);
touchgfx_setFontFlashOffset(assetOffset);
touchgfx_setImagesFlashOffset(0x90000000UL, assetOffset);

/* Continue with the rest of TouchGFX initialization. */
}

The image function takes both the base address used for linked images and the offset to apply. TouchGFX adds the offset only to image addresses at or above that base address.
Images linked below the base address, such as images stored in internal flash for performance reasons, do not receive the offset.
The font and text functions set offsets for their respective asset addresses.

The selected bank must contain a matching, complete set of assets at the expected layout. These functions only adjust addresses used by TouchGFX; they do not select a bank in the flash hardware, copy data, or perform the OTA update. The bootloader or application must choose and validate the active bank and make its offset available before calling these functions.

This method is for memory-mapped external flash. For flash that cannot be directly addressed by the MCU, see Using Non-Memory Mapped Flash.