Flushing the cache (writeback)
Posted: Sat Feb 01, 2025 10:13 am
Hi,
So, it all started (as a newbie to ESP32 and Arduino IDE) when I found difficulty finding a GFX library for my board (Guition ESP32-S3-4848S040) and what files need to be modified related to the assignment of ESP pins to the LCD interface, and for the initialisation sequence for the ST7701 panel driver.
This is an ESP32-S3 based board with attached 480x480 touch panel, that has a 3-wire SPI and 16-pin RGB interface.
I have some code from a different manufacturer to that of the board I have, and it initialises the LCD and draws colour bars (and reads the touch panel, displaying the x,y).
Anyway, so I decided I wanted to write direct to the LCD frame buffer. This turned out easier than expected (perhaps even easier if you already know!). I wrote (hacked) a little code that searched the GDMA for the channel that was used for the LCD. Then using this info, looked in memory for the DMA linked list, got the address of the display buffer, and can now write direct to the screen.
As you know, the GDMA accesses the external memory (where the frame store is located - too wasteful for internal SRAM, and also a huge waste of internal bus resources) directly - bypassing the DCache. But the CPU has to go via this cache to get to external. So the problem is...
1) I can write to the frame buffer, but a lot of the data gets stuck in cache. I mean, it comes out eventually after doing more writes to different addresses, or forcing a load of reads, but there must be a way of forcing a cache writeback that's more efficient. I see a function called Cache_WriteBack_Addr, but don't know what it does (or how long it takes to execute), and what library I need to include.
2) Second question: in the GDMA linked list description in the esp tech ref manual (page 360 of the doc I have), bit 31 of DW0 defines the owner. What does this mean in reality? I know the GDMA can access the buffer (there is a display after all), and the CPU can write to the buffer too.
Thanks for any info.
So, it all started (as a newbie to ESP32 and Arduino IDE) when I found difficulty finding a GFX library for my board (Guition ESP32-S3-4848S040) and what files need to be modified related to the assignment of ESP pins to the LCD interface, and for the initialisation sequence for the ST7701 panel driver.
This is an ESP32-S3 based board with attached 480x480 touch panel, that has a 3-wire SPI and 16-pin RGB interface.
I have some code from a different manufacturer to that of the board I have, and it initialises the LCD and draws colour bars (and reads the touch panel, displaying the x,y).
Anyway, so I decided I wanted to write direct to the LCD frame buffer. This turned out easier than expected (perhaps even easier if you already know!). I wrote (hacked) a little code that searched the GDMA for the channel that was used for the LCD. Then using this info, looked in memory for the DMA linked list, got the address of the display buffer, and can now write direct to the screen.
As you know, the GDMA accesses the external memory (where the frame store is located - too wasteful for internal SRAM, and also a huge waste of internal bus resources) directly - bypassing the DCache. But the CPU has to go via this cache to get to external. So the problem is...
1) I can write to the frame buffer, but a lot of the data gets stuck in cache. I mean, it comes out eventually after doing more writes to different addresses, or forcing a load of reads, but there must be a way of forcing a cache writeback that's more efficient. I see a function called Cache_WriteBack_Addr, but don't know what it does (or how long it takes to execute), and what library I need to include.
2) Second question: in the GDMA linked list description in the esp tech ref manual (page 360 of the doc I have), bit 31 of DW0 defines the owner. What does this mean in reality? I know the GDMA can access the buffer (there is a display after all), and the CPU can write to the buffer too.
Thanks for any info.