Projekt2k

RGB panel glitches only when WiFi is on: an ESP32-S3 + PSRAM case study

Setup. Waveshare ESP32-S3-Touch-LCD-7 (800×480 RGB panel with ST7262, 16-bit RGB565, GT911 touch, 8 MB octal PSRAM, 16 MB flash). PlatformIO with platform = espressif32 8.0.0 (Arduino core 3.3.x, ESP-IDF 5.5), LVGL 9.2.2, one frame buffer in PSRAM, 16 MHz pixel clock, bounce buffer (10 lines), LVGL partial rendering. The firmware is a dashboard that polls Home Assistant over WiFi.

Symptom. The picture was fine for a while, then showed horizontal lines on the left side, flicker, a picture shifted by a few pixels, and sometimes stayed that way until reboot. It happened at boot when WiFi and the first HTTP requests started, and every time the app made a burst of network requests (for example when the user switched a date range on a page that fetches statistics).

The misleading part. Changing the USB cable or charger changed how soon it glitched. That looks like a power problem. It was not: four cables, two chargers and both USB ports all glitched, just at different moments. Network load timing varies, and that is what the cable changes appeared to influence. The original Waveshare demo never glitched, but it also did not use WiFi at all.

How to tell what is going on. Two build switches made the problem measurable instead of “it glitches sometimes”:

  1. A build with WiFi and all network polling disabled (-DNO_NET). It stayed clean for as long as we watched, which ruled out the panel, the wiring and the power supply.
  2. A stress build that jumps to the page that fetches data and changes the request every 4 s by itself. Two minutes of watching is then enough to compare configurations.

What did not fix it (each tried on its own, with the stress build):

  • Lower pixel clock (12 MHz): the panel lost sync completely and cycled through white, red, green, blue, black. Leave the clock alone.
  • Bounce buffer 20 lines instead of 10: noticeably better, but not gone. 30 lines was not better, and the two bounce buffers use internal RAM, so WiFi ran short of memory.
  • DMA burst size 64 and the bb_invalidate_cache flag: no clear difference.
  • Sending requests one at a time instead of in a burst: no clear difference.

A partial fix: do not put the whole heap in PSRAM. The firmware called heap_caps_malloc_extmem_enable(16) so that LVGL’s many small objects would not exhaust internal RAM. That also moved every small allocation of WiFi, HTTP and JSON handling into PSRAM, so network work competed with the LCD, which reads the frame buffer from PSRAM constantly. Removing it and giving LVGL its own PSRAM allocator (LV_USE_STDLIB_MALLOC = LV_STDLIB_CUSTOM, heap_caps_malloc(..., MALLOC_CAP_SPIRAM)) helped visibly and freed internal RAM (about 50 KB to 86 KB free), but did not remove the glitches.

The fix: rebuild the libraries with a different sdkconfig. The precompiled Arduino libraries ship one fixed ESP-IDF configuration. Several of its settings are a poor match for a frame buffer in PSRAM plus WiFi. PlatformIO can compile Arduino as an ESP-IDF component (framework = arduino, espidf) and apply a custom sdkconfig.defaults. We took the Arduino S3 qio_opi configuration as the base and changed:

SettingArduino defaultUsed
CONFIG_LCD_RGB_ISR_IRAM_SAFEoffon
CONFIG_ESP32S3_DATA_CACHE_64KB / _LINE_64B32 KB, 32 B lines64 KB, 64 B lines
CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB16 KB32 KB
CONFIG_SPIRAM_FETCH_INSTRUCTIONS, CONFIG_SPIRAM_RODATAoffon (code and rodata run from PSRAM)
CONFIG_ESP_WIFI_IRAM_OPT, CONFIG_ESP_WIFI_RX_IRAM_OPT, CONFIG_LWIP_IRAM_OPTIMIZATIONoffon
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIPonoff (WiFi buffers stay in internal RAM)

With this build the stress run showed no glitches; the owner reported “not a single glitch” while watching it. Longer everyday use has not been reported yet.

Caveats, stated honestly.

  • We changed these settings together and did not bisect which one is decisive. A plausible mechanism: the LCD interrupt was not IRAM-safe, so it cannot run while the flash cache is disabled (WiFi start-up and calibration do that), and the small caches let frame buffer reads and WiFi code evict each other. That is a hypothesis, not a measurement.
  • The new configuration uses more internal RAM (IRAM optimisations, bigger caches). With bounce buffer 20 lines and LVGL draw buffers 15 lines WiFi failed to start (“Expected to init 4 rx buffers, actual is 3”); 10 and 10 work, leaving about 49 KB of free heap.
  • The test so far was a few minutes of stress run, not a long soak test.
  • The first hybrid build downloads ESP-IDF and compiles for several minutes. In our setup the Arduino framework’s idf_component.yml also pulled in unrelated Espressif components (RainMaker, Insights, speech recognition) that broke the build; we trimmed that list with a small script.
  • Hybrid builds do not use build_src_filter. Sources are listed in a src/CMakeLists.txt, and embedded files need a different mechanism (we used an assembly .incbin).

Video sample – before and after

Analysis, experiments and the fix were done by Claude (Anthropic) via Claude Code, with the project owner testing each build on the hardware.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.