Skip to content

Commit b53d406

Browse files
authored
Merge pull request lvgl#259 from tore-espressif/fix/esp32s2-memory-allocation
Fix/esp32s2 memory allocation
2 parents c985063 + 61e05b7 commit b53d406

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,16 @@ For more information see: [platformio with espidf framework compability](https:/
119119
120120
# ESP32-S2 Support
121121
122-
Support for ESP32-S2 variant isn't tested, the current drivers implementation
123-
would needs to be improved because this target available memory is less than
124-
ESP32 targets. The menuconfig interface also would need to be improved to take
125-
this into account.
122+
Support for ESP32-S2 variant is Work In Progress.
123+
Smaller displays (e.g. 320x240) work fine, but larger ones need testing.
124+
125+
## Background
126+
127+
ESP32-S2 has less on-chip SRAM than its predecessor ESP32 (520kB vs. 320kB).
128+
This causes problems with memory allocation with large LVGL display buffers as they don't fit into the on-chip memory
129+
and external PSRAM is not accessible by DMA.
130+
131+
Moreover, static allocation to external PSRAM is not yet supported
132+
(see [GitHub issue](https://github.com/espressif/esp-idf/issues/6162)).
133+
134+
At this momement, the buffers are dynamicaly allocated with DMA capabilty and memory allocator handles the rest.

main/main.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* LVGL Example project
2-
*
2+
*
33
* Basic project to test LVGL on ESP32 based projects.
44
*
55
* This example code is in the Public Domain (or CC0 licensed, at your option.)
@@ -60,7 +60,7 @@ static void create_demo_application(void);
6060
* APPLICATION MAIN
6161
**********************/
6262
void app_main() {
63-
63+
6464
/* If you want to use a task to create the graphic, you NEED to create a Pinned task
6565
* Otherwise there can be problem such as memory corruption and so on.
6666
* NOTE: When not using Wi-Fi nor Bluetooth you can pin the guiTask to core 0 */
@@ -73,20 +73,22 @@ void app_main() {
7373
SemaphoreHandle_t xGuiSemaphore;
7474

7575
static void guiTask(void *pvParameter) {
76-
76+
7777
(void) pvParameter;
7878
xGuiSemaphore = xSemaphoreCreateMutex();
7979

8080
lv_init();
81-
81+
8282
/* Initialize SPI or I2C bus used by the drivers */
8383
lvgl_driver_init();
8484

85-
static lv_color_t buf1[DISP_BUF_SIZE];
85+
lv_color_t* buf1 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
86+
assert(buf1 != NULL);
8687

8788
/* Use double buffered when not working with monochrome displays */
8889
#ifndef CONFIG_LV_TFT_DISPLAY_MONOCHROME
89-
static lv_color_t buf2[DISP_BUF_SIZE];
90+
lv_color_t* buf2 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
91+
assert(buf2 != NULL);
9092
#else
9193
static lv_color_t *buf2 = NULL;
9294
#endif
@@ -98,7 +100,7 @@ static void guiTask(void *pvParameter) {
98100
#if defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820 \
99101
|| defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A \
100102
|| defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D
101-
103+
102104
/* Actual size in pixels, not bytes. */
103105
size_in_px *= 8;
104106
#endif
@@ -130,7 +132,7 @@ static void guiTask(void *pvParameter) {
130132
indev_drv.type = LV_INDEV_TYPE_POINTER;
131133
lv_indev_drv_register(&indev_drv);
132134
#endif
133-
135+
134136
/* Create and start a periodic timer interrupt to call lv_tick_inc */
135137
const esp_timer_create_args_t periodic_timer_args = {
136138
.callback = &lv_tick_task,
@@ -142,7 +144,7 @@ static void guiTask(void *pvParameter) {
142144

143145
/* Create the demo application */
144146
create_demo_application();
145-
147+
146148
while (1) {
147149
/* Delay 1 tick (assumes FreeRTOS tick is 10ms */
148150
vTaskDelay(pdMS_TO_TICKS(10));
@@ -155,16 +157,20 @@ static void guiTask(void *pvParameter) {
155157
}
156158

157159
/* A task should NEVER return */
160+
free(buf1);
161+
#ifndef CONFIG_LV_TFT_DISPLAY_MONOCHROME
162+
free(buf2);
163+
#endif
158164
vTaskDelete(NULL);
159165
}
160166

161167
static void create_demo_application(void)
162168
{
163-
/* When using a monochrome display we only show "Hello World" centered on the
169+
/* When using a monochrome display we only show "Hello World" centered on the
164170
* screen */
165171
#if defined CONFIG_LV_TFT_DISPLAY_MONOCHROME || \
166172
defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S
167-
173+
168174
/* use a pretty small demo for monochrome displays */
169175
/* Get the current screen */
170176
lv_obj_t * scr = lv_disp_get_scr_act(NULL);

0 commit comments

Comments
 (0)