From cc693e52281892ad4e804adab629f9acb182b156 Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Sun, 18 Oct 2026 14:01:25 -0700 Subject: [PATCH] dotclockframebuffer: write back the frame buffer correctly on ESP32-P4 and ESP32-S31 refresh() wrote the frame buffer back from the cache with a hand-declared Cache_WriteBack_Addr(addr, size). That is the ROM signature on ESP32-S3, but on ESP32-P4 and ESP32-S31 the ROM function takes three arguments, Cache_WriteBack_Addr(map, addr, size), so there the buffer address went in as the cache map, the length as the address, and the size was whatever was left in the register. Nothing was written back. Use esp_cache_msync() from esp_cache.h instead, as esp_lcd does. It picks the right cache operation on every chip. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../common-hal/dotclockframebuffer/DotClockFramebuffer.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.c b/ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.c index 7e0ab560319..5558a222628 100644 --- a/ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.c +++ b/ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.c @@ -34,9 +34,7 @@ #include "hal/gpio_hal.h" #include "soc/lcd_cam_struct.h" #include "esp_heap_caps.h" - -// should be from rom/cache.h but it wasn't working -int Cache_WriteBack_Addr(uint32_t addr, uint32_t size); +#include "esp_cache.h" #define LCD_RGB_ISR_IRAM_SAFE (1) #define LCD_RGB_INTR_ALLOC_FLAGS (ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_INTRDISABLED) @@ -213,7 +211,7 @@ mp_int_t common_hal_dotclockframebuffer_framebuffer_get_first_pixel_offset(dotcl } void common_hal_dotclockframebuffer_framebuffer_refresh(dotclockframebuffer_framebuffer_obj_t *self) { - Cache_WriteBack_Addr((uint32_t)(self->bufinfo.buf), self->bufinfo.len); + esp_cache_msync(self->bufinfo.buf, self->bufinfo.len, ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_UNALIGNED); } mp_int_t common_hal_dotclockframebuffer_framebuffer_get_refresh_rate(dotclockframebuffer_framebuffer_obj_t *self) {