Skip to content

Commit 5e65c24

Browse files
committed
fix(lvgl_port): Fixed deinitialization of the task which was created with caps + lv_deinit()
1 parent d15cf39 commit 5e65c24

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static void lvgl_port_task(void *arg)
252252
lvgl_port_task_deinit();
253253

254254
/* Close task */
255-
vTaskDelete( NULL );
255+
vTaskDeleteWithCaps( NULL );
256256
}
257257

258258
static void lvgl_port_task_deinit(void)
@@ -274,10 +274,9 @@ static void lvgl_port_task_deinit(void)
274274
vEventGroupDelete(lvgl_port_ctx.lvgl_events);
275275
}
276276
memset(&lvgl_port_ctx, 0, sizeof(lvgl_port_ctx));
277-
#if LV_ENABLE_GC || !LV_MEM_CUSTOM
277+
278278
/* Deinitialize LVGL */
279279
lv_deinit();
280-
#endif
281280
}
282281

283282
static void lvgl_port_tick_increment(void *arg)

components/esp_lvgl_port/test_apps/lvgl_port/main/test.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static esp_err_t app_touch_deinit(void)
209209
return ESP_OK;
210210
}
211211

212-
static esp_err_t app_lvgl_init(void)
212+
static esp_err_t app_lvgl_init(int task_affinity)
213213
{
214214
/* Initialize LVGL */
215215
const lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG();
@@ -306,7 +306,7 @@ static void app_main_display(void)
306306
}
307307

308308
// Some resources are lazy allocated in the LCD driver, the threadhold is left for that case
309-
#define TEST_MEMORY_LEAK_THRESHOLD (50)
309+
#define TEST_MEMORY_LEAK_THRESHOLD (200)
310310

311311
static void check_leak(size_t start_free, size_t end_free, const char *type)
312312
{
@@ -333,8 +333,8 @@ TEST_CASE("Main test LVGL port", "[lvgl port]")
333333

334334
ESP_LOGI(TAG, "Initilize LVGL.");
335335

336-
/* LVGL initialization */
337-
TEST_ASSERT_EQUAL(app_lvgl_init(), ESP_OK);
336+
/* LVGL initialization - no task affinity */
337+
TEST_ASSERT_EQUAL(app_lvgl_init(-1), ESP_OK);
338338

339339
/* Show LVGL objects */
340340
app_main_display();
@@ -349,11 +349,36 @@ TEST_CASE("Main test LVGL port", "[lvgl port]")
349349

350350
ESP_LOGI(TAG, "LVGL deinitialized.");
351351

352+
esp_reent_cleanup();
352353
size_t end_lvgl_freemem_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
353354
size_t end_lvgl_freemem_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
354355
check_leak(start_lvgl_freemem_8bit, end_lvgl_freemem_8bit, "8BIT LVGL");
355356
check_leak(start_lvgl_freemem_32bit, end_lvgl_freemem_32bit, "32BIT LVGL");
356357

358+
ESP_LOGI(TAG, "Initilize LVGL - task affinity to core 1");
359+
360+
/* LVGL initialization - task affinity to core 1 */
361+
TEST_ASSERT_EQUAL(app_lvgl_init(1), ESP_OK);
362+
363+
/* Show LVGL objects */
364+
app_main_display();
365+
366+
vTaskDelay(5000 / portTICK_PERIOD_MS);
367+
368+
/* LVGL deinit */
369+
TEST_ASSERT_EQUAL(app_lvgl_deinit(), ESP_OK);
370+
371+
/* When using LVGL8, it takes some time to release all memory */
372+
vTaskDelay(1000 / portTICK_PERIOD_MS);
373+
374+
ESP_LOGI(TAG, "LVGL deinitialized.");
375+
376+
esp_reent_cleanup();
377+
end_lvgl_freemem_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
378+
end_lvgl_freemem_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
379+
check_leak(start_lvgl_freemem_8bit, end_lvgl_freemem_8bit, "8BIT LVGL");
380+
check_leak(start_lvgl_freemem_32bit, end_lvgl_freemem_32bit, "32BIT LVGL");
381+
357382
/* Touch deinit */
358383
TEST_ASSERT_EQUAL(app_touch_deinit(), ESP_OK);
359384

@@ -364,6 +389,7 @@ TEST_CASE("Main test LVGL port", "[lvgl port]")
364389

365390
ESP_LOGI(TAG, "LCD deinitilized.");
366391

392+
esp_reent_cleanup();
367393
size_t end_freemem_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
368394
size_t end_freemem_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
369395
check_leak(start_freemem_8bit, end_freemem_8bit, "8BIT");

0 commit comments

Comments
 (0)