From 6e623843ab41345150c26a53bd0f0c26e899de5f Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Fri, 20 Nov 2026 10:47:06 -0600 Subject: [PATCH] fix(m5stack-tab5): wait for the flush's PPA rotation with LVGL's PPA draw unit With CONFIG_LV_USE_PPA, LVGL's fills and blends (the PPA's blend engine) ran while the flush's rotation (the SRM engine) was still in flight, and on a Tab5 that rotation's completion then never arrived: LVGL waited in wait_for_flushing() forever (core dump of a launcher that hung within seconds of scrolling). With LV_USE_PPA the flush now runs its rotation blocking, so it finishes before LVGL draws again; the completion callback still signals LVGL as before. Without LV_USE_PPA nothing changes. The README documents the settings the PPA draw unit needs with this BSP and what it measured on a Tab5: no gain over software drawing with the rotation left in flight (75 ms average redraw, against 88-91 ms with the PPA draw unit). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY --- components/m5stack-tab5/README.md | 20 +++++++++++++++++++- components/m5stack-tab5/src/video.cpp | 9 +++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/components/m5stack-tab5/README.md b/components/m5stack-tab5/README.md index fc554d76f6..198a7f429f 100644 --- a/components/m5stack-tab5/README.md +++ b/components/m5stack-tab5/README.md @@ -149,7 +149,25 @@ RGB565): 75.6 ms with full-frame double draw buffers copied into one frame buffe PSRAM, against 5.5 MB for one frame buffer plus two full-frame draw buffers (and the 1.8 MB rotation scratch buffer is not needed either). The frame buffers are cache-line aligned, so they also satisfy a raised `LV_DRAW_BUF_ALIGN` (e.g. 128 -for the PPA draw unit), which a plain `heap_caps_malloc()` draw buffer may not. +for the PPA draw unit); so are the draw buffers `initialize_display()` allocates. + +## LVGL's PPA draw unit + +LVGL (9.6) can draw opaque fills and unscaled opaque images with the PPA +(`CONFIG_LV_USE_PPA`, `CONFIG_LV_USE_PPA_IMG`). It needs +`CONFIG_LV_DRAW_BUF_ALIGN` equal to the data cache line size (128), and short +PPA bursts like the BSP's own (`CONFIG_LV_PPA_BURST_LENGTH_64`: the DPI panel's +scan-out underruns under full-length ones). With it enabled, the flush waits +for its PPA rotation before returning instead of leaving it in flight while +LVGL draws the next area: with the two overlapping, the rotation's completion +never arrived and LVGL waited for the flush forever. + +Measured on a Tab5 (a 1280 x 720 landscape launcher UI, rotated by the PPA in +partial draw buffers), it did not pay off: redraws averaged 88-91 ms with the +PPA draw unit, 85-88 ms with the rotation waited for but software drawing, +and 75 ms with software drawing and the rotation left in flight (the +default). Each PPA operation syncs the cache over the rows it touches, and +waiting for the rotation loses the overlap with drawing. ## Saving internal DMA-capable RAM diff --git a/components/m5stack-tab5/src/video.cpp b/components/m5stack-tab5/src/video.cpp index 6a8d048873..64dc18ff7a 100644 --- a/components/m5stack-tab5/src/video.cpp +++ b/components/m5stack-tab5/src/video.cpp @@ -1398,7 +1398,16 @@ void M5StackTab5::flush(lv_display_t *disp, const lv_area_t *area, uint8_t *px_m // and notify_ppa_trans_done() signals LVGL when it finishes, so LVGL // renders the next area into its other draw buffer meanwhile. The next // panel operation waits for it first (wait_for_transfer_idle()). +#if LV_USE_PPA + // Except with LVGL's PPA draw unit: its fills and blends (the PPA's + // blend engine) while this rotation (the SRM engine) is in flight left + // the rotation's completion never arriving on a Tab5 (LVGL then waits + // for the flush forever), so the rotation finishes before LVGL draws + // again. The completion callback still signals LVGL as below. + srm.mode = PPA_TRANS_MODE_BLOCKING; +#else srm.mode = PPA_TRANS_MODE_NON_BLOCKING; +#endif srm.user_data = this; // Serialize the framebuffer write with draw_bitmap (write_lcd_lines / // the non-PPA flush tail) so two engines never write the panel FB at once.