Skip to content

Commit cfe08f1

Browse files
committed
fix(lvgl_port): Fixed deinitialization of the task which was created with caps + lv_deinit()
1 parent 4d7bf33 commit cfe08f1

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

components/esp_lvgl_port/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Fixes
6+
- Fixed deinitialization of the task which was created with caps - https://github.com/espressif/esp-bsp/issues/680
7+
- Call lv_deinit() - https://github.com/espressif/esp-bsp/issues/635
8+
39
## 2.7.0
410

511
### Features

components/esp_lvgl_port/examples/rgb_lcd/main/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ static esp_err_t app_lcd_init(void)
103103
.dma_burst_size = 64,
104104
#endif
105105
.data_width = 16,
106+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6,0,0)
107+
.in_color_format = LCD_COLOR_FMT_RGB565,
108+
#else
106109
.bits_per_pixel = 16,
110+
#endif
107111
.de_gpio_num = EXAMPLE_LCD_GPIO_DE,
108112
.pclk_gpio_num = EXAMPLE_LCD_GPIO_PCLK,
109113
.vsync_gpio_num = EXAMPLE_LCD_GPIO_VSYNC,

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: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ 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 */
215-
const lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG();
215+
lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG();
216+
lvgl_cfg.task_affinity = task_affinity;
216217
ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "LVGL port initialization failed");
217218

218219
/* Add LCD screen */
@@ -306,7 +307,7 @@ static void app_main_display(void)
306307
}
307308

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

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

334335
ESP_LOGI(TAG, "Initilize LVGL.");
335336

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

339340
/* Show LVGL objects */
340341
app_main_display();
@@ -349,11 +350,36 @@ TEST_CASE("Main test LVGL port", "[lvgl port]")
349350

350351
ESP_LOGI(TAG, "LVGL deinitialized.");
351352

353+
esp_reent_cleanup();
352354
size_t end_lvgl_freemem_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
353355
size_t end_lvgl_freemem_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
354356
check_leak(start_lvgl_freemem_8bit, end_lvgl_freemem_8bit, "8BIT LVGL");
355357
check_leak(start_lvgl_freemem_32bit, end_lvgl_freemem_32bit, "32BIT LVGL");
356358

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

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

365391
ESP_LOGI(TAG, "LCD deinitilized.");
366392

393+
esp_reent_cleanup();
367394
size_t end_freemem_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
368395
size_t end_freemem_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
369396
check_leak(start_freemem_8bit, end_freemem_8bit, "8BIT");

components/lcd/esp_lcd_gc9503/test_apps/main/test_esp_lcd_gc9503.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define TEST_LCD_V_RES (480)
2929
#define TEST_LCD_BIT_PER_PIXEL (18)
3030
#define TEST_RGB_BIT_PER_PIXEL (16)
31+
#define TEST_LCD_IN_COLOR_FORMAT (LCD_COLOR_FMT_RGB565)
3132
#define TEST_LCD_DATA_WIDTH (16)
3233

3334
#define TEST_LCD_IO_RGB_DISP (GPIO_NUM_NC)
@@ -111,7 +112,11 @@ TEST_CASE("test gc9503 to draw color bar with RGB interface, using GPIO", "[gc95
111112
.dma_burst_size = 64,
112113
#endif
113114
.data_width = TEST_LCD_DATA_WIDTH,
115+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6,0,0)
116+
.in_color_format = TEST_LCD_IN_COLOR_FORMAT,
117+
#else
114118
.bits_per_pixel = TEST_RGB_BIT_PER_PIXEL,
119+
#endif
115120
.de_gpio_num = TEST_LCD_IO_RGB_DE,
116121
.pclk_gpio_num = TEST_LCD_IO_RGB_PCLK,
117122
.vsync_gpio_num = TEST_LCD_IO_RGB_VSYNC,
@@ -200,7 +205,11 @@ TEST_CASE("test gc9503 to draw color bar with RGB interface, using IO expander",
200205
.dma_burst_size = 64,
201206
#endif
202207
.data_width = TEST_LCD_DATA_WIDTH,
208+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6,0,0)
209+
.in_color_format = TEST_LCD_IN_COLOR_FORMAT,
210+
#else
203211
.bits_per_pixel = TEST_RGB_BIT_PER_PIXEL,
212+
#endif
204213
.de_gpio_num = TEST_LCD_IO_RGB_DE,
205214
.pclk_gpio_num = TEST_LCD_IO_RGB_PCLK,
206215
.vsync_gpio_num = TEST_LCD_IO_RGB_VSYNC,

0 commit comments

Comments
 (0)