Custom cache invalidation callback

The STM32 DMA2D driver currently has a static function within it that invalidates the D-Cache. This is not usable out-of-the-box with an operating system that prevents applications from accessing core system registers. I think it would be better to make this a global function and set it as the default choice for a new option in lv_conf.h. This would allow users to rewrite the logic for an OS if they need to.

1 Like

This is topic is question for all platforms, that try to use HW for drawing. AFAIK flushes are needed across all platforms and accelerators in the same way, unless CPU is drawing into uncached area, so shouldn’t be there a generic way to work with caches in LVGL, whatever platform or accelerator is used? Kind of callback for display driver?

Just out of curiosity, is this a theoretical problem or have you really faced this issue?

So a disp_drv.clear_mcu_cache() would be enough to clear only data cache?

I have faced this issue in practice as I test LVGL in an environment where the application has limited direct access to hardware.

Yes; I think that would be sufficient, although I’d choose a more specific name like clean_data_cache (clear doesn’t specify whether it’s being invalidated or cleaned). I can send a patch for this if you’d like.

Looks good, please send a PR.

I can see that there was a change in CB name, from invalidate to clean. But after all, both has to be done, as it’s done anyway in SCB_CleanInvalidateDCache(). Clean to let HW accelerator see the results from CPU, and invalidate to let CPU see the results from accelerator. So “clean” alone, or “invalidate” alone may be confusing.

I see. Now even the docs say

clean_dcache_cb a callback for cleaning any caches related to the display

I think at least the docs need to be updated to mention invalidation too.