You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ESP32-S3(M5Dial)调用LVGL画布填充函数时触发Guru Meditation Error核心崩溃问题求助

ESP32-S3(M5Dial)调用LVGL画布填充函数时触发Guru Meditation Error核心崩溃问题求助

我手上有一台M5Stack的M5Dial设备,它搭载了ESP32-S3芯片,带一块240×240像素的圆形可视区域屏幕。最近我在用ESP-IDF的idf.py工具做开发,已经搞定了USB串口控制台,LVGL的官方UI演示也能正常运行,但只要一用LVGL的基础绘图原语,设备就会崩溃——不过崩溃后还能重新烧录,这点还算幸运。

我怀疑是C语言里的内存分配不足导致的,已经折腾好一阵了,问过AI也试过各种调整,现在陷入了死胡同。下面是我的代码:

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"

#include "lv_demos.h"
#include "bsp/esp-bsp.h"
#include "lvgl.h"  // Include LVGL header for drawing functions

static char *TAG = "app_main";

#define CANVAS_WIDTH 240
#define CANVAS_HEIGHT 240
#define BITS_PER_PIXEL 32 // 4 bytes for ARGB8888
#define LOG_MEM_INFO (0)

void draw_graphics_canvas2(lv_obj_t *canvas) {
    ESP_LOGI(TAG, "Clear canvas");

    // Clear the canvas with a black background
    lv_canvas_fill_bg(canvas, lv_color_make(255, 255, 0), LV_OPA_100);

    ESP_LOGI(TAG, "Have we crashed"); // We do not get here
}

void app_main(void) {
    /* Initialize display and LVGL */
    bsp_display_start();
    /* Set display brightness to 100% */
    bsp_display_backlight_on();
    lv_init(); // Initialize LVGL

    ESP_LOGI(TAG, "Display LVGL demo");
    bsp_display_lock(0);    

    // THIS WORKS, SO LET'S TRY PRIMITIVES INSTEAD
    //lv_demo_widgets();

    // Create a canvas object
    lv_obj_t *canvas = lv_canvas_create(lv_scr_act());
    lv_obj_set_size(canvas, CANVAS_WIDTH, CANVAS_HEIGHT); // Set canvas size
    lv_obj_set_pos(canvas, 0, 0); // Position it on the screen

    uint8_t* canvas_buffer = lv_malloc(LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, BITS_PER_PIXEL, 0));    
    if (!canvas_buffer) {
        ESP_LOGE(TAG, "Failed to allocate memory for canvas buffer");
        return; // Handle memory allocation failure.
    }

    // Allocate the buffer for the canvas
    lv_canvas_set_buffer(canvas, canvas_buffer, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888);

    // Draw graphics on the canvas
    draw_graphics_canvas2(canvas);

    // Refresh the canvas to ensure it updates on the display
    lv_obj_invalidate(canvas);

    // Create an infinite sleep loop
    while (1) {
        // Delay for a long time (e.g., 1 hour = 3600 seconds = 3600000 milliseconds)
        vTaskDelay(pdMS_TO_TICKS(3600000)); // Converts milliseconds to ticks
    }

    bsp_display_unlock();
}

下面是串口控制台的输出,包括我自己加的调试日志。可以看到程序执行到Clear canvas就停住了,后面的Have we crashed根本没打出来:

ELF file SHA256: 2fee38b22

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x2b (SPI_FAST_FLASH_BOOT)
Saved PC:0x40375c54
--- 0x40375c54: esp_restart_noos at /home/user/esp/esp-idf/components/esp_system/port/soc/esp32s3/system_internal.c:162
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce2810,len:0x1564
load:0x403c8700,len:0x4
load:0x403c8704,len:0xd24
load:0x403cb700,len:0x2ed4
entry 0x403c8928
I (26) boot: ESP-IDF v5.4.3 2nd stage bootloader
I (26) boot: compile time Feb 16 2026 00:52:53
I (26) boot: Multicore bootloader
I (27) boot: chip revision: v0.2
I (29) boot: efuse block revision: v1.3
I (33) boot.esp32s3: Boot SPI Speed : 80MHz
I (37) boot.esp32s3: SPI Mode       : DIO
I (40) boot.esp32s3: SPI Flash Size : 2MB
I (44) boot: Enabling RNG early entropy source...
I (49) boot: Partition Table:
I (51) boot: ## Label            Usage          Type ST Offset   Length
I (58) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (64) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (71) boot:  2 factory          factory app      00 00 00010000 00100000
I (77) boot: End of partition table
I (80) esp_image: segment 0: paddr=00010020 vaddr=3c060020 size=160e0h ( 90336) map
I (104) esp_image: segment 1: paddr=00026108 vaddr=3fc96300 size=02d8ch ( 11660) load
I (107) esp_image: segment 2: paddr=00028e9c vaddr=40374000 size=0717ch ( 29052) load
I (114) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=5c4f8h (378104) map
I (182) esp_image: segment 4: paddr=0008c520 vaddr=4037b17c size=0b100h ( 45312) load
I (192) esp_image: segment 5: paddr=00097628 vaddr=50000000 size=0001ch (    28) load
I (199) boot: Loaded app from partition at offset 0x10000
I (200) boot: Disabling RNG early entropy source...
I (210) cpu_start: Multicore app
I (220) cpu_start: Pro cpu start user code
I (220) cpu_start: cpu freq: 160000000 Hz
I (220) app_init: Application information:
I (220) app_init: Project name:     graphics_primitives
I (225) app_init: App version:      1
I (228) app_init: Compile time:     Feb 16 2026 01:40:15
I (233) app_init: ELF file SHA256:  2fee38b22...
I (237) app_init: ESP-IDF:          v5.4.3
I (241) efuse_init: Min chip rev:     v0.0
I (245) efuse_init: Max chip rev:     v0.99 
I (249) efuse_init: Chip rev:         v0.2
I (253) heap_init: Initializing. RAM available for dynamic allocation:
I (259) heap_init: At 3FCA9D88 len 0003F988 (254 KiB): RAM
I (264) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
I (270) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (275) heap_init: At 600FE000 len 00001FE8 (7 KiB): RTCRAM
I (281) spi_flash: detected chip: gd
I (283) spi_flash: flash io: dio
W (286) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (299) sleep_gpio: Configure to isolate all GPIO pins in sleep state
I (305) sleep_gpio: Enable automatic switching of GPIO sleep configuration
I (312) main_task: Started on CPU0
I (322) main_task: Calling app_main()
I (322) LVGL: Starting LVGL task
I (322) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (332) gc9a01: LCD panel create success, version: 2.0.4
I (452) gpio: GPIO[14]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:2 
I (482) gpio: GPIO[42]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (482) button: IoT Button Version: 4.1.5
I (482) gpio: GPIO[41]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (492) gpio: GPIO[40]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (502) Knob: Iot Knob Config Succeed, encoder A:41, encoder B:40, direction:0, Version: 1.0.2
I (512) M5Dial: Setting LCD backlight: 100%
I (512) app_main: Display LVGL demo
I (522) app_main: Clear canvas
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x4037f8d4  PS      : 0x00060033  A0      : 0x80378c84  A1      : 0x3fc97610  
--- 0x4037f8d4: vTaskGenericNotifyGiveFromISR at /home/user/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:6190
A2      : 0xffffff00  A3      : 0x00000000  A4      : 0x3fc97630  A5      : 0x3fcad668  
A6      : 0x3fc99454  A7      : 0x00000000  A8      : 0x00000050  A9      : 0x00000150  
A10     : 0x00000001  A11     : 0xffffffff  A12     : 0x00000000  A13     : 0x00060023  
A14     : 0x3fcaa5c8  A15     : 0x0000cdcd  SAR     : 0x00000004  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000050  LBEG    : 0x400556d5  LEND    : 0x400556e5  LCOUNT  : 0xfffffffd  
--- 0x400556d5: strlen in ROM
--- 0x400556e5: strlen in ROM


Backtrace: 0x4037f8d1:0x3fc97610 0x40378c81:0x3fc97630 0x4037705d:0x3fc97660 0x40377681:0x3fc97680 0x42022760:0x3fcad430 0x4200a1d9:0xffffff00 |<-CORRUPTED
--- 0x4037f8d1: vTaskGenericNotifyGiveFromISR at /home/user/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:6190
--- 0x40378c81: timer_alarm_handler at /home/user/esp/esp-idf/components/esp_timer/src/esp_timer.c:487
--- 0x4037705d: timer_alarm_isr at /home/user/esp/esp-idf/components/esp_timer/src/esp_timer_impl_systimer.c:93
--- 0x40377681: _xt_lowint1 at /home/user/esp/esp-idf/components/xtensa/xtensa_vectors.S:1240
--- 0x42022760: lv_canvas_fill_bg at /home/user/Documents/Development/Hardware/ESP32/graphics_primitives/managed_components/lvgl__lvgl/src/widgets/canvas/lv_canvas.c:330
--- 0x4200a1d9: draw_graphics_canvas2 at /home/user/Documents/Development/Hardware/ESP32/graphics_primitives/main/graphics_primitives.c:72

目前我观察到的现象是,屏幕一开始会亮白(应该是bsp_display_backlight_on()的效果),但崩溃后就变黑,然后设备重启,循环往复,屏幕一直闪白。

我本来以为LV_CANVAS_BUF_SIZE会自动计算需要的内存大小,lv_malloc()也能正常分配,但现在看来问题出在lv_canvas_fill_bg这个函数上——要么是我用错了,要么是背后还有别的问题。我的最终目标是能成功调用lv_draw_line,但现在连填充屏幕都搞不定,实在头疼。

有没有大佬能给点思路,我接下来该排查什么?

备注:内容来源于stack exchange,提问作者halfer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 17:54:36