From 05ff8169f74286e954dba59389476b084f6e9a8c Mon Sep 17 00:00:00 2001 From: Markus Ebner Date: Thu, 29 Feb 2024 22:24:21 +0100 Subject: [PATCH] fix(esp_lcd): Flush rgb lcd PSRAM framebuffers after allocation Flush PSRAM framebuffers after allocation to avoid visual corruption. Merges https://github.com/espressif/esp-idf/pull/13294 Closes https://github.com/espressif/esp-idf/issues/13293 --- components/esp_lcd/src/esp_lcd_panel_rgb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/esp_lcd/src/esp_lcd_panel_rgb.c b/components/esp_lcd/src/esp_lcd_panel_rgb.c index 80a0bfaafc..e0c8ffb32f 100644 --- a/components/esp_lcd/src/esp_lcd_panel_rgb.c +++ b/components/esp_lcd/src/esp_lcd_panel_rgb.c @@ -152,10 +152,14 @@ static esp_err_t lcd_rgb_panel_alloc_frame_buffers(const esp_lcd_rgb_panel_confi if (fb_in_psram) { // the low level malloc function will help check the validation of alignment rgb_panel->fbs[i] = heap_caps_aligned_calloc(psram_trans_align, 1, rgb_panel->fb_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); + ESP_RETURN_ON_FALSE(rgb_panel->fbs[i], ESP_ERR_NO_MEM, TAG, "no mem for frame buffer"); + // calloc not only allocates but also zero's the buffer. We have to make sure this is + // properly committed to the PSRAM, otherwise all sorts of visual corruption will happen. + ESP_RETURN_ON_ERROR(esp_cache_msync(rgb_panel->fbs[i], rgb_panel->fb_size, ESP_CACHE_MSYNC_FLAG_DIR_C2M), TAG, "cache write back failed"); } else { rgb_panel->fbs[i] = heap_caps_aligned_calloc(sram_trans_align, 1, rgb_panel->fb_size, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA); + ESP_RETURN_ON_FALSE(rgb_panel->fbs[i], ESP_ERR_NO_MEM, TAG, "no mem for frame buffer"); } - ESP_RETURN_ON_FALSE(rgb_panel->fbs[i], ESP_ERR_NO_MEM, TAG, "no mem for frame buffer"); } }