How to enable LV_ASSERT_HANDLER on ESP32-S3


I’ve got LVGL 8.3.11 running on my ESP32-S3, but when the LVGL heap is out of memory, it’ll hang, because LV_ASSERT_HANDLER is defined to while(1); I’d like to be able to trap this condition during development and print the assert in the ESP console. Will this require a custom lv_conf.h, or is it possible to configure through the menuconfig? I’ll gladly consider any guidance on this topic.

What MCU/Processor/Board and compiler are you using?

ESP32-S3, ESP-IDF v5.1.2, ESP GCC12.2.0

What do you want to achieve?

I’d like to redirect LV_ASSERT_HANDLER to hook the libc assert handler so that I can get a synchronous result on the console rather than a watchdog timer error later.

What have you tried so far?

I tried adding a configuration options for it in Kconfig.projbuild, but I can’t figure out how to #define CONFIG_LV_ASSERT_HANDLER assert(0);, I can only seem to get it #define CONFIG_LV_ASSERT_HANDLER "assert(0);", (of course, this doesn’t work).

I tried adding CONFIG_LV_ASSERT_HANDLER=assert(0); to the top-level cmake file, but that resulted in ‘Function-style preprocessor definitions may not be passed on the compiler command line because many compilers do not support it.’

I tried adding a managed_components/lv_conf.h, just for testing it contains only #error (my lvgl is in managed_components/lvgl__lvgl), but it doesn’t seem to be included in the build, as the #error is not hit.

Code to reproduce

Add the relevant code snippets here.

The code block(s) should be between ```c and ``` tags:

#include "lvgl.h"
void app_main(void)

Currently, I get:

E (8929) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (8929) task_wdt:  - IDLE (CPU 0)
E (8929) task_wdt: Tasks currently running:
E (8929) task_wdt: CPU 0: main
E (8929) task_wdt: CPU 1: IDLE
E (8929) task_wdt: Print CPU 0 (current core) backtrace
...backtrace here...

I’d like to get(or generally redirect the macro):

assert failed: example_main.c:10(0)

Backtrace: 0x40379e2a:0x3fcb6cb0 0x403840f9:0x3fcb6cd0 0x4038b4f9:0x3fcb6cf0 0x4200a7bd:0x3fcb6e10 0x420b6a77:0x3fcb6e50 0x40386ba9:0x3fcb6e80
0x40379e2a: panic_abort at C:/Espressif/frameworks/esp-idf-v5.1.2/components/esp_system/panic.c:452
0x403840f9: esp_system_abort at C:/Espressif/frameworks/esp-idf-v5.1.2/components/esp_system/port/esp_system_chip.c:84
0x4038b4f9: __assert_func at C:/Espressif/frameworks/esp-idf-v5.1.2/components/newlib/assert.c:81
0x4200a7bd: app_main at C:/Projects/ChessUpTwo/ESP32/main/spi_lcd_touch_example_main.c:325 (discriminator 2)
0x420b6a77: main_task at C:/Espressif/frameworks/esp-idf-v5.1.2/components/freertos/app_startup.c:208 (discriminator 13)
0x40386ba9: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v5.1.2/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

I’m also interested in how to change the definition, something like #define LV_ASSERT_HANDLER vMyAssert(); Inside the lvgl folder, the folder MyAssert (contains *.c i *.h file)