Caching External NOR FLASH, not uploading code - bad linker
Hi, I'm trying to find adress space for not memory mapped 16MB NOR.
I have external PSRAM IS66WVE4M16EBLL + NOR MT28EW128ABA1LPC-0SIT with STM32H753ZIT6. They are both on the same bus:

FMC: NOR 0x60000000,PSRAM 0x68000000. Not using MPU. I use raw addresses of PSRAM as memory mapped, and HAL functions to transfer data to NOR. I tested memory integrity, R/W - all fine.
So far I had TouchGFX running with internal FLASH for graphics + doublebuffers in external PSRAM - it was working fine with stable 32 FPS @ 480 x 272px RGB565.
Now I want to use external FLASH for storing graphics. Seems it is not memory mapped so I started with this article and to cache most of graphics to external PSRAM and faced this section:
"In this example we will put the image data in the ExtFlashSection at address 0x24000000. You can select any address that is otherwise unused (not part of the code or data address space)."
I grab 288k of RAM_D2 to test (0x30000000) as unused address space. Then I added to FrontendApplication.cpp the buffer and attached in the constructor:
#define FRONTEND_CACHE_SIZE_HALFWORLDS (600*1024)
static __attribute__ ((section(".external_cache"), used)) uint16_t external_ram_cache[FRONTEND_CACHE_SIZE_HALFWORLDS];
uint16_t* frontend_cache = external_ram_cache;
...
Bitmap::setCache(frontend_cache, FRONTEND_CACHE_SIZE_BYTES);
Bitmap::cache(BITMAP_BUTTON_ID);Linker script:
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
EXT_RAM (xrw) : ORIGIN = 0x68000000, LENGTH = 8M
EXT_FLASH_DUMMY (r) : ORIGIN = 0x30000000, LENGTH = 16M
}
...
.framebuffer(NOLOAD) :
{
. = ALIGN(2);
. = ABSOLUTE(0x68000000);
*(.framebuffer_1)
. = ALIGN(2);
. = ABSOLUTE(0x68040000);
*(.framebuffer_2)
. = ABSOLUTE(0x68080000);
} >EXT_RAM
.ext_data(NOLOAD) :
{
. = ALIGN(1);
. = ABSOLUTE(0x68080090);
*(.external_cache)
} >EXT_RAM
ExtFlashSection :
{
*(ExtFlashSection ExtFlashSection.*)
} >EXT_FLASH_DUMMYBecause both SDRAM and NOR are connected to the same data/address bus I created internal RAM buffer to let transfer the data in chunks:
bool TouchGFXHAL::blockCopy(void* RESTRICT dest, const void* RESTRICT src, uint32_t numBytes) {
const uint32_t dummy_address = 0x30000000;
const uint32_t srcVal = (uint32_t)(src);
if ((srcVal >= dummy_address) && srcVal < (dummy_address + 16*1024*1024)) {
const uint32_t localAddress = srcVal - dummy_address;
const uint32_t fullBlocksCount = numBytes / GFX_COPY_BLOCK_SIZE;
for(uint32_t block=0; block<fullBlocksCount; ++block) {
const uint32_t offset = block * GFX_COPY_BLOCK_SIZE;
const uint32_t blockAddress = localAddress + offset;
memset(copyBlockBuffer, 0, sizeof(copyBlockBuffer));
mem_manager_read_ext_flash(blockAddress, copyBlockBuffer, GFX_COPY_BLOCK_SIZE);
memcpy((void*)((uint8_t*)dest + offset), (void*)copyBlockBuffer, GFX_COPY_BLOCK_SIZE);
}
return true;
}
else {
return HAL::blockCopy(dest, src, numBytes);
}
return TouchGFXGeneratedHAL::blockCopy(dest, src, numBytes);
}It is working fine.
But adress space of RAM_D2 is only 64k and I need about 16M of graphics. Looking at RM0433 I dont really see any block of memory in which I could store 16M of unused adressed space.
I triend many addresses to try fit at least 500k of graphics and it always fails during uploading with Failed to execute MI command load.

All caching logic is working fine. I only need to understand how to treat addresses managed by linker. Could you give me a hint?
