 Hello and welcome to this presentation. My name is Badr Dean and in this video we will learn how to cache the bitmaps stored in the SD card. In the first part we saw how to set up the SDMMC peripheral and add FATFS file system to the SDM32F746 3rdGFX template. In this second part we'll see how to cache the bitmaps stored in the SD card into the SDR. I have my SDM32Q by DE launcher asking me to select a new workspace. I will use a new workspace for this project and click launch. Here I have my SDM32Q by DE project open. I'll close the information center and expand the project here. I will start by setting up the bitmap cache which consists of a pointer to a buffer and the size of the buffer. I will expand project, then application, user and then touch GFX and then target. The bitmap cache setup is done in touch GFX, hold dot cpp, double click on the file. The initialize method we will set up the bitmap cache. By default the template uses 3 frame buffers of 261 kilobytes each. The total size of the frame buffer is BF400. Here we set up the start address of the cache right after the 3 frame buffers. The total size of the cache is 8 MB which is the size of the SDR. For the user manual of the SDM32F746 discovery board we have an SDR of 128 MB but only 64 MB is accessible, so 8 MB. So the size is 8 MB minus the size of the 3 frame buffers which gives us 7.4 MB or 7400C00. Then I will remove the default bitmap cache configuration and last but not least we set up the cache based on the start address and the size defined above. Here we cache up to 128 dynamic bitmaps. Next we will go to GUI mainview dot cpp and here we tell touch GFX framework which bitmaps to cache. We have 2 cache strategies, either we cache all the bitmaps or we cache specific bitmaps per ID. For example I can cache the background image on the setup screen and I can cache the image that I have on the main screen image 00 or I can cache all the bitmaps using cache all. So I can do bitmaps cache all. And of course in this case I need to remove these 2 lines. If we need to cache all the bitmaps of course the size of the cache must be large enough to contain all the bitmap data. Then of course we need to clear the cache and the tear down method. So here in the setup screen method we cache all the bitmaps and then in the tear down screen we clear all the cache. Now I will modify the linker script in a way to add a new virtual memory area SD card that starts from 0xA00000 with the length of 7MB. So I go to the linker script here and in the memory section I add a new memory area that is virtual that starts from the address A00000 and the length of 7MB. And then here I tell the linker to place the external flash section which contains all the bitmaps into the SD card virtual memory. And then I'll add the keyword noload here to tell Q by D not to load the binary to that section. If we look into that JFX designer and then images tab we see that the background image and image 00 are both placed in the external flash section. We'll go back here and what we did is we placed the external flash section in the SD card. I'll keep the font and the text flash section and the quote spy. When you cache a bitmap, TADGFX copies the pixels from the original location to the bitmap cache using the block copy function in TADGFX.cpp. In our case the bitmaps are stored in the SD card which is not a memory map memory. Then we need to add the FATFS red operation from the SD card. If the address is within the SD card virtual memory region then we use FATFS file to read the data. We calculate the offset within the SD card virtual memory. We place the file pointer to that offset then we read the number of bytes from the SD file to the destination address which is an SDM address. Else meaning if the address is not within the SD card virtual memory region then we use the default implementation. Of course before I can read it from the SD card I need to mount the file system and then open the file and I want to do that only once. So I'll do FATFS, if FATFS in it is 0 then mount the file system to SDFATFS and then open the file SD file and then set the variable to 1 to make sure I mount and open the file only once. Then I need to define these variables. So I already have the FATFS files or FATFS variables defined here. For example FATFS.c I see the SD path is defined here, the SDFATFS file system object is defined here, the SD file is defined here. So what I need to do is to define them here as extra and then I need to include the header file for the FATFS. And I still need to define FATFS in it variable and the byte thread variable. And here I have SD path copied twice, I need to remove it. Now I'm ready to build the project, select the project and click on build. We see here the build finished successfully.