How to solve HardFault exception loading L8 images from non memory mapped flash
I'm working on a STM32H7B3I-DK with a 565 format frame buffer.
In my design, the Serial Flash that contents the ExtFlashSection in a standard project will not be memory mapped because I need part of it to record other data.
I followed the topics about caching bitmaps (https://support.touchgfx.com/docs/development/ui-development/touchgfx-engine-features/caching-bitmaps and https://support.touchgfx.com/docs/development/ui-development/scenarios/using-non-memory-mapped-flash )
In TouchGFX Designer, if I put the ’section’ part of the image to ExtFlashSection and the ‘Extra Section’ (e.g. the CLUT) in IntFlashSection everything is fine.
But if I try to put the ‘Extra Section’ in the ExtFlashSection the engine crashes on a HardFault because the library code tries to access directly the extra section in a memory mapped fashion.
Here is the state when hitting the HardFault exception
EXEC_RETURN (LR):
lr 0xffffffed -19
xPSR 0x21000000
ReturnAddress 0x8026bbe
LR (R14) 0x8026edb
R12 0x0
R3 0x1fe00
R2 0x14
R1 0x9001fe00
R0 0x80363d8
Return instruction:
0x8026bbe <_ZN8touchgfx6Bitmap15getSizeOfBitmapEt+198>: ldrb r0, [r1, #3]
LR instruction:
0x8026edb <_ZN8touchgfx6Bitmap5cacheEt+62>: mov r9, r0
I keep the linker file to have the ExtFlashSection mapped to 0x90000000 addresses so the data is loaded on debugger start but these addresses are not directly available at run time because the OSPI flash is not memory mapped as in a default TouchGfx project.
I put in bold the offending intsr/data in cpu trace. As you see, the R1 register holds the address of where is linked the _black_extra_data[] array (the CLUT of an image called ‘black’).
This fault happens before my overloaded blockCopy function is called.
Using the working linker map (with extra_ data section in internal flash), I verified that all images were copied to the cache by tracking the calls to my overloaded blockCopy function after a call to Bitmap::cacheAll() (both pixels and clut's are effectively copied to cache but this happen after the offending code !! )
