Skip to content

Commit

Permalink
fix(esp_lvgl_port): Init LVGL in lvgl_port_init() call
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tore-espressif committed Jan 16, 2025
1 parent 446a88f commit 2877ed4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Unreleased]

### Fixes
- Fixed a crash when esp_lvgl_port was initialized from high priority task https://github.com/espressif/esp-bsp/issues/455

## 2.4.3

### Fixes
Expand Down
14 changes: 11 additions & 3 deletions components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -84,12 +84,17 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg)

BaseType_t res;
if (cfg->task_affinity < 0) {
res = xTaskCreate(lvgl_port_task, "taskLVGL", cfg->task_stack, NULL, cfg->task_priority, &lvgl_port_ctx.lvgl_task);
res = xTaskCreate(lvgl_port_task, "taskLVGL", cfg->task_stack, xTaskGetCurrentTaskHandle(), cfg->task_priority, &lvgl_port_ctx.lvgl_task);
} else {
res = xTaskCreatePinnedToCore(lvgl_port_task, "taskLVGL", cfg->task_stack, NULL, cfg->task_priority, &lvgl_port_ctx.lvgl_task, cfg->task_affinity);
res = xTaskCreatePinnedToCore(lvgl_port_task, "taskLVGL", cfg->task_stack, xTaskGetCurrentTaskHandle(), cfg->task_priority, &lvgl_port_ctx.lvgl_task, cfg->task_affinity);
}
ESP_GOTO_ON_FALSE(res == pdPASS, ESP_FAIL, err, TAG, "Create LVGL task fail!");

// Wait until taskLVGL starts
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(5000)) == 0) {
ret = ESP_ERR_TIMEOUT;
}

err:
if (ret != ESP_OK) {
lvgl_port_deinit();
Expand Down Expand Up @@ -206,6 +211,7 @@ IRAM_ATTR bool lvgl_port_task_notify(uint32_t value)

static void lvgl_port_task(void *arg)
{
TaskHandle_t task_to_notify = (TaskHandle_t)arg;
lvgl_port_event_t event;
uint32_t task_delay_ms = 0;
lv_indev_t *indev = NULL;
Expand All @@ -219,6 +225,8 @@ static void lvgl_port_task(void *arg)

/* LVGL init */
lv_init();
/* LVGL is initialized, notify lvgl_port_init() function about it */
xTaskNotifyGive(task_to_notify);
/* Tick init */
lvgl_port_tick_init();

Expand Down

0 comments on commit 2877ed4

Please sign in to comment.