Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential Exception Due to Task Priority in esp_lvgl_port with LVGL9 (BSP-596) #455

Open
1 task done
nicechao opened this issue Dec 10, 2024 · 0 comments · May be fixed by #468
Open
1 task done

Potential Exception Due to Task Priority in esp_lvgl_port with LVGL9 (BSP-596) #455

nicechao opened this issue Dec 10, 2024 · 0 comments · May be fixed by #468
Assignees
Labels

Comments

@nicechao
Copy link

Board

ESP32S3

Hardware Description

ESP32S3+ST7789

IDE Name

ESP-IDF5.3 + esp_lvgl_port 2.4.3 + lvgl 9.2.2

Operating System

UBUNTU24.10

Description

During code debugging, the following exception occurred:

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x42028d0e  PS      : 0x00060330  A0      : 0x82028d9c  A1      : 0x3fcb1aa0  
0x42028d0e: search_suitable_block at /projpath/managed_components/lvgl__lvgl/src/stdlib/builtin/lv_tlsf.c:563

A2      : 0x00000000  A3      : 0x3fcb1ac0  A4      : 0x3fcb1ac4  A5      : 0x3fcaed94  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000010  A9      : 0x3fcb1a80  
A10     : 0x00000003  A11     : 0x3fcb1ac0  A12     : 0x3fcb1ac4  A13     : 0x00000000  
A14     : 0x3c07d097  A15     : 0x3fcb163c  SAR     : 0x00000004  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000014  LBEG    : 0x400556d5  LEND    : 0x400556e5  LCOUNT  : 0xfffffffd  
0x400556d5: strlen in ROM
0x400556e5: strlen in ROM

Backtrace: 0x42028d0b:0x3fcb1aa0 0x42028d99:0x3fcb1ac0 0x42028f3d:0x3fcb1af0 0x420279c4:0x3fcb1b10 0x42029100:0x3fcb1b30 0x420264b2:0x3fcb1b80 0x42019c31:0x3fcb1ba0 0x4201114a:0x3fcb1be0 0x42011680:0x3fcb1c30 0x4200adda:0x3fcb1c60 0x4200ae4b:0x3fcb1cd0 0x4037ecf9:0x3fcb1d10
0x42028d0b: search_suitable_block at managed_components/lvgl__lvgl/src/stdlib/builtin/lv_tlsf.c:563
0x42028d99: block_locate_free at managed_components/lvgl__lvgl/src/stdlib/builtin/lv_tlsf.c:769
0x42028f3d: lv_tlsf_malloc at managed_components/lvgl__lvgl/src/stdlib/builtin/lv_tlsf.c:1101
0x420279c4: lv_malloc_core at managed_components/lvgl__lvgl/src/stdlib/builtin/lv_mem_core_builtin.c:144
0x42029100: lv_malloc at managed_components/lvgl__lvgl/src/stdlib/lv_mem.c:70
0x420264b2: lv_ll_ins_head at managed_components/lvgl__lvgl/src/misc/lv_ll.c:61
0x42019c31: lv_display_create at managed_components/lvgl__lvgl/src/display/lv_display.c:64
0x4201114a: lvgl_port_add_disp_priv at managed_components/espressif__esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c:321
0x42011680: lvgl_port_add_disp at managed_components/espressif__esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c:87
0x420110b0: lvgl_port_add_disp at managed_components/espressif__esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c:87

The assembly code corresponding to the exception:

static block_header_t * search_suitable_block(control_t * control, int * fli, int * sli)
42028d00 <search_suitable_block>:
{
42028d00:       004136          entry   a1, 32
    int fl = *fli;
42028d03:       002372          l32i    a7, a3, 0
    int sl = *sli;
42028d06:       0024a2          l32i    a10, a4, 0
    unsigned int sl_map = control->sl_bitmap[fl] & (~0U << sl);
42028d09:       874b            addi.n  a8, a7, 4
42028d0b:       a08820          addx4   a8, a8, a2
42028d0e:       1898            l32i.n  a9, a8, 4
42028d10:       f87c            movi.n  a8, -1
42028d12:       401a00          ssl     a10
42028d15:       a18800          sll     a8, a8
42028d18:       10a980          and     a10, a9, a8
    if(!sl_map) {
42028d1b:       398987          bany    a9, a8, 42028d58 <search_suitable_block+0x58>
        const unsigned int fl_map = control->fl_bitmap & (~0U << (fl + 1));
42028d1e:       4298            l32i.n  a9, a2, 16
42028d20:       771b            addi.n  a7, a7, 1
42028d22:       f87c            movi.n  a8, -1
42028d24:       401700          ssl     a7
42028d27:       a18800          sll     a8, a8
42028d2a:       10a980          and     a10, a9, a8

The cause of the exception is that the control parameter was not properly initialized and was actually a null pointer.

The root cause was traced back to the initialization process:

  • According to the documentation, the initialization should first call lvgl_port_init() and then lvgl_port_add_disp().
  • When using LVGL8, the lv_init() function is directly called within lvgl_port_init(), and the program runs normally.
  • However, when using LVGL9, the lv_init() function is scheduled to run within the lvgl_port_task(), a task created by lvgl_port_init(). If the priority of lvgl_port_task() is lower than the current task, the lv_init() function may not have been executed by the time lvgl_port_add_disp() calls the LVGL9 API, which can lead to the exception.

Sketch

static esp_err_t app_lvgl_init(void)
{
    /* Initialize LVGL */
    const lvgl_port_cfg_t lvgl_cfg = {
        .task_priority = 4,         /* LVGL task priority */
        .task_stack = 4096,         /* LVGL task stack size */
        .task_affinity = -1,        /* LVGL task pinned to core (-1 is no affinity) */
        .task_max_sleep_ms = 500,   /* Maximum sleep in LVGL task */
        .timer_period_ms = 5        /* LVGL timer tick period in ms */
    };
    ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "LVGL port initialization failed");

    /* Add LCD screen */
    ESP_LOGD(TAG, "Add LCD screen");
    const lvgl_port_display_cfg_t disp_cfg = {
        .io_handle = lcd_io,
        .panel_handle = lcd_panel,
        .buffer_size = EXAMPLE_LCD_H_RES * EXAMPLE_LCD_DRAW_BUFF_HEIGHT * sizeof(uint16_t),
        .double_buffer = EXAMPLE_LCD_DRAW_BUFF_DOUBLE,
        .hres = EXAMPLE_LCD_H_RES,
        .vres = EXAMPLE_LCD_V_RES,
        .monochrome = false,
        /* Rotation values must be same as used in esp_lcd for initial settings of the screen */
        .rotation = {
            .swap_xy = false,
            .mirror_x = true,
            .mirror_y = true,
        },
        .flags = {
            .buff_dma = true,
#if LVGL_VERSION_MAJOR >= 9
            .swap_bytes = true,
#endif
        }
    };
    lvgl_disp = lvgl_port_add_disp(&disp_cfg);

    /* Add touch input (for selected screen) */
    const lvgl_port_touch_cfg_t touch_cfg = {
        .disp = lvgl_disp,
        .handle = touch_handle,
    };
    lvgl_touch_indev = lvgl_port_add_touch(&touch_cfg);

    return ESP_OK;
}

static void lvgl_task(void *arg)
{
    app_lvgl_init();
}

xTaskCreate(lvgl_task, TAG, 4 * 1024, NULL, 5, NULL);

Other Steps to Reproduce

Suggested Solution:

  • The documentation should be updated to include a reminder about task priority.
  • Alternatively, it could be ensured that lvgl_port_add_disp() only runs after lv_init() has been completed.

I have checked existing issues, README.md and ESP32 Forum

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@nicechao nicechao added Status: Awaiting triage Type: Bug Something isn't working labels Dec 10, 2024
@github-actions github-actions bot changed the title Potential Exception Due to Task Priority in esp_lvgl_port with LVGL9 Potential Exception Due to Task Priority in esp_lvgl_port with LVGL9 (BSP-596) Dec 10, 2024
tore-espressif added a commit that referenced this issue Jan 3, 2025
Previously, we initialized LVGL in the new LVGL handling task.
If lvgl_port_init() was called from high priority task, it could
return with uninitialized LVGL.

Closes #455
@tore-espressif tore-espressif self-assigned this Jan 3, 2025
tore-espressif added a commit that referenced this issue Jan 9, 2025
Previously, we initialized LVGL in the new LVGL handling task.
If lvgl_port_init() was called from high priority task, it could
return with uninitialized LVGL.

Closes #455
tore-espressif added a commit that referenced this issue Jan 9, 2025
Previously, we initialized LVGL in the new LVGL handling task.
If lvgl_port_init() was called from high priority task, it could
return with uninitialized LVGL.

Closes #455
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants